Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.

Commit a2682b1

Browse files
author
Riccardo Cipolleschi
committed
[Test] Test the new feature in your app
1 parent 2543c47 commit a2682b1

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Start from there up to the `[TurboModule] Test the swift Turbomodule` section. T
88
* [[Codegen] Update Codegen Specs](#codegen)
99
* [[Swift] Implement the Swift logic](#swift-logic)
1010
* [[Obj-C++] Implement the Objective-C++ logic](#objc-logic)
11+
* [[Test] Test the new feature in your app](#test)
1112

1213
## Steps
1314

@@ -158,3 +159,42 @@ extension Calculator {
158159
[calculator eventfulSqrtWithValue:a];
159160
}
160161
```
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

Comments
 (0)