Skip to content

Commit bb01f08

Browse files
committed
refactor: simplify example menu
1 parent 5b4958f commit bb01f08

1 file changed

Lines changed: 53 additions & 86 deletions

File tree

example/src/App.tsx

Lines changed: 53 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,44 @@ import StateMachineInputsExample from './pages/RiveStateMachineInputsExample';
1515
import TextRunExample from './pages/RiveTextRunExample';
1616
import OutOfBandAssets from './pages/OutOfBandAssets';
1717

18+
const Examples = [
19+
{
20+
title: 'Rive File Loading Examples',
21+
screenId: 'RiveFileLoading',
22+
component: RiveFileLoadingExample,
23+
},
24+
{
25+
title: 'Rive Data Binding Example',
26+
screenId: 'RiveDataBinding',
27+
component: DataBindingExample,
28+
},
29+
{
30+
title: 'Rive Events Example',
31+
screenId: 'RiveEvents',
32+
component: EventsExample,
33+
},
34+
{
35+
title: 'Rive State Machine Inputs Example',
36+
screenId: 'RiveStateMachineInputs',
37+
component: StateMachineInputsExample,
38+
},
39+
{
40+
title: 'Rive Text Run Example',
41+
screenId: 'RiveTextRun',
42+
component: TextRunExample,
43+
},
44+
{
45+
title: 'Out of band assets',
46+
screenId: 'OutOfBandAssets',
47+
component: OutOfBandAssets,
48+
},
49+
{ title: 'Template Page', screenId: 'Template', component: TemplatePage },
50+
] as const;
51+
1852
type RootStackParamList = {
1953
Home: undefined;
20-
RiveFileLoading: undefined;
21-
RiveDataBinding: undefined;
22-
RiveEvents: undefined;
23-
RiveStateMachineInputs: undefined;
24-
RiveTextRun: undefined;
25-
Template: undefined;
26-
OutOfBandAssets: undefined;
54+
} & {
55+
[K in (typeof Examples)[number]['screenId']]: undefined;
2756
};
2857

2958
const Stack = createStackNavigator<RootStackParamList>();
@@ -33,50 +62,15 @@ function HomeScreen({ navigation }: { navigation: any }) {
3362
<ScrollView style={styles.container}>
3463
<Text style={styles.header}>Rive React Native Examples</Text>
3564
<View style={styles.buttonContainer}>
36-
<TouchableOpacity
37-
style={styles.button}
38-
onPress={() => navigation.navigate('RiveFileLoading')}
39-
>
40-
<Text style={styles.buttonText}>Rive File Loading Examples</Text>
41-
</TouchableOpacity>
42-
<TouchableOpacity
43-
style={styles.button}
44-
onPress={() => navigation.navigate('RiveDataBinding')}
45-
>
46-
<Text style={styles.buttonText}>Rive Data Binding Example</Text>
47-
</TouchableOpacity>
48-
<TouchableOpacity
49-
style={styles.button}
50-
onPress={() => navigation.navigate('RiveEvents')}
51-
>
52-
<Text style={styles.buttonText}>Rive Events Example</Text>
53-
</TouchableOpacity>
54-
<TouchableOpacity
55-
style={styles.button}
56-
onPress={() => navigation.navigate('RiveStateMachineInputs')}
57-
>
58-
<Text style={styles.buttonText}>
59-
Rive State Machine Inputs Example
60-
</Text>
61-
</TouchableOpacity>
62-
<TouchableOpacity
63-
style={styles.button}
64-
onPress={() => navigation.navigate('RiveTextRun')}
65-
>
66-
<Text style={styles.buttonText}>Rive Text Run Example</Text>
67-
</TouchableOpacity>
68-
<TouchableOpacity
69-
style={styles.button}
70-
onPress={() => navigation.navigate('OutOfBandAssets')}
71-
>
72-
<Text style={styles.buttonText}>Out of band assets</Text>
73-
</TouchableOpacity>
74-
<TouchableOpacity
75-
style={styles.button}
76-
onPress={() => navigation.navigate('Template')}
77-
>
78-
<Text style={styles.buttonText}>Template Page</Text>
79-
</TouchableOpacity>
65+
{Examples.map(({ title, screenId }) => (
66+
<TouchableOpacity
67+
key={screenId}
68+
style={styles.button}
69+
onPress={() => navigation.navigate(screenId)}
70+
>
71+
<Text style={styles.buttonText}>{title}</Text>
72+
</TouchableOpacity>
73+
))}
8074
</View>
8175
</ScrollView>
8276
);
@@ -101,41 +95,14 @@ export default function App() {
10195
component={HomeScreen}
10296
options={{ title: 'Rive Examples' }}
10397
/>
104-
<Stack.Screen
105-
name="RiveFileLoading"
106-
component={RiveFileLoadingExample}
107-
options={{ title: 'Rive File Loading' }}
108-
/>
109-
<Stack.Screen
110-
name="RiveDataBinding"
111-
component={DataBindingExample}
112-
options={{ title: 'Rive Data Binding' }}
113-
/>
114-
<Stack.Screen
115-
name="RiveEvents"
116-
component={EventsExample}
117-
options={{ title: 'Rive Events' }}
118-
/>
119-
<Stack.Screen
120-
name="RiveStateMachineInputs"
121-
component={StateMachineInputsExample}
122-
options={{ title: 'Rive State Machine Inputs' }}
123-
/>
124-
<Stack.Screen
125-
name="RiveTextRun"
126-
component={TextRunExample}
127-
options={{ title: 'Rive Text Runs' }}
128-
/>
129-
<Stack.Screen
130-
name="OutOfBandAssets"
131-
component={OutOfBandAssets}
132-
options={{ title: 'Out of Band Asset' }}
133-
/>
134-
<Stack.Screen
135-
name="Template"
136-
component={TemplatePage}
137-
options={{ title: 'Template' }}
138-
/>
98+
{Examples.map(({ screenId, component, title }) => (
99+
<Stack.Screen
100+
key={screenId}
101+
name={screenId}
102+
component={component}
103+
options={{ title }}
104+
/>
105+
))}
139106
</Stack.Navigator>
140107
</NavigationContainer>
141108
);

0 commit comments

Comments
 (0)