@@ -40,6 +40,20 @@ export default function MenuListExample() {
4040function MenuList ( { file } : { file : RiveFile } ) {
4141 const instance = useViewModelInstance ( file ) ;
4242
43+ if ( ! instance ) {
44+ return < ActivityIndicator size = "large" color = "#007AFF" /> ;
45+ }
46+
47+ return < MenuListContent file = { file } instance = { instance } /> ;
48+ }
49+
50+ function MenuListContent ( {
51+ file,
52+ instance,
53+ } : {
54+ file : RiveFile ;
55+ instance : ViewModelInstance ;
56+ } ) {
4357 const addLabelRef = useRef < TextInput > ( null ) ;
4458 const lastAdded = useRef < ViewModelInstance | null > ( null ) ;
4559 const indexToDeleteRef = useRef < TextInput > ( null ) ;
@@ -115,22 +129,18 @@ function MenuList({ file }: { file: RiveFile }) {
115129 menuItemLabel . value = label ;
116130 } ;
117131
118- const controlsDisabled = ! instance ;
119-
120132 return (
121133 < View style = { styles . container } >
122134 < RiveView
123135 style = { styles . rive }
124136 autoPlay = { true }
125- dataBind = { instance ?? undefined }
137+ dataBind = { instance }
126138 fit = { Fit . FitWidth }
127139 file = { file }
128140 />
129141
130142 < ScrollView style = { styles . controls } >
131- < Text style = { styles . listLength } >
132- { instance ? `Menu Items: ${ length } ` : 'Loading...' }
133- </ Text >
143+ < Text style = { styles . listLength } > Menu Items: { length } </ Text >
134144 { error && < Text style = { styles . errorText } > { error . message } </ Text > }
135145
136146 < View style = { styles . controlGroup } >
@@ -142,17 +152,12 @@ function MenuList({ file }: { file: RiveFile }) {
142152 onChangeText = { ( text ) => ( addLabelValue . current = text ) }
143153 />
144154 < TouchableOpacity
145- style = { [ styles . button , controlsDisabled && styles . buttonDisabled ] }
155+ style = { styles . button }
146156 onPress = { ( ) => addNewMenuItem ( addLabelValue . current ) }
147- disabled = { controlsDisabled }
148157 >
149158 < Text style = { styles . buttonText } > Add Menu Item</ Text >
150159 </ TouchableOpacity >
151- < TouchableOpacity
152- style = { [ styles . button , controlsDisabled && styles . buttonDisabled ] }
153- onPress = { removeLastAdded }
154- disabled = { controlsDisabled }
155- >
160+ < TouchableOpacity style = { styles . button } onPress = { removeLastAdded } >
156161 < Text style = { styles . buttonText } > Delete Last Added</ Text >
157162 </ TouchableOpacity >
158163 </ View >
@@ -166,11 +171,10 @@ function MenuList({ file }: { file: RiveFile }) {
166171 onChangeText = { ( text ) => ( indexToDeleteValue . current = text ) }
167172 />
168173 < TouchableOpacity
169- style = { [ styles . button , controlsDisabled && styles . buttonDisabled ] }
174+ style = { styles . button }
170175 onPress = { ( ) =>
171176 removeByIndex ( parseInt ( indexToDeleteValue . current , 10 ) )
172177 }
173- disabled = { controlsDisabled }
174178 >
175179 < Text style = { styles . buttonText } > Remove by Index</ Text >
176180 </ TouchableOpacity >
@@ -192,14 +196,13 @@ function MenuList({ file }: { file: RiveFile }) {
192196 onChangeText = { ( text ) => ( index2Value . current = text ) }
193197 />
194198 < TouchableOpacity
195- style = { [ styles . button , controlsDisabled && styles . buttonDisabled ] }
199+ style = { styles . button }
196200 onPress = { ( ) =>
197201 swapIndexes (
198202 parseInt ( index1Value . current , 10 ) ,
199203 parseInt ( index2Value . current , 10 )
200204 )
201205 }
202- disabled = { controlsDisabled }
203206 >
204207 < Text style = { styles . buttonText } > Swap Indexes</ Text >
205208 </ TouchableOpacity >
@@ -221,14 +224,13 @@ function MenuList({ file }: { file: RiveFile }) {
221224 onChangeText = { ( text ) => ( updateLabelValue . current = text ) }
222225 />
223226 < TouchableOpacity
224- style = { [ styles . button , controlsDisabled && styles . buttonDisabled ] }
227+ style = { styles . button }
225228 onPress = { ( ) =>
226229 updateLabelAtIndex (
227230 parseInt ( updateIndexValue . current , 10 ) ,
228231 updateLabelValue . current
229232 )
230233 }
231- disabled = { controlsDisabled }
232234 >
233235 < Text style = { styles . buttonText } > Update Label</ Text >
234236 </ TouchableOpacity >
@@ -298,9 +300,6 @@ const styles = StyleSheet.create({
298300 paddingHorizontal : 14 ,
299301 borderRadius : 6 ,
300302 } ,
301- buttonDisabled : {
302- backgroundColor : '#555' ,
303- } ,
304303 buttonText : {
305304 color : '#fff' ,
306305 fontSize : 13 ,
0 commit comments