Skip to content

Commit 981b943

Browse files
author
Jan Rochel
committed
Ot_page_transition: fix screenshots
previously screenshots were not updated after replacing pages
1 parent 28ab5f0 commit 981b943

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/widgets/ot_page_transition.eliom

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,6 @@ module Make (Conf:PAGE_TRANSITION_CONF) = struct
4949
then Hashtbl.replace screenshot_list id (screenshot,w,h)
5050
else Hashtbl.add screenshot_list id (screenshot,w,h)
5151

52-
let wait_for_screenshot max_wait_time id =
53-
let rec aux i =
54-
if (not (mem_screenshot id)) && i < max_wait_time then
55-
let%lwt () = Lwt_js.sleep 0.01 in
56-
aux (i+1)
57-
else Lwt.return_unit
58-
in
59-
aux 0
60-
6152
let wrap_screenshot screenshot transition_duration =
6253
let container = Conf.screenshot_container screenshot in
6354
let wrapper = div ~a:[a_class ["ot-page-transition-wrapper"]] [container] in
@@ -93,11 +84,24 @@ module Make (Conf:PAGE_TRANSITION_CONF) = struct
9384
style##.transitionDuration := initial_transition_duration;
9485
Lwt.return_unit
9586

87+
let wait_for ~sleep ~cycles cond =
88+
let rec loop i =
89+
if not (cond ()) && i < cycles then
90+
let%lwt () = Lwt_js.sleep sleep in
91+
loop (i+1)
92+
else Lwt.return_unit
93+
in
94+
loop 0
95+
9696
let forward_animation ?(transition_duration=0.5) take_screenshot id =
9797
try
98-
take_screenshot (push_screenshot id);
98+
let screenshot = ref None in
99+
take_screenshot (fun ss -> screenshot := Some ss);
99100
forward_animation_ transition_duration id;
100-
wait_for_screenshot 100 id
101+
wait_for ~sleep:0.01 ~cycles:100
102+
(fun () -> match !screenshot with
103+
| None -> false
104+
| Some ss -> push_screenshot id ss; true)
101105
with _ -> Lwt.return_unit
102106

103107
let backward_animation_

0 commit comments

Comments
 (0)