Skip to content

Commit 088f55a

Browse files
author
Riccardo
authored
Merge branch 'main' into feat/new-architecture-guide-refactoring
2 parents ff7d4bd + b72a879 commit 088f55a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+3009
-2198
lines changed

.alexrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ exports.allow = [
1818

1919
// host refers to host objects in native code
2020
'host-hostess',
21+
22+
// allowing this term to prevent reporting "primitive", which is a programming term
23+
'savage',
2124
];
2225

2326
// Use a "maybe" level of profanity instead of the default "unlikely".

docs/debugging.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ On Android 5.0+ devices connected via USB, you can use the [`adb` command line t
193193

194194
`adb reverse tcp:8081 tcp:8081`
195195

196-
<!-- alex ignore host-hostess -->
197-
198196
Alternatively, select "Dev Settings" from the Developer Menu, then update the "Debug server host for device" setting to match the IP address of your computer.
199197

200198
> If you run into any issues, it may be possible that one of your Chrome extensions is interacting in unexpected ways with the debugger. Try disabling all of your extensions and re-enabling them one-by-one until you find the problematic extension.

docs/image.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,10 @@ More details about `resize` and `scale` can be found at http://frescolib.org/doc
397397

398398
Determines how to resize the image when the frame doesn't match the raw image dimensions. Defaults to `cover`.
399399

400-
- `cover`: Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding).
400+
- `cover`: Scale the image uniformly (maintain the image's aspect ratio) so that
401+
402+
- both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding)
403+
- at least one dimension of the scaled image will be equal to the corresponding dimension of the view (minus padding)
401404

402405
- `contain`: Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding).
403406

