@@ -8,6 +8,7 @@ Start from there up to the `[TurboModule] Test the swift Turbomodule` section. T
8
8
* [[ Codegen] Update Codegen Specs] ( #codegen )
9
9
* [[ Swift] Implement the Swift logic] ( #swift-logic )
10
10
* [[ Obj-C++] Implement the Objective-C++ logic] ( #objc-logic )
11
+ * [[ Test] Test the new feature in your app] ( #test )
11
12
12
13
## Steps
13
14
@@ -158,3 +159,42 @@ extension Calculator {
158
159
[ calculator eventfulSqrtWithValue: a ] ;
159
160
}
160
161
```
162
+
163
+ ### <a name =" test " />[[ Test] Test the new feature in your app] ( )
164
+
165
+ 1 . from the ` NewArchitecture ` root app, run:
166
+ ``` sh
167
+ cd add ../calculator
168
+ cd ios
169
+ RCT_NEW_ARCH_ENABLED=1 bundle exec pod install
170
+ cd ..
171
+ ```
172
+ 2 . Open the ` NewArchitecture/App.tsx ` file and, inside the ` function App() ` body:
173
+ 1 . Add the following line to handle the new state
174
+ ``` ts
175
+ const [sqrtState, setSqrtState] = useState <number | undefined >(undefined );
176
+ ```
177
+ 2. Add a function to issue the computation:
178
+ ```ts
179
+ async function computeSqrt() {
180
+ RNCalculator .eventfulSqrt (4 );
181
+ }
182
+ ```
183
+ 3. Register to the event emitter :
184
+ ` ` ` ts
185
+ const eventEmitter = new NativeEventEmitter(RNCalculator);
186
+ let subscription = null
187
+ subscription = eventEmitter.addListener("sqrt", (event) => {
188
+ setSqrtState(event);
189
+ });
190
+ ` ` `
191
+ 4. Add the UI to test your code :
192
+ ` ` ` ts
193
+ <Text>eventfulSqrt(4)={sqrtState ? ` $ {sqrtState }` : '???' } </Text>
194
+ <Button title='Compute' onPress={computeSqrt}/>
195
+ ` ` `
196
+ 3. Run ` yarn ios ` from the ` NewArchitecture ` folder
197
+
198
+ ** Note :** Not to pollute the repository , the code of the ` NewArchitecture ` app has not been pushed . Follow the previous guides to set it up :
199
+ - [feat / back - turbomodule - 070 ](https :// github.com/react-native-community/RNNewArchitectureLibraries/tree/feat/back-turbomodule-070)
200
+ - [feat / turbomodule - swift ](https :// github.com/react-native-community/RNNewArchitectureLibraries/tree/feat/turbomodule-swift)
0 commit comments