Skip to content

Commit c1303cc

Browse files
committed
Use the "enabled" flag rather than removing event handlers - this fixes horizontal dragging being broken in Expo 46 in the first card in the stack.
1 parent 4c2239d commit c1303cc

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

react-native/components/createStackRoutingComponent/Card/index.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,14 @@ export const Card: React.FunctionComponent<
2424
return (
2525
<Swipeable
2626
ref={ref}
27+
enabled={allowsSwiping}
2728
childrenContainerStyle={styles.swipeableChildrenContainer}
28-
{...(allowsSwiping
29-
? {
30-
renderLeftActions: () => <View style={styles.leftActionsView} />,
31-
onSwipeableLeftOpen() {
32-
onBack(pop, () => {
33-
ref.current?.close();
34-
});
35-
},
36-
}
37-
: {})}
29+
renderLeftActions={() => <View style={styles.leftActionsView} />}
30+
onSwipeableLeftOpen={() => {
31+
onBack(pop, () => {
32+
ref.current?.close();
33+
});
34+
}}
3835
>
3936
{children}
4037
</Swipeable>

react-native/components/createStackRoutingComponent/Card/unit.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,19 @@ test(`renders as expected when disallowing swiping`, () => {
2525
children: `Example Children`,
2626
},
2727
}),
28+
renderLeftActions: expect.any(Function),
29+
onSwipeableLeftOpen: expect.any(Function),
30+
enabled: false,
2831
},
2932
}),
3033
});
3134

35+
expect(
36+
(renderer.toTree()?.rendered as TestRenderer.ReactTestRendererTree).props[
37+
`renderLeftActions`
38+
]()
39+
).toEqual(<View style={{ width: `100%` }} />);
40+
3241
expect(pop).not.toHaveBeenCalled();
3342
expect(onBack).not.toHaveBeenCalled();
3443
expect(
@@ -62,6 +71,7 @@ test(`renders as expected when allowing swiping`, () => {
6271
}),
6372
renderLeftActions: expect.any(Function),
6473
onSwipeableLeftOpen: expect.any(Function),
74+
enabled: true,
6575
},
6676
}),
6777
});

0 commit comments

Comments
 (0)