docs/linking.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ The `Promise` will reject on Android if it was impossible to check if the URL ca
315315
316316
> This method has limitations on iOS 9+. From [the official Apple documentation](https://developer.apple.com/documentation/uikit/uiapplication/1622952-canopenurl):
317317
>
318-
> - If your app is linked against an earlier version of iOS but is running in iOS 9.0 or later, you can call this method up to 50 times. After reaching that limit, subsequent calls always return false. If the user reinstalls or upgrades the app, iOS resets the limit.
318+
> - If your app is linked against an earlier version of iOS but is running in iOS 9.0 or later, you can call this method up to 50 times. After reaching that limit, subsequent calls always resolve to `false`. If the user reinstalls or upgrades the app, iOS resets the limit.
319319
>
320-
> As of iOS 9, your app also needs to provide the `LSApplicationQueriesSchemes` key inside `Info.plist` or `canOpenURL()` will always return `false`.
320+
> As of iOS 9, your app also needs to provide the `LSApplicationQueriesSchemes` key inside `Info.plist` or `canOpenURL()` will always resolve to `false`.
321321
322322
> When targeting Android 11 (SDK 30) you must specify the intents for the schemes you want to handle in `AndroidManifest.xml`. A list of common intents can be found [here](https://developer.android.com/guide/components/intents-common).
323323
>

docs/native-components-android.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,10 @@ Properties that are to be reflected in JavaScript needs to be exposed as setter
102102

103103
Annotation `@ReactProp` has one obligatory argument `name` of type `String`. Name assigned to the `@ReactProp` annotation linked to the setter method is used to reference the property on JS side.
104104

105-
<!-- alex disable primitive -->
106-
107105
Except from `name`, `@ReactProp` annotation may take following optional arguments: `defaultBoolean`, `defaultInt`, `defaultFloat`. Those arguments should be of the corresponding type (accordingly `boolean`, `int`, `float` in Java and `Boolean`, `Int`, `Float` in Kotlin) and the value provided will be passed to the setter method in case when the property that the setter is referencing has been removed from the component. Note that "default" values are only provided for primitive types, in case when setter is of some complex type, `null` will be provided as a default value in case when corresponding property gets removed.
108106

109107
Setter declaration requirements for methods annotated with `@ReactPropGroup` are different than for `@ReactProp`, please refer to the `@ReactPropGroup` annotation class docs for more information about it. **IMPORTANT!** in ReactJS updating the property value will result in setter method call. Note that one of the ways we can update component is by removing properties that have been set before. In that case setter method will be called as well to notify view manager that property has changed. In that case "default" value will be provided (for primitive types "default" value can be specified using `defaultBoolean`, `defaultFloat`, etc. arguments of `@ReactProp` annotation, for complex types setter will be called with value set to `null`).
110108

111-
<!-- alex enable primitive -->
112-
113109
<Tabs groupId="android-language" defaultValue={constants.defaultAndroidLanguage} values={constants.androidLanguages}>
114110
<TabItem value="kotlin">
115111

docs/new-architecture-app-modules-android.md

Lines changed: 173 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ title: Enabling TurboModule on Android
44
---
55

66
import NewArchitectureWarning from './\_markdown-new-architecture-warning.mdx';
7+
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
8+
import constants from '@site/core/TabsConstants';
79

810
<NewArchitectureWarning/>
911

@@ -154,11 +156,14 @@ You can now verify that everything works correctly by running your android app:
154156
yarn react-native run-android
155157
```
156158

157-
## 2. Java - Provide a `ReactPackageTurboModuleManagerDelegate`
159+
## 2. Java/Kotlin - Provide a `ReactPackageTurboModuleManagerDelegate`
158160

159161
Now is time to actually use the TurboModule.
160162
First, we will need to create a `ReactPackageTurboModuleManagerDelegate` subclass, like the following:
161163

164+
<Tabs groupId="android-language" defaultValue={constants.defaultAndroidLanguage} values={constants.androidLanguages}>
165+
<TabItem value="java">
166+
162167
```java
163168
package com.awesomeproject;
164169

@@ -198,6 +203,52 @@ public class MyApplicationTurboModuleManagerDelegate extends ReactPackageTurboMo
198203
}
199204
```
200205

206+
</TabItem>
207+
208+
<TabItem value="kotlin">
209+
210+
```kotlin
211+
package com.awesomeproject
212+
213+
import com.facebook.jni.HybridData
214+
import com.facebook.react.ReactPackage
215+
import com.facebook.react.ReactPackageTurboModuleManagerDelegate
216+
import com.facebook.react.bridge.ReactApplicationContext
217+
import com.facebook.soloader.SoLoader
218+
219+
class MyApplicationTurboModuleManagerDelegate
220+
protected constructor(
221+
reactApplicationContext: ReactApplicationContext,
222+
packages: List<ReactPackage>
223+
) : ReactPackageTurboModuleManagerDelegate(reactApplicationContext, packages) {
224+
225+
override protected external fun initHybrid(): HybridData?
226+
class Builder : ReactPackageTurboModuleManagerDelegate.Builder() {
227+
override protected fun build(
228+
context: ReactApplicationContext,
229+
packages: List<ReactPackage>
230+
): MyApplicationTurboModuleManagerDelegate =
231+
MyApplicationTurboModuleManagerDelegate(context, packages)
232+
}
233+
234+
@Synchronized
235+
override protected fun maybeLoadOtherSoLibraries() {
236+
// Prevents issues with initializer interruptions.
237+
if (!isSoLibraryLoaded) {
238+
SoLoader.loadLibrary("myapplication_appmodules")
239+
isSoLibraryLoaded = true
240+
}
241+
}
242+
243+
companion object {
244+
@Volatile private var isSoLibraryLoaded = false
245+
}
246+
}
247+
```
248+
249+
</TabItem>
250+
</Tabs>
251+
201252
Please note that the `SoLoader.loadLibrary` parameter (in this case `"myapplication_appmodules")` should be the same as the one specified for `LOCAL_MODULE :=` inside the `Android.mk` file you created before.
202253

203254
This class will then be responsible of loading the TurboModules and will take care of loading the native library build with the NDK at runtime.
@@ -208,6 +259,9 @@ Then, you can provide the class you created to your `ReactNativeHost`. You can l
208259

209260
Once you located it, you need to add the `getReactPackageTurboModuleManagerDelegateBuilder` method as from the snippet below:
210261

262+
<Tabs groupId="android-language" defaultValue={constants.defaultAndroidLanguage} values={constants.androidLanguages}>
263+
<TabItem value="java">
264+
211265
```java
212266
public class MyApplication extends Application implements ReactApplication {
213267

@@ -231,10 +285,43 @@ public class MyApplication extends Application implements ReactApplication {
231285
}
232286
```
233287

288+
</TabItem>
289+
<TabItem value="kotlin">
290+
291+
```kotlin
292+
class MyApplication : Application(), ReactApplication {
293+
private val reactNativeHost: ReactNativeHost =
294+
object : ReactNativeHost(this) {
295+
296+
override fun getUseDeveloperSupport(): Boolean {
297+
/* ... */
298+
}
299+
300+
override fun getPackages(): List<ReactPackage?>? {
301+
/* ... */
302+
}
303+
304+
override fun getJSMainModuleName(): String? {
305+
/* ... */
306+
}
307+
308+
@NonNull
309+
override fun getReactPackageTurboModuleManagerDelegateBuilder() =
310+
ReactPackageTurboModuleManagerDelegate.Builder()
311+
}
312+
}
313+
```
314+
315+
</TabItem>
316+
</Tabs>
317+
234318
## 4. Extend the `getPackages()` from your `ReactNativeHost` to use the TurboModule
235319

236320
Still on the `ReactNativeHost` , we need to extend the the `getPackages()` method to include the newly created TurboModule. Update the method to include the following:
237321

322+
<Tabs groupId="android-language" defaultValue={constants.defaultAndroidLanguage} values={constants.androidLanguages}>
323+
<TabItem value="java">
324+
238325
```java
239326
public class MyApplication extends Application implements ReactApplication {
240327

@@ -291,8 +378,72 @@ public class MyApplication extends Application implements ReactApplication {
291378
return new MyApplicationTurboModuleManagerDelegate.Builder();
292379
}
293380
};
381+
}
382+
```
383+
384+
</TabItem>
385+
<TabItem value="kotlin">
386+
387+
```kotlin
388+
class MyApplication() : Application(), ReactApplication {
389+
390+
private val reactNativeHost: ReactNativeHost =
391+
object : ReactNativeHost(this) {
392+
override fun getUseDeveloperSupport(): Boolean {
393+
/* ... */
394+
}
395+
396+
override protected fun getPackages(): List<ReactPackage>? {
397+
val packages: MutableList<ReactPackage> = PackageList(this).getPackages()
398+
399+
// Add those lines
400+
packages.add(
401+
object : TurboReactPackage() {
402+
@Nullable
403+
override fun getModule(
404+
name: String,
405+
reactContext: ReactApplicationContext?
406+
): NativeModule? =
407+
if ((name == NativeAwesomeManager.NAME)) {
408+
NativeAwesomeManager(reactContext)
409+
} else {
410+
null
411+
}
412+
413+
override fun getReactModuleInfoProvider() =
414+
mutableMapOf<String, ReactModuleInfo>(
415+
NativeAwesomeManager.NAME,
416+
ReactModuleInfo(
417+
NativeAwesomeManager.NAME,
418+
"NativeAwesomeManager",
419+
false, // canOverrideExistingModule
420+
false, // needsEagerInit
421+
true, // hasConstants
422+
false, // isCxxModule
423+
true // isTurboModule
424+
)
425+
)
426+
}
427+
)
428+
return packages
429+
}
430+
431+
override protected fun getJSMainModuleName(): String? {
432+
/* ... */
433+
}
434+
435+
@NonNull
436+
override protected fun getReactPackageTurboModuleManagerDelegateBuilder():
437+
ReactPackageTurboModuleManagerDelegate.Builder? {
438+
return Builder()
439+
}
440+
}
441+
}
294442
```
295443

444+
</TabItem>
445+
</Tabs>
446+
296447
## 5. C++ Provide a native implementation for the methods in your `*TurboModuleDelegate` class
297448

298449
If you take a closer look at the class `MyApplicationTurboModuleManagerDelegate` that you created before, you will notice how some of the methods are `native`.
@@ -441,6 +592,9 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
441592
442593
Now you can finally enable the `TurboModule `support in your Application. To do so, you need to turn on the `useTurboModule` flag inside your Application `onCreate` method.
443594
595+
<Tabs groupId="android-language" defaultValue={constants.defaultAndroidLanguage} values={constants.androidLanguages}>
596+
<TabItem value="java">
597+
444598
```java
445599
public class MyApplication extends Application implements ReactApplication {
446600
@@ -449,8 +603,26 @@ public class MyApplication extends Application implements ReactApplication {
449603
ReactFeatureFlags.useTurboModules = true;
450604
//...
451605
}
606+
}
607+
```
608+
609+
</TabItem>
610+
611+
<TabItem value="kotlin">
612+
613+
```kotlin
614+
class MyApplication : Application(), ReactApplication {
615+
616+
override fun onCreate() {
617+
ReactFeatureFlags.useTurboModules = true
618+
// ...
619+
}
620+
}
452621
```
453622

623+
</TabItem>
624+
</Tabs>
625+
454626
It’s now time to run again your Android app to verify that everything works correctly:
455627

456628
```bash

