diff --git a/src/panResponderRe.re b/src/panResponderRe.re index c602cb81a1eb41..651b5d0e0b2cb4 100644 --- a/src/panResponderRe.re +++ b/src/panResponderRe.re @@ -1,7 +1,23 @@ type t; -type gestureState = - { +type gestureState = { + stateID: float, + moveX: float, + moveY: float, + x0: float, + y0: float, + dx: float, + dy: float, + vx: float, + vy: float, + numberActiveTouches: int +}; + +external _create : 'a => t = "create" [@@bs.scope "PanResponder"] [@@bs.module "react-native"]; + +type jsGestureState = + Js.t { + . stateID : float, moveX : float, moveY : float, @@ -14,9 +30,24 @@ type gestureState = numberActiveTouches : int }; -type callback 'a = RNEvent.NativeEvent.t => gestureState => 'a; +type callback 'a = Js.t {. nativeEvent : RNEvent.NativeEvent.t} => jsGestureState => 'a; -external _create : 'a => t = "create" [@@bs.scope "PanResponder"] [@@bs.module "react-native"]; +let callback (x: RNEvent.NativeEvent.t => gestureState => 'a) :callback 'a => + fun event state => + x + event##nativeEvent + { + dx: state##dx, + dy: state##dy, + moveX: state##moveX, + moveY: state##moveY, + numberActiveTouches: state##numberActiveTouches, + stateID: state##stateID, + vx: state##vx, + vy: state##vy, + x0: state##x0, + y0: state##y0 + }; external shamelesslyWrapCallback : 'a => callback unit = "%identity"; @@ -34,27 +65,10 @@ let animatedEvent l => { (Js.Obj.empty ()) l; shamelesslyWrapCallback ( - AnimatedRe.event (Array.of_list [Js.null, Js.Null.return config]) {"useNativeDriver": Js.false_} + AnimatedRe.event [|Js.null, Js.Null.return config|] {"useNativeDriver": Js.false_} ) }; -let convertCallback x => - switch x { - | None => Js.undefined; - | Some x => Js.Undefined.return (fun event state => x event##nativeEvent { - dx: state##dx, - dy: state##dy, - moveX: state##moveX, - moveY: state##moveY, - numberActiveTouches: state##numberActiveTouches, - stateID: state##stateID, - vx: state##vx, - vy: state##vy, - x0: state##x0, - y0: state##y0 - }); - }; - let create onMoveShouldSetPanResponder::(onMoveShouldSetPanResponder: option (callback bool))=? onMoveShouldSetPanResponderCapture:: @@ -72,27 +86,27 @@ let create onPanResponderTerminationRequest::(onPanResponderTerminationRequest: option (callback bool))=? onShouldBlockNativeResponder::(onShouldBlockNativeResponder: option (callback bool))=? () => - _create - { - "onMoveShouldSetPanResponder": convertCallback onMoveShouldSetPanResponder, - "onMoveShouldSetPanResponderCapture": convertCallback onMoveShouldSetPanResponderCapture, - "onStartShouldSetPanResponder": convertCallback onStartShouldSetPanResponder, - "onStartShouldSetPanResponderCapture": convertCallback onStartShouldSetPanResponderCapture, - "onPanResponderReject": convertCallback onPanResponderReject, - "onPanResponderGrant": convertCallback onPanResponderGrant, - "onPanResponderStart": convertCallback onPanResponderStart, - "onPanResponderEnd": convertCallback onPanResponderEnd, - "onPanResponderRelease": convertCallback onPanResponderRelease, - "onPanResponderMove": - switch onPanResponderMove { - | None => Js.undefined - | Some x => - switch x { - | `update l => Js.Undefined.return (animatedEvent l) - | `callback (x: callback unit) => Js.Undefined.return x - } - }, - "onPanResponderTerminate": convertCallback onPanResponderTerminate, - "onPanResponderTerminationRequest": convertCallback onPanResponderTerminationRequest, - "onShouldBlockNativeResponder": convertCallback onShouldBlockNativeResponder - }; + _create { + "onMoveShouldSetPanResponder": Js.Undefined.from_opt onMoveShouldSetPanResponder, + "onMoveShouldSetPanResponderCapture": Js.Undefined.from_opt onMoveShouldSetPanResponderCapture, + "onStartShouldSetPanResponder": Js.Undefined.from_opt onStartShouldSetPanResponder, + "onStartShouldSetPanResponderCapture": + Js.Undefined.from_opt onStartShouldSetPanResponderCapture, + "onPanResponderReject": Js.Undefined.from_opt onPanResponderReject, + "onPanResponderGrant": Js.Undefined.from_opt onPanResponderGrant, + "onPanResponderStart": Js.Undefined.from_opt onPanResponderStart, + "onPanResponderEnd": Js.Undefined.from_opt onPanResponderEnd, + "onPanResponderRelease": Js.Undefined.from_opt onPanResponderRelease, + "onPanResponderMove": + switch onPanResponderMove { + | None => Js.undefined + | Some x => + switch x { + | `update l => Js.Undefined.return (animatedEvent l) + | `callback (x: callback unit) => Js.Undefined.return x + } + }, + "onPanResponderTerminate": Js.Undefined.from_opt onPanResponderTerminate, + "onPanResponderTerminationRequest": Js.Undefined.from_opt onPanResponderTerminationRequest, + "onShouldBlockNativeResponder": Js.Undefined.from_opt onShouldBlockNativeResponder + }; \ No newline at end of file diff --git a/src/panResponderRe.rei b/src/panResponderRe.rei index f9b19e2f038b8a..56f60d12a528e0 100644 --- a/src/panResponderRe.rei +++ b/src/panResponderRe.rei @@ -1,21 +1,21 @@ type t; -type gestureState = - { - stateID : float, - moveX : float, - moveY : float, - x0 : float, - y0 : float, - dx : float, - dy : float, - vx : float, - vy : float, - numberActiveTouches : int - }; +type gestureState = { + stateID: float, + moveX: float, + moveY: float, + x0: float, + y0: float, + dx: float, + dy: float, + vx: float, + vy: float, + numberActiveTouches: int +}; +type callback 'a; -type callback 'a = RNEvent.NativeEvent.t => gestureState => 'a; +let callback: (RNEvent.NativeEvent.t => gestureState => 'a) => callback 'a; let create: onMoveShouldSetPanResponder::callback bool? => @@ -28,14 +28,14 @@ let create: onPanResponderEnd::callback unit? => onPanResponderRelease::callback unit? => onPanResponderMove:: - [< + [ | `callback (callback unit) | `update ( - list [< | `X AnimatedRe.Value.t | `XY AnimatedRe.ValueXY.t | `Y AnimatedRe.Value.t] + list [ | `X AnimatedRe.Value.t | `XY AnimatedRe.ValueXY.t | `Y AnimatedRe.Value.t] ) ]? => onPanResponderTerminate::callback unit? => onPanResponderTerminationRequest::callback bool? => onShouldBlockNativeResponder::callback bool? => unit => - t; + t; \ No newline at end of file