Skip to content

Commit

Permalink
Use the "enabled" flag rather than removing event handlers - this fix…
Browse files Browse the repository at this point in the history
…es horizontal dragging being broken in Expo 46 in the first card in the stack.
  • Loading branch information
jameswilddev committed Sep 5, 2022
1 parent 4c2239d commit c1303cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
17 changes: 7 additions & 10 deletions react-native/components/createStackRoutingComponent/Card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,14 @@ export const Card: React.FunctionComponent<
return (
<Swipeable
ref={ref}
enabled={allowsSwiping}
childrenContainerStyle={styles.swipeableChildrenContainer}
{...(allowsSwiping
? {
renderLeftActions: () => <View style={styles.leftActionsView} />,
onSwipeableLeftOpen() {
onBack(pop, () => {
ref.current?.close();
});
},
}
: {})}
renderLeftActions={() => <View style={styles.leftActionsView} />}
onSwipeableLeftOpen={() => {
onBack(pop, () => {
ref.current?.close();
});
}}
>
{children}
</Swipeable>
Expand Down
10 changes: 10 additions & 0 deletions react-native/components/createStackRoutingComponent/Card/unit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,19 @@ test(`renders as expected when disallowing swiping`, () => {
children: `Example Children`,
},
}),
renderLeftActions: expect.any(Function),
onSwipeableLeftOpen: expect.any(Function),
enabled: false,
},
}),
});

expect(
(renderer.toTree()?.rendered as TestRenderer.ReactTestRendererTree).props[
`renderLeftActions`
]()
).toEqual(<View style={{ width: `100%` }} />);

expect(pop).not.toHaveBeenCalled();
expect(onBack).not.toHaveBeenCalled();
expect(
Expand Down Expand Up @@ -62,6 +71,7 @@ test(`renders as expected when allowing swiping`, () => {
}),
renderLeftActions: expect.any(Function),
onSwipeableLeftOpen: expect.any(Function),
enabled: true,
},
}),
});
Expand Down

0 comments on commit c1303cc

Please sign in to comment.