Skip to content

Commit f4625e2

Browse files
committed
convert to rngh 2.0
1 parent eb1fe50 commit f4625e2

File tree

3 files changed

+31
-59
lines changed

3 files changed

+31
-59
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"homepage": "https://github.com/computerjazz/react-native-swipeable-item#readme",
3737
"peerDependencies": {
3838
"react-native": ">=0.64.0",
39-
"react-native-gesture-handler": ">=1.10.1",
39+
"react-native-gesture-handler": ">=2.0.0",
4040
"react-native-reanimated": ">=2.8.0"
4141
},
4242
"dependencies": {
@@ -52,7 +52,7 @@
5252
"react": "~16.9.0",
5353
"react-native": "^0.62.2",
5454
"react-native-builder-bob": "^0.18.1",
55-
"react-native-gesture-handler": "^1.10.3",
55+
"react-native-gesture-handler": "^2.0.0",
5656
"react-native-reanimated": "^2.8.0",
5757
"typescript": "^4.2.4"
5858
},

src/index.tsx

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ import React, {
77
useState,
88
} from "react";
99
import { StyleSheet } from "react-native";
10-
import {
11-
GestureEvent,
12-
PanGestureHandler,
13-
PanGestureHandlerEventPayload,
14-
} from "react-native-gesture-handler";
10+
import { Gesture, GestureDetector } from "react-native-gesture-handler";
1511
import Animated, {
1612
runOnJS,
1713
useAnimatedGestureHandler,
@@ -266,25 +262,24 @@ function SwipeableItem<T>(
266262
onChange({ open: openDirection, snapPoint });
267263
}
268264

269-
const onGestureEvent = useAnimatedGestureHandler<
270-
GestureEvent<PanGestureHandlerEventPayload>,
271-
{ startX: number }
272-
>({
273-
onStart: (_evt, ctx) => {
274-
ctx.startX = animStatePos.value;
265+
const startX = useSharedValue(0);
266+
267+
const gesture = Gesture.Pan()
268+
.onStart(() => {
269+
startX.value = animStatePos.value;
275270
isGestureActive.value = true;
276-
},
277-
onActive: (evt, ctx) => {
278-
const rawVal = evt.translationX + ctx.startX;
271+
})
272+
.onUpdate((evt) => {
273+
const rawVal = evt.translationX + startX.value;
279274
const clampedVal = interpolate(
280275
rawVal,
281276
[maxTranslateLeft, maxTranslateRight],
282277
[maxTranslateLeft, maxTranslateRight],
283278
Extrapolate.CLAMP
284279
);
285280
animStatePos.value = clampedVal;
286-
},
287-
onEnd: (evt) => {
281+
})
282+
.onEnd((evt) => {
288283
isGestureActive.value = false;
289284

290285
// Approximate where item would end up with velocity taken into account
@@ -322,8 +317,9 @@ function SwipeableItem<T>(
322317
springConfig,
323318
onComplete
324319
);
325-
},
326-
});
320+
})
321+
.enabled(swipeEnabled !== false)
322+
.activeOffsetX(activeOffsetX);
327323

328324
const sharedParams = useMemo(
329325
() => ({
@@ -398,16 +394,12 @@ function SwipeableItem<T>(
398394
{renderUnderlayRight(underlayRightParams)}
399395
</UnderlayContext.Provider>
400396
</Animated.View>
401-
<PanGestureHandler
402-
enabled={swipeEnabled}
403-
activeOffsetX={activeOffsetX}
404-
onGestureEvent={onGestureEvent}
405-
>
397+
<GestureDetector gesture={gesture}>
406398
<Animated.View style={[styles.flex, overlayStyle]}>
407399
{children}
408400
{renderOverlay(overlayParams)}
409401
</Animated.View>
410-
</PanGestureHandler>
402+
</GestureDetector>
411403
</OverlayContext.Provider>
412404
);
413405
}

yarn.lock

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2496,13 +2496,6 @@ create-react-class@^15.6.3:
24962496
loose-envify "^1.3.1"
24972497
object-assign "^4.1.1"
24982498

2499-
cross-fetch@^3.0.4:
2500-
version "3.1.5"
2501-
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.5.tgz#e1389f44d9e7ba767907f7af8454787952ab534f"
2502-
integrity sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==
2503-
dependencies:
2504-
node-fetch "2.6.7"
2505-
25062499
cross-spawn@^5.1.0:
25072500
version "5.1.0"
25082501
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
@@ -2947,19 +2940,6 @@ fbjs@^1.0.0:
29472940
setimmediate "^1.0.5"
29482941
ua-parser-js "^0.7.18"
29492942

2950-
fbjs@^3.0.0:
2951-
version "3.0.0"
2952-
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-3.0.0.tgz#0907067fb3f57a78f45d95f1eacffcacd623c165"
2953-
integrity sha512-dJd4PiDOFuhe7vk4F80Mba83Vr2QuK86FoxtgPmzBqEJahncp+13YCmfoa53KHCo6OnlXLG7eeMWPfB5CrpVKg==
2954-
dependencies:
2955-
cross-fetch "^3.0.4"
2956-
fbjs-css-vars "^1.0.0"
2957-
loose-envify "^1.0.0"
2958-
object-assign "^4.1.0"
2959-
promise "^7.1.1"
2960-
setimmediate "^1.0.5"
2961-
ua-parser-js "^0.7.18"
2962-
29632943
figures@^2.0.0:
29642944
version "2.0.0"
29652945
resolved "https://registry.yarnpkg.com/figures/-/figures-2.0.0.tgz#3ab1a2d2a62c8bfb431a0c94cb797a2fce27c962"
@@ -3881,7 +3861,7 @@ lodash.throttle@^4.1.1:
38813861
resolved "https://registry.yarnpkg.com/lodash.throttle/-/lodash.throttle-4.1.1.tgz#c23e91b710242ac70c37f1e1cda9274cc39bf2f4"
38823862
integrity sha1-wj6RtxAkKscMN/HhzaknTMOb8vQ=
38833863

3884-
lodash@^4.17.14, lodash@^4.17.15, lodash@^4.3.0:
3864+
lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.21, lodash@^4.3.0:
38853865
version "4.17.21"
38863866
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
38873867
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
@@ -4507,13 +4487,6 @@ nocache@^2.1.0:
45074487
resolved "https://registry.yarnpkg.com/nocache/-/nocache-2.1.0.tgz#120c9ffec43b5729b1d5de88cd71aa75a0ba491f"
45084488
integrity sha512-0L9FvHG3nfnnmaEQPjT9xhfN4ISk0A8/2j4M37Np4mcDesJjHgEUfgPhdCyZuFI954tjokaIj/A3NdpFNdEh4Q==
45094489

4510-
[email protected], node-fetch@^2.2.0, node-fetch@^2.6.0:
4511-
version "2.6.7"
4512-
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
4513-
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
4514-
dependencies:
4515-
whatwg-url "^5.0.0"
4516-
45174490
node-fetch@^1.0.1:
45184491
version "1.7.3"
45194492
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
@@ -4522,6 +4495,13 @@ node-fetch@^1.0.1:
45224495
encoding "^0.1.11"
45234496
is-stream "^1.0.1"
45244497

4498+
node-fetch@^2.2.0, node-fetch@^2.6.0:
4499+
version "2.6.7"
4500+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
4501+
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
4502+
dependencies:
4503+
whatwg-url "^5.0.0"
4504+
45254505
node-int64@^0.4.0:
45264506
version "0.4.0"
45274507
resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b"
@@ -5028,15 +5008,15 @@ react-native-builder-bob@^0.18.1:
50285008
optionalDependencies:
50295009
jetifier "^1.6.6"
50305010

5031-
react-native-gesture-handler@^1.10.3:
5032-
version "1.10.3"
5033-
resolved "https://registry.yarnpkg.com/react-native-gesture-handler/-/react-native-gesture-handler-1.10.3.tgz#942bbf2963bbf49fa79593600ee9d7b5dab3cfc0"
5034-
integrity sha512-cBGMi1IEsIVMgoox4RvMx7V2r6bNKw0uR1Mu1o7NbuHS6BRSVLq0dP34l2ecnPlC+jpWd3le6Yg1nrdCjby2Mw==
5011+
react-native-gesture-handler@^2.0.0:
5012+
version "2.5.0"
5013+
resolved "https://registry.yarnpkg.com/react-native-gesture-handler/-/react-native-gesture-handler-2.5.0.tgz#61385583570ed0a45a9ed142425e35f8fe8274fb"
5014+
integrity sha512-djZdcprFf08PZC332D+AeG5wcGeAPhzfCJtB3otUgOgTlvjVXmg/SLFdPJSpzLBqkRAmrC77tM79QgKbuLxkfw==
50355015
dependencies:
50365016
"@egjs/hammerjs" "^2.0.17"
5037-
fbjs "^3.0.0"
50385017
hoist-non-react-statics "^3.3.0"
50395018
invariant "^2.2.4"
5019+
lodash "^4.17.21"
50405020
prop-types "^15.7.2"
50415021

50425022
react-native-reanimated@^2.8.0:

0 commit comments

Comments
 (0)