@@ -95,8 +95,10 @@ let%shared drawer
9595 in
9696 let d = D. div ~a: [a_class [ " ot-drawer"
9797 ; match position with
98- | `Left -> " ot-dr-left"
99- | `Right -> " ot-dr-right" ]]
98+ | `Top -> " ot-dr-top"
99+ | `Right -> " ot-dr-right"
100+ | `Bottom -> " ot-dr-bottom"
101+ | `Left -> " ot-dr-left" ]]
100102 (toggle_button :: (content :> Html_types.div_content elt list ))
101103 in
102104 let bckgrnd_init_class = if opened then [" ot-dr-open" ] else [] in
@@ -193,10 +195,15 @@ let%shared drawer
193195 animation_frame_requested := false ;
194196 (match ! action with
195197 | `Move delta ->
196- let s = Js. string ((if ~% position = `Right
197- then " translateX(calc(-100% + "
198- else " translateX(calc(100% + " )^
199- string_of_int delta^ " px))" ) in
198+ let s =
199+ (match ~% position with
200+ | `Top -> " translateY(calc(100% + "
201+ | `Right -> " translateX(calc(-100% + "
202+ | `Bottom -> " translateY(calc(-100% + "
203+ | `Left -> " translateX(calc(100% + " )
204+ |> (fun t -> Printf. sprintf " %s%dpx" t delta)
205+ |> Js. string
206+ in
200207 (Js.Unsafe. coerce (dr##.style))##.transform := s;
201208 (Js.Unsafe. coerce (dr##.style))##.webkitTransform := s
202209 | `Close ->
@@ -226,26 +233,36 @@ let%shared drawer
226233 let status = ref Stopped in
227234 let onpan ev _ =
228235 let left = clX ev - ! startx in
236+ let top = clY ev - ! starty in
229237 if ! status = Start
230- then begin
231- status := if abs (clY ev - ! starty) > abs left
232- then Aborted (* vertical scrolling *)
233- else if abs left > Ot_swipe. threshold
234- then begin (* We decide to take the event *)
238+ then
239+ status :=
240+ if ((~% position = `Top || ~% position = `Bottom )
241+ && abs left > abs top)
242+ || ((~% position = `Left || ~% position = `Right )
243+ && abs top > abs left)
244+ then Aborted (* Orthogonal scrolling *)
245+ else if ((~% position = `Top || ~% position = `Bottom )
246+ && abs top < = Ot_swipe. threshold)
247+ || ((~% position = `Left || ~% position = `Right ) &&
248+ abs left < = Ot_swipe. threshold)
249+ then ! status
250+ else begin (* We decide to take the event *)
235251 Manip.Class. add ~% bckgrnd " ot-swiping" ;
236252 (Js.Unsafe. coerce (dr##.style))##.transition :=
237253 Js. string " -webkit-transform 0s, transform 0s" ;
238254 In_progress
239- end
240- else ! status
241- end ;
255+ end ;
242256 if ! status = In_progress
243257 then begin
244258 Dom. preventDefault ev;
245259 Dom_html. stopPropagation ev;
246- if (~% position = `Left && left < = 0 )
247- || (~% position = `Right && left > = 0 )
248- then perform_animation (`Move left)
260+ let move = ref 0 in
261+ if (~% position = `Top && top < = 0 && (move := top; true ))
262+ || (~% position = `Right && left > = 0 && (move := left; true ))
263+ || (~% position = `Bottom && top > = 0 && (move := top; true ))
264+ || (~% position = `Left && left < = 0 && (move := left; true ))
265+ then perform_animation (`Move ! move)
249266 else Lwt. return_unit
250267 end
251268 else Lwt. return_unit
@@ -257,9 +274,12 @@ let%shared drawer
257274 (Js.Unsafe. coerce (dr##.style))##.transition :=
258275 Js. string " -webkit-transform .35s, transform .35s" ;
259276 let width = dr##.offsetWidth in
260- let delta = float_of_int (clX ev - ! startx) in
261- if (~% position = `Left && delta < - 0.3 *. float width)
262- || (~% position = `Right && delta > 0.3 *. float width)
277+ let deltaX = float_of_int (clX ev - ! startx) in
278+ let deltaY = float_of_int (clY ev - ! starty) in
279+ if (~% position = `Top && deltaY < - 0.3 *. float width)
280+ || (~% position = `Right && deltaX > 0.3 *. float width)
281+ || (~% position = `Bottom && deltaY > 0.3 *. float width)
282+ || (~% position = `Left && deltaX < - 0.3 *. float width)
263283 then perform_animation `Close
264284 else perform_animation `Open
265285 end
0 commit comments