Skip to content

Commit 4c9e720

Browse files
committed
merge swipeable examples
1 parent c52d675 commit 4c9e720

File tree

3 files changed

+132
-152
lines changed

3 files changed

+132
-152
lines changed

example/App.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import NestedTouchables from './src/release_tests/nestedTouchables';
3636
import NestedPressables from './src/release_tests/nestedPressables';
3737
import NestedButtons from './src/release_tests/nestedButtons';
3838
import PointerType from './src/release_tests/pointerType';
39-
import SwipeableReanimation from './src/release_tests/swipeableReanimation';
4039
import NestedGestureHandlerRootViewWithModal from './src/release_tests/nestedGHRootViewWithModal';
4140
import TwoFingerPan from './src/release_tests/twoFingerPan';
4241
import { PinchableBox } from './src/recipes/scaleAndRotate';
@@ -192,7 +191,6 @@ const EXAMPLES: ExamplesSection[] = [
192191
},
193192
{ name: 'PointerType', component: PointerType },
194193
{ name: 'Reanimated Drawer Layout', component: ReanimatedDrawerLayout },
195-
{ name: 'Swipeable Reanimation', component: SwipeableReanimation },
196194
{ name: 'RectButton (borders)', component: RectButtonBorders },
197195
{ name: 'Gesturized pressable', component: GesturizedPressable },
198196
{

example/src/new_api/swipeable/index.tsx

Lines changed: 132 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
import React from 'react';
1+
import React, { useRef } from 'react';
22
import { StyleSheet, Text, View, I18nManager } from 'react-native';
33

4-
import { FlatList, RectButton } from 'react-native-gesture-handler';
4+
import { FlatList, Pressable, RectButton } from 'react-native-gesture-handler';
5+
6+
import Reanimated, {
7+
SharedValue,
8+
useAnimatedStyle,
9+
} from 'react-native-reanimated';
510

611
import AppleStyleSwipeableRow from './AppleStyleSwipeableRow';
712
import GmailStyleSwipeableRow from './GmailStyleSwipeableRow';
813

14+
import ReanimatedSwipeable, {
15+
SwipeableMethods,
16+
} from 'react-native-gesture-handler/ReanimatedSwipeable';
17+
918
// To toggle LTR/RTL change to `true`
1019
I18nManager.allowRTL(false);
1120

@@ -42,25 +51,111 @@ const SwipeableRow = ({ item, index }: { item: DataRow; index: number }) => {
4251
}
4352
};
4453

54+
function LeftAction(prog: SharedValue<number>, drag: SharedValue<number>) {
55+
const styleAnimation = useAnimatedStyle(() => {
56+
console.log('[R] showLeftProgress:', prog.value);
57+
console.log('[R] appliedTranslation:', drag.value);
58+
59+
return {
60+
transform: [{ translateX: drag.value - 60 }],
61+
};
62+
});
63+
64+
return (
65+
<Reanimated.View style={styleAnimation}>
66+
<Text style={styles.leftAction}>Text</Text>
67+
</Reanimated.View>
68+
);
69+
}
70+
71+
function RightAction(prog: SharedValue<number>, drag: SharedValue<number>) {
72+
const styleAnimation = useAnimatedStyle(() => {
73+
console.log('[R] showRightProgress:', prog.value);
74+
console.log('[R] appliedTranslation:', drag.value);
75+
76+
return {
77+
transform: [{ translateX: drag.value + 60 }],
78+
};
79+
});
80+
81+
return (
82+
<Reanimated.View style={styleAnimation}>
83+
<Text style={styles.rightAction}>Text</Text>
84+
</Reanimated.View>
85+
);
86+
}
87+
4588
const Separator = () => <View style={styles.separator} />;
4689

4790
export default function App() {
91+
const reanimatedRef = useRef<SwipeableMethods>(null);
4892
return (
49-
<FlatList
50-
data={DATA}
51-
ItemSeparatorComponent={Separator}
52-
renderItem={({ item, index }) => (
53-
<SwipeableRow item={item} index={index} />
54-
)}
55-
keyExtractor={(_item, index) => `message ${index}`}
56-
/>
93+
<View>
94+
<Separator />
95+
96+
<View style={styles.controlPanelWrapper}>
97+
<Text style={styles.fromText}>Programatical controls</Text>
98+
<View style={styles.controlPanel}>
99+
<Pressable
100+
style={styles.control}
101+
onPress={() => {
102+
reanimatedRef.current!.openLeft();
103+
}}>
104+
<Text>open left</Text>
105+
</Pressable>
106+
<Pressable
107+
style={styles.control}
108+
onPress={() => {
109+
reanimatedRef.current!.close();
110+
}}>
111+
<Text>close</Text>
112+
</Pressable>
113+
<Pressable
114+
style={styles.control}
115+
onPress={() => {
116+
reanimatedRef.current!.reset();
117+
}}>
118+
<Text>reset</Text>
119+
</Pressable>
120+
<Pressable
121+
style={styles.control}
122+
onPress={() => {
123+
reanimatedRef.current!.openRight();
124+
}}>
125+
<Text>open right</Text>
126+
</Pressable>
127+
</View>
128+
</View>
129+
130+
<Separator />
131+
132+
<ReanimatedSwipeable
133+
ref={reanimatedRef}
134+
containerStyle={styles.swipeable}
135+
friction={2}
136+
leftThreshold={80}
137+
enableTrackpadTwoFingerGesture
138+
rightThreshold={40}
139+
renderLeftActions={LeftAction}
140+
renderRightActions={RightAction}>
141+
<Text>Use the programatic control panel</Text>
142+
</ReanimatedSwipeable>
143+
144+
<Separator />
145+
<FlatList
146+
data={DATA}
147+
ItemSeparatorComponent={Separator}
148+
renderItem={({ item, index }) => (
149+
<SwipeableRow item={item} index={index} />
150+
)}
151+
keyExtractor={(_item, index) => `message ${index}`}
152+
/>
153+
</View>
57154
);
58155
}
59156

60157
const styles = StyleSheet.create({
61158
rectButton: {
62-
flex: 1,
63-
height: 80,
64159
paddingVertical: 10,
65160
paddingHorizontal: 20,
66161
justifyContent: 'space-between',
@@ -87,6 +182,31 @@ const styles = StyleSheet.create({
87182
color: '#999',
88183
fontWeight: 'bold',
89184
},
185+
leftAction: { width: 60, height: 60, backgroundColor: '#ff5ca3' },
186+
rightAction: { width: 60, height: 60, backgroundColor: '#b658b6' },
187+
swipeable: {
188+
height: 60,
189+
backgroundColor: 'white',
190+
alignItems: 'center',
191+
justifyContent: 'center',
192+
},
193+
controlPanelWrapper: {
194+
backgroundColor: 'white',
195+
alignItems: 'center',
196+
},
197+
controlPanel: {
198+
backgroundColor: 'white',
199+
alignItems: 'center',
200+
flexDirection: 'row',
201+
},
202+
control: {
203+
flex: 1,
204+
height: 40,
205+
borderWidth: StyleSheet.hairlineWidth,
206+
borderColor: 'rgb(200, 199, 204)',
207+
alignItems: 'center',
208+
justifyContent: 'center',
209+
},
90210
});
91211

92212
const DATA: DataRow[] = [

example/src/release_tests/swipeableReanimation/index.tsx

Lines changed: 0 additions & 138 deletions
This file was deleted.

0 commit comments

Comments
 (0)