Skip to content

Commit 8fc4f04

Browse files
authored
Test examples (#3961)
## Description This PR ports some legacy examples to v3, which I didn't rewrite previosuly in #3857. Particularly those marked as "release tests" and those related to pressable. It also adds two new examples: * reattach, for testing whether gesture reattaching works, because I often find myself testing it * timer, inspired by old multitap example, which I found confusing. ## Test plan Check if the examples work
1 parent 18af65a commit 8fc4f04

File tree

19 files changed

+1288
-19
lines changed

19 files changed

+1288
-19
lines changed

apps/common-app/src/common.tsx

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ export interface ExamplesSection {
3232
data: Example[];
3333
}
3434

35+
export const COLORS = {
36+
offWhite: '#f8f9ff',
37+
headerSeparator: '#eef0ff',
38+
PURPLE: '#b58df1',
39+
NAVY: '#001A72',
40+
RED: '#A41623',
41+
YELLOW: '#F2AF29',
42+
GREEN: '#0F956F',
43+
GRAY: '#ADB1C2',
44+
KINDA_RED: '#FFB2AD',
45+
KINDA_YELLOW: '#FFF096',
46+
KINDA_GREEN: '#C4E7DB',
47+
KINDA_BLUE: '#A0D5EF',
48+
};
49+
3550
/* eslint-disable react-native/no-unused-styles */
3651
export const commonStyles = StyleSheet.create({
3752
centerView: {
@@ -44,6 +59,8 @@ export const commonStyles = StyleSheet.create({
4459
width: 150,
4560
borderRadius: 20,
4661
marginBottom: 30,
62+
justifyContent: 'center',
63+
alignItems: 'center',
4764
},
4865
ball: {
4966
height: 120,
@@ -72,6 +89,25 @@ export const commonStyles = StyleSheet.create({
7289
justifyContent: 'center',
7390
textAlign: 'center',
7491
},
92+
row: {
93+
flex: 1,
94+
justifyContent: 'center',
95+
alignItems: 'center',
96+
flexDirection: 'row',
97+
gap: 40,
98+
padding: 20,
99+
},
100+
centered: {
101+
flexDirection: 'column',
102+
alignItems: 'center',
103+
justifyContent: 'center',
104+
},
105+
caption: {
106+
fontSize: 12,
107+
color: COLORS.GRAY,
108+
fontWeight: '600',
109+
marginTop: 4,
110+
},
75111
});
76112
/* eslint-enable react-native/no-unused-styles */
77113

@@ -93,7 +129,7 @@ const styles = StyleSheet.create({
93129
color: '#4A5568',
94130
},
95131
feedback: {
96-
marginTop: 20,
132+
marginVertical: 10,
97133
fontSize: 16,
98134
fontWeight: '600',
99135
},
@@ -197,21 +233,6 @@ export const Feedback = ({ duration = 1000, ref }: FeedbackProps) => {
197233
);
198234
};
199235

200-
export const COLORS = {
201-
offWhite: '#f8f9ff',
202-
headerSeparator: '#eef0ff',
203-
PURPLE: '#b58df1',
204-
NAVY: '#001A72',
205-
RED: '#A41623',
206-
YELLOW: '#F2AF29',
207-
GREEN: '#0F956F',
208-
GRAY: '#ADB1C2',
209-
KINDA_RED: '#FFB2AD',
210-
KINDA_YELLOW: '#FFF096',
211-
KINDA_GREEN: '#C4E7DB',
212-
KINDA_BLUE: '#A0D5EF',
213-
};
214-
215236
const LOREM_IPSUM = `
216237
Curabitur accumsan sit amet massa quis cursus. Fusce sollicitudin nunc nisl, quis efficitur quam tristique eget. Ut non erat molestie, ullamcorper turpis nec, euismod neque. Praesent aliquam risus ultricies, cursus mi consectetur, bibendum lorem. Nunc eleifend consectetur metus quis pulvinar. In vitae lacus eu nibh tincidunt sagittis ut id lorem. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Quisque sagittis mauris rhoncus, maximus justo in, consequat dolor. Pellentesque ornare laoreet est vulputate vestibulum. Aliquam sit amet metus lorem.
217238

apps/common-app/src/legacy/release_tests/gesturizedPressable/testingBase.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {
77
PressableProps as RNPressableProps,
88
} from 'react-native';
99
import {
10-
Pressable as GesturizedPressable,
11-
PressableProps as GHPressableProps,
10+
LegacyPressable as GesturizedPressable,
11+
LegacyPressableProps as GHPressableProps,
1212
} from 'react-native-gesture-handler';
1313

1414
const TestingBase = (props: GHPressableProps & RNPressableProps) => (

apps/common-app/src/new_api/hover_mouse/mouse_buttons/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,15 @@ function Tests({ name, color, mouseButton, feedbackRef }: TestsProps) {
7070
onUpdate: () => {
7171
feedbackRef.current?.showMessage(`Panning with ${name}`);
7272
},
73+
disableReanimated: true,
7374
});
7475

7576
const longPress = useLongPressGesture({
7677
mouseButton,
7778
onActivate: () => {
7879
feedbackRef.current?.showMessage(`LongPress with ${name}`);
7980
},
81+
disableReanimated: true,
8082
});
8183

8284
const fling = useFlingGesture({
@@ -85,6 +87,7 @@ function Tests({ name, color, mouseButton, feedbackRef }: TestsProps) {
8587
onActivate: () => {
8688
feedbackRef.current?.showMessage(`Fling with ${name}`);
8789
},
90+
disableReanimated: true,
8891
});
8992

9093
const gestures = [tap, longPress, pan, fling];

apps/common-app/src/new_api/index.tsx

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import OverlapExample from './showcase/overlap';
55
import SharedValueExample from './showcase/shared_value';
66
import SvgExample from './showcase/svg';
77
import StateManagerExample from './showcase/state_manager';
8+
import TimerExample from './showcase/timer';
89

910
import CameraExample from './complicated/camera';
1011
import ChatHeadsExample from './complicated/chat_heads';
@@ -32,6 +33,15 @@ import ScrollViewExample from './components/scrollview';
3233
import Swipeable from './components/swipeable/index';
3334
import SwitchTextInputExample from './components/switchAndInput';
3435

36+
import RectButtonExample from './tests/rectButton';
37+
import TwoFingerPanExample from './tests/twoFingerPan';
38+
import WebStylesResetExample from './tests/webStylesReset';
39+
import PointerTypeExample from './tests/pointerType';
40+
import ReattachingExample from './tests/reattaching';
41+
import NestedRootViewExample from './tests/nestedRootView';
42+
import NestedPressablesExample from './tests/nestedPressables';
43+
import PressableExample from './tests/pressable';
44+
3545
import { ExamplesSection } from '../common';
3646
import EmptyExample from '../empty';
3747

@@ -62,13 +72,18 @@ export const NEW_EXAMPLES: ExamplesSection[] = [
6272
{ name: 'Bottom Sheet', component: BottomSheetExample },
6373
{ name: 'Overlap', component: OverlapExample },
6474
{ name: 'Animated', component: AnimatedExample },
75+
{ name: 'Timer', component: TimerExample },
6576
],
6677
},
6778
{
6879
sectionTitle: 'Hover and mouse',
6980
data: [
7081
{ name: 'Stylus Data', component: StylusDataExample },
71-
{ name: 'Context Menu', component: ContextMenuExample },
82+
{
83+
name: 'Context Menu',
84+
component: ContextMenuExample,
85+
unsupportedPlatforms: new Set(['android', 'ios', 'macos']),
86+
},
7287
{ name: 'Hover Icons', component: HoverIconsExample },
7388
{ name: 'Hoverable Icons', component: HoverableIconsExample },
7489
{ name: 'Mouse Buttons', component: MouseButtonsExample },
@@ -95,4 +110,21 @@ export const NEW_EXAMPLES: ExamplesSection[] = [
95110
{ name: 'Reanimated Drawer Layout', component: ReanimatedDrawerLayout },
96111
],
97112
},
113+
{
114+
sectionTitle: 'Tests',
115+
data: [
116+
{ name: 'RectButton', component: RectButtonExample },
117+
{ name: 'Two Finger Trackpad Pan', component: TwoFingerPanExample },
118+
{
119+
name: 'Web Styles Reset',
120+
component: WebStylesResetExample,
121+
unsupportedPlatforms: new Set(['android', 'ios', 'macos']),
122+
},
123+
{ name: 'Pointer Type', component: PointerTypeExample },
124+
{ name: 'Reattaching', component: ReattachingExample },
125+
{ name: 'Modal with Nested Root View', component: NestedRootViewExample },
126+
{ name: 'Nested pressables', component: NestedPressablesExample },
127+
{ name: 'Pressable', component: PressableExample },
128+
],
129+
},
98130
];
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import React, { useRef } from 'react';
2+
import { StyleSheet, View, Text, TextInput } from 'react-native';
3+
import {
4+
useLongPressGesture,
5+
GestureDetector,
6+
GestureHandlerRootView,
7+
} from 'react-native-gesture-handler';
8+
import Animated, {
9+
useSharedValue,
10+
withTiming,
11+
cancelAnimation,
12+
Easing,
13+
useAnimatedProps,
14+
useAnimatedStyle,
15+
interpolateColor,
16+
} from 'react-native-reanimated';
17+
import {
18+
Feedback,
19+
FeedbackHandle,
20+
COLORS,
21+
commonStyles,
22+
} from '../../../common';
23+
24+
const AnimatedTextInput = Animated.createAnimatedComponent(TextInput);
25+
26+
export default function TimerExample() {
27+
const feedbackRef = useRef<FeedbackHandle>(null);
28+
const duration = useSharedValue(0);
29+
const colorProgress = useSharedValue(0);
30+
const animatedProps = useAnimatedProps(() => {
31+
return {
32+
text: `Duration: ${duration.value.toFixed(2)}s`,
33+
} as any;
34+
});
35+
36+
const animatedBoxStyle = useAnimatedStyle(() => {
37+
return {
38+
backgroundColor: interpolateColor(
39+
colorProgress.value,
40+
[0, 1],
41+
[COLORS.PURPLE, COLORS.NAVY]
42+
),
43+
};
44+
});
45+
46+
const longPressGesture = useLongPressGesture({
47+
onBegin: () => {
48+
colorProgress.value = withTiming(1, { duration: 150 });
49+
duration.value = 0;
50+
duration.value = withTiming(600, {
51+
duration: 600000,
52+
easing: Easing.linear,
53+
});
54+
},
55+
onFinalize: () => {
56+
colorProgress.value = withTiming(0, { duration: 300 });
57+
cancelAnimation(duration);
58+
},
59+
});
60+
61+
return (
62+
<GestureHandlerRootView style={commonStyles.centerView}>
63+
<View style={styles.container}>
64+
<AnimatedTextInput
65+
underlineColorAndroid="transparent"
66+
editable={false}
67+
value="Duration: 0.00s"
68+
style={styles.timerText}
69+
animatedProps={animatedProps}
70+
/>
71+
<GestureDetector gesture={longPressGesture}>
72+
<Animated.View style={[commonStyles.box, animatedBoxStyle]} />
73+
</GestureDetector>
74+
<Text style={commonStyles.instructions}>
75+
Hold the box to measure press duration
76+
</Text>
77+
<Feedback ref={feedbackRef} />
78+
</View>
79+
</GestureHandlerRootView>
80+
);
81+
}
82+
83+
const styles = StyleSheet.create({
84+
container: {
85+
alignItems: 'center',
86+
justifyContent: 'center',
87+
},
88+
timerText: {
89+
fontSize: 20,
90+
fontWeight: 'bold',
91+
color: COLORS.NAVY,
92+
marginBottom: 20,
93+
textAlign: 'center',
94+
fontVariant: ['tabular-nums'],
95+
},
96+
});

0 commit comments

Comments
 (0)