Skip to content

Commit 06ad351

Browse files
committed
fix state on imperative open/close
1 parent f4625e2 commit 06ad351

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/index.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { StyleSheet } from "react-native";
1010
import { Gesture, GestureDetector } from "react-native-gesture-handler";
1111
import Animated, {
1212
runOnJS,
13-
useAnimatedGestureHandler,
1413
useAnimatedStyle,
1514
useDerivedValue,
1615
useSharedValue,
@@ -183,16 +182,17 @@ function SwipeableItem<T>(
183182
);
184183

185184
const openLeft: OpenPromiseFn = (snapPoint, options) => {
185+
const toValue = snapPoint ?? maxSnapPointLeft;
186+
186187
return new Promise<void>((resolve) => {
187188
function resolvePromiseIfFinished(isFinished: boolean) {
188189
if (isFinished) resolve();
190+
onAnimationEnd(OpenDirection.LEFT, toValue);
189191
}
190192

191-
const toValue = snapPoint ?? maxSnapPointLeft;
192-
193193
if (options?.animated === false) {
194194
animStatePos.value = toValue;
195-
resolve();
195+
runOnJS(resolvePromiseIfFinished)(true);
196196
} else {
197197
animStatePos.value = withSpring(toValue, springConfig, (isFinished) => {
198198
if (isFinished) {
@@ -204,16 +204,17 @@ function SwipeableItem<T>(
204204
};
205205

206206
const openRight: OpenPromiseFn = (snapPoint, options) => {
207+
const toValue = snapPoint ?? maxSnapPointRight;
208+
207209
return new Promise<void>((resolve) => {
208210
function resolvePromiseIfFinished(isFinished: boolean) {
209211
if (isFinished) resolve();
212+
onAnimationEnd(OpenDirection.RIGHT, toValue);
210213
}
211214

212-
const toValue = snapPoint ?? maxSnapPointRight;
213-
214215
if (options?.animated === false) {
215216
animStatePos.value = toValue;
216-
resolve();
217+
runOnJS(resolvePromiseIfFinished)(true);
217218
} else {
218219
animStatePos.value = withSpring(toValue, springConfig, (isFinished) => {
219220
if (isFinished) {
@@ -225,16 +226,18 @@ function SwipeableItem<T>(
225226
};
226227

227228
const close: ClosePromiseFn = (options) => {
229+
const toValue = 0;
228230
return new Promise<void>((resolve) => {
229231
function resolvePromiseIfFinished(isFinished: boolean) {
230232
if (isFinished) resolve();
233+
onAnimationEnd(OpenDirection.NONE, toValue);
231234
}
232235

233236
if (options?.animated === false) {
234-
animStatePos.value = 0;
235-
resolve();
237+
animStatePos.value = toValue;
238+
runOnJS(resolvePromiseIfFinished)(true);
236239
} else {
237-
animStatePos.value = withSpring(0, springConfig, (isFinished) => {
240+
animStatePos.value = withSpring(toValue, springConfig, (isFinished) => {
238241
if (isFinished) {
239242
runOnJS(resolvePromiseIfFinished)(isFinished);
240243
}

0 commit comments

Comments
 (0)