docs/new-architecture-library-intro.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,6 @@ While we know that all deprecations are a hassle, this guide is intended to help
237237
238238
### Migrating `findNodeHandle` / getting a `HostComponent`
239239
240-
<!-- alex ignore host -->
241-
242240
Much of the migration work requires a HostComponent ref to access certain APIs that are only attached to host components (like View, Text, or ScrollView). HostComponents are the return value of calls to `requireNativeComponent`. `findNodeHandle` tunnels through multiple levels of component hierarchy to find the nearest native component.
243241
244242
As a concrete example, this code uses `findNodeHandle` to tunnel from `ParentComponent` through to the `View` rendered by `ChildComponent`.

docs/running-on-device.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ You can also connect to the development server over Wi-Fi. You'll first need to
8787

8888
You can find the IP address in **System Preferences****Network**.
8989

90-
<!-- alex ignore host -->
91-
9290
1. Make sure your laptop and your phone are on the **same** Wi-Fi network.
9391
2. Open your React Native app on your device.
9492
3. You'll see a [red screen with an error](debugging.md#in-app-errors-and-warnings). This is OK. The following steps will fix that.
@@ -167,8 +165,6 @@ You can also connect to the development server over Wi-Fi. You'll first need to
167165

168166
Open the command prompt and type `ipconfig` to find your machine's IP address ([more info](http://windows.microsoft.com/en-us/windows/using-command-line-tools-networking-information)).
169167

