From c1303cc332d874a59e54793451c35259e04bd5c2 Mon Sep 17 00:00:00 2001 From: jameswilddev Date: Mon, 5 Sep 2022 09:08:37 +0100 Subject: [PATCH] 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. --- .../createStackRoutingComponent/Card/index.tsx | 17 +++++++---------- .../createStackRoutingComponent/Card/unit.tsx | 10 ++++++++++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/react-native/components/createStackRoutingComponent/Card/index.tsx b/react-native/components/createStackRoutingComponent/Card/index.tsx index 13807f66..69200d5c 100644 --- a/react-native/components/createStackRoutingComponent/Card/index.tsx +++ b/react-native/components/createStackRoutingComponent/Card/index.tsx @@ -24,17 +24,14 @@ export const Card: React.FunctionComponent< return ( , - onSwipeableLeftOpen() { - onBack(pop, () => { - ref.current?.close(); - }); - }, - } - : {})} + renderLeftActions={() => } + onSwipeableLeftOpen={() => { + onBack(pop, () => { + ref.current?.close(); + }); + }} > {children} diff --git a/react-native/components/createStackRoutingComponent/Card/unit.tsx b/react-native/components/createStackRoutingComponent/Card/unit.tsx index a0a60a44..db453537 100644 --- a/react-native/components/createStackRoutingComponent/Card/unit.tsx +++ b/react-native/components/createStackRoutingComponent/Card/unit.tsx @@ -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(); + expect(pop).not.toHaveBeenCalled(); expect(onBack).not.toHaveBeenCalled(); expect( @@ -62,6 +71,7 @@ test(`renders as expected when allowing swiping`, () => { }), renderLeftActions: expect.any(Function), onSwipeableLeftOpen: expect.any(Function), + enabled: true, }, }), });