-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add reanimated jota and gesturehandler
- Loading branch information
Showing
39 changed files
with
3,524 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Aleksa Bacovic | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# `rescript-gesture-handler` | ||
|
||
ReScript bindings for `react-native-gesture-handler`. | ||
|
||
`rescript-gesture-handler` `x.y.*` means it's compatible with `react-native-gesture-handler` `x.y.*` | ||
|
||
**NOTE:** `v2` isn't backwards compatible with `v1`, even though original `react-native-gesture-handler` is. Mainly because I believe they will be dropping support for it in the near future (they already warn you if you are using `v1` API). | ||
|
||
## Status | ||
|
||
Work in progress. | ||
|
||
### v1 (See `v1.10.0` branch) | ||
|
||
**NOTE:** There won't be any progress with `v1` until `v2` is finished. | ||
|
||
- [x] `FlingGestureHandler` | ||
- [ ] `PanGestureHandler` | ||
- [ ] ... | ||
|
||
### v2 | ||
|
||
- [x] `Fling` | ||
- [x] `Pan` | ||
- [ ] `Pinch` | ||
- [ ] `Force` | ||
- [ ] ... | ||
|
||
## Installation | ||
|
||
### v1 | ||
|
||
``` | ||
npm install [email protected] | ||
# or | ||
yarn add [email protected] | ||
``` | ||
|
||
### v2 | ||
|
||
``` | ||
npm install rescript-gesture-handler | ||
# or | ||
yarn add rescript-gesture-handler | ||
``` | ||
|
||
## Example (v2) | ||
|
||
### Fling | ||
|
||
```res | ||
open Directions | ||
let flingGesture = | ||
Gesture.makeFling() | ||
->Fling.direction(Direction.make(directions.left)) | ||
->Fling.onEnd((_event, _success) => ResAnimated.runOnJS(__someFunction__)(.)) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "rescript-gesture-handler", | ||
"reason": { "react-jsx": 3 }, | ||
"sources": [ | ||
{ | ||
"dir": "src", | ||
"subdirs": true | ||
} | ||
], | ||
"package-specs": [ | ||
{ | ||
"module": "es6", | ||
"in-source": true | ||
} | ||
], | ||
"suffix": ".bs.js", | ||
"bs-dependencies": ["@rescript/react", "rescript-react-native"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"name": "rescript-gesture-handler", | ||
"description": "ReScript bindings for react-native-gesture-handler", | ||
"version": "2.2.2", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/reck753/rescript-gesture-handler.git" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"keywords": [ | ||
"rescript", | ||
"react-native", | ||
"react-native-gesture-handler" | ||
], | ||
"license": "MIT", | ||
"scripts": { | ||
"format:most": "prettier --write \"**/*.{md,json,js,css}\"", | ||
"format:res": "rescript format -all", | ||
"format:all": "yarn format:most && yarn format:res", | ||
"clean": "rescript clean", | ||
"build": "rescript clean && rescript build -with-deps", | ||
"watch": "rescript clean && rescript build -with-deps -w" | ||
}, | ||
"peerDependencies": { | ||
"@rescript/react": "^0.10.3", | ||
"react-native-gesture-handler": "~2.2.0", | ||
"rescript-react-native": "^0.64.3 || ^0.65.0 || ^0.66.0" | ||
}, | ||
"devDependencies": { | ||
"@rescript/react": "^0.10.3", | ||
"rescript-react-native": "^0.64.3 || ^0.65.0 || ^0.66.0", | ||
"rescript": "^9.1.4", | ||
"prettier": "^2.5.1" | ||
}, | ||
"prettier": { | ||
"trailingComma": "all" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/reck753/rescript-gesture-handler/issues" | ||
}, | ||
"homepage": "https://github.com/reck753/rescript-gesture-handler#readme" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
type directions = { | ||
@as("RIGHT") right: int, | ||
@as("LEFT") left: int, | ||
@as("UP") up: int, | ||
@as("DOWN") down: int, | ||
} | ||
|
||
@module("react-native-gesture-handler") | ||
external directions: directions = "Directions" | ||
|
||
module type Direction = { | ||
type t | ||
let make: int => t | ||
} | ||
|
||
module Direction = { | ||
type t = int | ||
let make = direction => direction | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
type handlerStateChangeEventPayload = { | ||
// Flign specific | ||
x: float, | ||
y: float, | ||
absoluteX: float, | ||
absoluteY: float, | ||
// Common | ||
handlerTag: int, | ||
numberOfPointers: int, | ||
state: GestureHandlerCommon.state, | ||
oldState: GestureHandlerCommon.state, | ||
} | ||
|
||
module GestureHandlerCallbacks = GestureHandlerCommon.GestureHandlerCallbacks.Make({ | ||
type gestureStateChangeEvent = handlerStateChangeEventPayload | ||
}) | ||
|
||
type config = { | ||
// Fling specific | ||
direction: option<Directions.Direction.t>, | ||
numberOfPointers: option<int>, | ||
// Common | ||
enabled: option<bool>, | ||
shouldCancelWhenOutside: option<bool>, | ||
hitSlop: option<GestureHandlerCommon.HitSlop.t>, | ||
ref: option<Js.Nullable.t<React.ref<GestureHandlerCommon.GestureType.t>>>, | ||
requireToFail: option<array<GestureHandlerCommon.GestureRef.t>>, | ||
simultaneousWith: option<array<GestureHandlerCommon.GestureRef.t>>, | ||
needsPointerData: option<bool>, | ||
manualActivation: option<bool>, | ||
} | ||
|
||
type t = { | ||
// Fling specific | ||
config: config, | ||
// Common | ||
handlerTag: int, | ||
handlerName: string, | ||
handlers: GestureHandlerCallbacks.t, | ||
} | ||
|
||
// Fling specific | ||
@send external direction: (t, Directions.Direction.t) => t = "direction" | ||
@send external numberOfPointers: (t, int) => t = "numberOfPointers" | ||
// Common | ||
include GestureHandlerCommon.Methods({ | ||
type t = t | ||
type gestureStateChangeEvent = handlerStateChangeEventPayload | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
type t | ||
|
||
external fling: Fling.t => t = "%identity" | ||
external pan: Pan.t => t = "%identity" | ||
|
||
@module("react-native-gesture-handler") @scope("Gesture") | ||
external makeFling: unit => Fling.t = "Fling" | ||
|
||
@module("react-native-gesture-handler") @scope("Gesture") | ||
external makePan: unit => Pan.t = "Pan" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@react.component @module("react-native-gesture-handler") | ||
external make: (~gesture: Gesture.t, ~children: React.element) => React.element = "GestureDetector" |
128 changes: 128 additions & 0 deletions
128
drafts/rescript-gesture-handler/src/GestureHandlerCommon.res
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
type state = [#0 | #1 | #2 | #3 | #4 | #5] | ||
|
||
type eventType = [#0 | #1 | #2 | #3 | #4] | ||
|
||
type touchData = {id: int, x: float, y: float, absoluteX: float, absoluteY: float} | ||
|
||
type gestureEventPayload = {numberOfPointers: int, state: state} | ||
|
||
type gestureTouchEvent = { | ||
handlerTag: int, | ||
numberOfTouches: int, | ||
state: state, | ||
eventType: eventType, | ||
allTouches: array<touchData>, | ||
changedTouches: array<touchData>, | ||
} | ||
|
||
module HitSlop = { | ||
type t | ||
type asFloat = float | ||
type asAllSides = { | ||
top: option<float>, | ||
bottom: option<float>, | ||
left: option<float>, | ||
right: option<float>, | ||
vertical: option<float>, | ||
horizontal: option<float>, | ||
} | ||
type asWidthLeft = { | ||
width: float, | ||
left: float, | ||
} | ||
type asWidthRight = { | ||
width: float, | ||
right: float, | ||
} | ||
type asHeightTop = { | ||
height: float, | ||
top: float, | ||
} | ||
type asHeightBottom = { | ||
height: float, | ||
bottom: float, | ||
} | ||
|
||
external float: asFloat => t = "%identity" | ||
external allSides: asAllSides => t = "%identity" | ||
external widthLeft: asWidthLeft => t = "%identity" | ||
external widthRight: asWidthRight => t = "%identity" | ||
external heightTop: asHeightTop => t = "%identity" | ||
external heightBottom: asHeightBottom => t = "%identity" | ||
} | ||
|
||
type touchEventHandlerType = (gestureTouchEvent, GestureStateManager.t) => unit | ||
|
||
module GestureHandlerCallbacks = { | ||
module Make = ( | ||
T: { | ||
type gestureStateChangeEvent | ||
}, | ||
) => { | ||
type t = { | ||
handlerTag: int, | ||
onBegin: option<T.gestureStateChangeEvent => unit>, | ||
onStart: option<T.gestureStateChangeEvent => unit>, | ||
onEnd: option<(T.gestureStateChangeEvent, bool) => unit>, | ||
onFinalize: option<(T.gestureStateChangeEvent, bool) => unit>, | ||
// handlerStateUpdateEvent? | ||
onUpdate: option<T.gestureStateChangeEvent => unit>, | ||
onChange: option<T.gestureStateChangeEvent => unit>, | ||
onTouchesDown: option<touchEventHandlerType>, | ||
onTouchesMove: option<touchEventHandlerType>, | ||
onTouchesUp: option<touchEventHandlerType>, | ||
onTouchesCancelled: option<touchEventHandlerType>, | ||
changeEventCalculator: option< | ||
(gestureEventPayload, option<gestureEventPayload>) => gestureEventPayload, | ||
>, | ||
isWorklet: bool, | ||
} | ||
} | ||
} | ||
|
||
// FIXME This is extremely hard since this has to be some twisted | ||
// recursive type. This literally has to be `Fling.t` | `Pan.t` | ... type | ||
module GestureType = { | ||
type t | ||
} | ||
|
||
module GestureRef = { | ||
type t | ||
type asFloat = float | ||
type asGestureType = GestureType.t | ||
type asRef = Js.Nullable.t<React.ref<GestureType.t>> | ||
|
||
external float: asFloat => t = "%identity" | ||
external gestureType: asGestureType => t = "%identity" | ||
external ref: asRef => t = "%identity" | ||
} | ||
|
||
module Methods = ( | ||
T: { | ||
type t | ||
type gestureStateChangeEvent | ||
}, | ||
) => { | ||
type onEndCallback = (T.gestureStateChangeEvent, bool) => unit | ||
type onFinalizeCallback = (T.gestureStateChangeEvent, bool) => unit | ||
@send external onBegin: (T.t, T.gestureStateChangeEvent => unit) => T.t = "onBegin" | ||
@send external onStart: (T.t, T.gestureStateChangeEvent => unit) => T.t = "onStart" | ||
@send external onEnd: (T.t, onEndCallback) => T.t = "onEnd" | ||
@send external onFinalize: (T.t, onFinalizeCallback) => T.t = "onFinalize" | ||
@send external onUpdate: (T.t, T.gestureStateChangeEvent => unit) => T.t = "onUpdate" | ||
@send | ||
external onTouchesDown: (T.t, touchEventHandlerType) => T.t = "onTouchesDown" | ||
@send external onTouchesUp: (T.t, touchEventHandlerType) => T.t = "onTouchesUp" | ||
@send | ||
external onTouchesMove: (T.t, touchEventHandlerType) => T.t = "onTouchesMove" | ||
@send | ||
external onTouchesCancelled: (T.t, touchEventHandlerType) => T.t = "onTouchesCancelled" | ||
@send external enabled: (T.t, bool) => T.t = "enabled" | ||
@send external shouldCancelWhenOutside: (T.t, bool) => T.t = "shouldCancelWhenOutside" | ||
@send external hitSlop: (T.t, HitSlop.t) => T.t = "hitSlop" | ||
// @send external simultaneousWithExternalGesture: - TODO too hard to type right now. Appears like React.ref<T.t> | ||
// @send external requireExternalGestureToFail: - TODO too hard to type right now. Appears like React.ref<T.t> | ||
@send external initialize: (T.t, unit) => unit = "initialize" | ||
@send external toGestureArray: (T.t, unit) => array<T.t> = "toGestureArray" | ||
@send external prepare: (T.t, unit) => unit = "prepare" | ||
} |
11 changes: 11 additions & 0 deletions
11
drafts/rescript-gesture-handler/src/GestureStateManager.res
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
type t = { | ||
begin: unit => unit, | ||
activate: unit => unit, | ||
fail: unit => unit, | ||
end: unit => unit, | ||
} | ||
|
||
type gestureStateManager = {create: int => t} | ||
|
||
@module("react-native-gesture-handler") | ||
external gestureStateManager: gestureStateManager = "GestureStateManager" |
Oops, something went wrong.