170-
<!-- alex ignore host -->
171-
172168
1. Make sure your laptop and your phone are on the **same** Wi-Fi network.
173169
2. Open your React Native app on your device.
174170
3. You'll see a [red screen with an error](debugging.md#in-app-errors-and-warnings). This is OK. The following steps will fix that.
@@ -294,8 +290,6 @@ You can also connect to the development server over Wi-Fi. You'll first need to
294290

295291
Open a terminal and type `/sbin/ifconfig` to find your machine's IP address.
296292

297-
<!-- alex ignore host -->
298-
299293
1. Make sure your laptop and your phone are on the **same** Wi-Fi network.
300294
2. Open your React Native app on your device.
301295
3. You'll see a [red screen with an error](debugging.md#in-app-errors-and-warnings). This is OK. The following steps will fix that.

docs/running-on-simulator-ios.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ Once you have your React Native project initialized, you can run `npx react-nati
99

1010
## Specifying a device
1111

12-
You can specify the device the simulator should run with the `--simulator` flag, followed by the device name as a string. The default is `"iPhone 13"`. If you wish to run your app on an iPhone SE (2nd generation), run `npx react-native run-ios --simulator="iPhone SE (2nd generation)"`.
12+
You can specify the device the simulator should run with the `--simulator` flag, followed by the device name as a string. The default is `"iPhone 13"`. If you wish to run your app on an iPhone SE (2nd generation), run `npx react-native run-ios --simulator='iPhone SE (2nd generation)'`.
1313

1414
The device names correspond to the list of devices available in Xcode. You can check your available devices by running `xcrun simctl list devices` from the console.
15+
16+
### Specifying a version of device
17+
18+
If you have multiple iOS versions installed, you also need to specify it's appropiate version. E.g. run `npx react-native run-ios --simulator='iPhone 13 Pro (15.5)'` in order to specify the iOS version.
19+
20+
## Specifying an UDID
21+
22+
You can specify the device UDID returned from `xcrun simctl list devices` command. E.g. run `npx react-native run-ios --udid='AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA'`.

docs/textinput.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -844,16 +844,12 @@ see [Issue#7070](https://github.com/facebook/react-native/issues/7070) for more
844844

845845
### `textBreakStrategy` <div class="label android">Android</div>
846846

847-
<!-- alex disable simple -->
848-
849847
Set text break strategy on Android API Level 23+, possible values are `simple`, `highQuality`, `balanced` The default value is `simple`.
850848

851849
| Type |
852850
| ----------------------------------------- |
853851
| enum('simple', 'highQuality', 'balanced') |
854852

855-
<!-- alex enable simple -->
856-
857853
---
858854

859855
### `underlineColorAndroid` <div class="label android">Android</div>

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
},
1818
"dependencies": {
1919
"babel-eslint": "^10.1.0",
20-
"case-police": "^0.5.1",
21-
"eslint": "^8.10.0",
20+
"case-police": "^0.5.6",
21+
"eslint": "^8.20.0",
2222
"eslint-config-prettier": "^8.5.0",
2323
"eslint-plugin-mdx": "^1.16.0",
24-
"eslint-plugin-prettier": "^4.0.0",
24+
"eslint-plugin-prettier": "^4.2.1",
2525
"eslint-plugin-yaml": "^0.5.0",
2626
"husky": "^4.3.8",
2727
"netlify-plugin-cache": "^1.0.3",
28-
"prettier": "^2.5.1",
28+
"prettier": "^2.7.1",
2929
"pretty-quick": "^3.1.3",
30-
"yarn-deduplicate": "^3.1.0"
30+
"yarn-deduplicate": "^5.0.0"
3131
},
3232
"resolutions": {
3333
"trim": "^1.0.1",

website/architecture/architecture-overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ Architecture Overview is intended to share conceptual overview of how React Nati
2121
- [View Flattening](view-flattening)
2222
- [Threading Model](threading-model)
2323
- Build Tools
24-
- [Bundled Hermes](bundled-hermes)
24+
- [Bundled Hermes](bundled-hermes)
2525
- [Glossary](glossary)

0 commit comments

Comments
 (0)