Skip to content

Commit 3d39f4a

Browse files
committed
Merge branch 'facebook-main' into production
# Conflicts: # yarn.lock
2 parents 64d80e7 + 4a5e3be commit 3d39f4a

Some content is hidden

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

42 files changed

+1956
-888
lines changed

.alexrc.js

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

2222
// allowing this term to prevent reporting "primitive", which is a programming term
2323
'savage',
24+
25+
// allowing this term, since it seems to be used not in insensitive cases
26+
'straightforward',
2427
];
2528

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

docs/_integration-with-existing-apps-ios.md

Lines changed: 137 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ curl -O https://raw.githubusercontent.com/react-native-community/template/refs/h
115115
Please use the Community Template as a reference point for the [Gemfile](https://github.com/react-native-community/template/blob/0.78-stable/template/Gemfile) and for the [Podfile](https://github.com/react-native-community/template/blob/0.78-stable/template/ios/Podfile).
116116

117117
:::note
118-
Remember to change [this line](https://github.com/react-native-community/template/blob/0.78-stable/template/ios/Podfile#L17) and [this line](https://github.com/react-native-community/template/blob/0.78-stable/template/ios/Podfile#L26) of the Podfile to match the name of your app.
119-
120-
If your app don't have tests, remember to remove [this block](https://github.com/react-native-community/template/blob/0.78-stable/template/ios/Podfile#L26-L29).
118+
Remember to change [this line](https://github.com/react-native-community/template/blob/0.78-stable/template/ios/Podfile#L17).
121119
:::
122120

123121
Now, we need to run a couple of extra commands to install the Ruby gems and the Pods.
@@ -258,6 +256,8 @@ Now open the `ReactViewController.m` file and apply the following changes
258256
+#import <React/RCTBundleURLProvider.h>
259257
+#import <RCTReactNativeFactory.h>
260258
+#import <RCTDefaultReactNativeFactoryDelegate.h>
259+
+#import <RCTAppDependencyProvider.h>
260+
261261

262262
@interface ReactViewController ()
263263

@@ -275,7 +275,8 @@ Now open the `ReactViewController.m` file and apply the following changes
275275
- (void)viewDidLoad {
276276
[super viewDidLoad];
277277
// Do any additional setup after loading the view.
278-
+ _factoryDelegate = [ReactNativeDelegate new];
278+
+ _factoryDelegate = [ReactNativeFactoryDelegate new];
279+
+ _factoryDelegate.dependencyProvider = [RCTAppDependencyProvider new];
279280
+ _factory = [[RCTReactNativeFactory alloc] initWithDelegate:_factoryDelegate];
280281
+ self.view = [_factory.rootViewFactory viewWithModuleName:@"HelloWorld"];
281282
}
@@ -311,6 +312,7 @@ Now open the `ReactViewController.swift` file and apply the following changes
311312
import UIKit
312313
+import React
313314
+import React_RCTAppDelegate
315+
+import ReactAppDependencyProvider
314316

315317
class ReactViewController: UIViewController {
316318
+ var reactNativeFactory: RCTReactNativeFactory?
@@ -319,6 +321,7 @@ class ReactViewController: UIViewController {
319321
override func viewDidLoad() {
320322
super.viewDidLoad()
321323
+ reactNativeFactoryDelegate = ReactNativeDelegate()
324+
+ reactNativeFactoryDelegate!.dependencyProvider = RCTAppDependencyProvider()
322325
+ reactNativeFactory = RCTReactNativeFactory(delegate: reactNativeFactoryDelegate!)
323326
+ view = reactNativeFactory!.rootViewFactory.view(withModuleName: "HelloWorld")
324327

@@ -513,6 +516,135 @@ REACT_NATIVE_XCODE="$REACT_NATIVE_PATH/scripts/react-native-xcode.sh"
513516

514517
Now, if you build your app for Release, it will work as expected.
515518

516-
### Now what?
519+
## 7. Passing initial props to the React Native view
520+
521+
In some case, you'd like to pass some information from the Native app to JavaScript. For example, you might want to pass the user id of the currently logged user to React Native, together with a token that can be used to retrieve information from a database.
522+
523+
This is possible by using the `initialProperties` parameter of the `view(withModuleName:initialProperty)` overload of the `RCTReactNativeFactory` class. The following steps shows you how to do it.
524+
525+
### Update the App.tsx file to read the initial properties.
526+
527+
Open the `App.tsx` file and add the following code:
528+
529+
```diff title="App.tsx"
530+
import {
531+
Colors,
532+
DebugInstructions,
533+
Header,
534+
ReloadInstructions,
535+
} from 'react-native/Libraries/NewAppScreen';
536+
537+
-function App(): React.JSX.Element {
538+
+function App(props): React.JSX.Element {
539+
const isDarkMode = useColorScheme() === 'dark';
540+
541+
const backgroundStyle = {
542+
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
543+
};
544+
545+
return (
546+
<SafeAreaView style={backgroundStyle}>
547+
<StatusBar
548+
barStyle={isDarkMode ? 'light-content' : 'dark-content'}
549+
backgroundColor={backgroundStyle.backgroundColor}
550+
/>
551+
<ScrollView
552+
contentInsetAdjustmentBehavior="automatic"
553+
style={backgroundStyle}>
554+
<Header />
555+
- <View
556+
- style={{
557+
- backgroundColor: isDarkMode
558+
- ? Colors.black
559+
- : Colors.white,
560+
- padding: 24,
561+
- }}>
562+
- <Text style={styles.title}>Step One</Text>
563+
- <Text>
564+
- Edit <Text style={styles.bold}>App.tsx</Text> to
565+
- change this screen and see your edits.
566+
- </Text>
567+
- <Text style={styles.title}>See your changes</Text>
568+
- <ReloadInstructions />
569+
- <Text style={styles.title}>Debug</Text>
570+
- <DebugInstructions />
571+
+ <Text style={styles.title}>UserID: {props.userID}</Text>
572+
+ <Text style={styles.title}>Token: {props.token}</Text>
573+
</View>
574+
</ScrollView>
575+
</SafeAreaView>
576+
);
577+
}
578+
579+
const styles = StyleSheet.create({
580+
title: {
581+
fontSize: 24,
582+
fontWeight: '600',
583+
+ marginLeft: 20,
584+
},
585+
bold: {
586+
fontWeight: '700',
587+
},
588+
});
589+
590+
export default App;
591+
```
592+
593+
These changes will tell React Native that your App component is now accepting some properties. The `RCTreactNativeFactory` will take care of passing them to the component when it's rendered.
594+
595+
### Update the Native code to pass the initial properties to JavaScript.
596+
597+
<Tabs groupId="ios-language" queryString defaultValue={constants.defaultAppleLanguage} values={constants.appleLanguages}>
598+
<TabItem value="objc">
599+
600+
Modify the `ReactViewController.mm` to pass the initial properties to JavaScript.
601+
602+
```diff title="ReactViewController.mm"
603+
- (void)viewDidLoad {
604+
[super viewDidLoad];
605+
// Do any additional setup after loading the view.
606+
607+
_factoryDelegate = [ReactNativeFactoryDelegate new];
608+
_factoryDelegate.dependencyProvider = [RCTAppDependencyProvider new];
609+
_factory = [[RCTReactNativeFactory alloc] initWithDelegate:_factoryDelegate];
610+
- self.view = [_factory.rootViewFactory viewWithModuleName:@"HelloWorld"];
611+
+ self.view = [_factory.rootViewFactory viewWithModuleName:@"HelloWorld" initialProperties:@{
612+
+ @"userID": @"12345678",
613+
+ @"token": @"secretToken"
614+
+ }];
615+
}
616+
```
617+
618+
</TabItem>
619+
<TabItem value="swift">
620+
621+
Modify the `ReactViewController.swift` to pass the initial properties to the React Native view.
622+
623+
```diff title="ReactViewController.swift"
624+
override func viewDidLoad() {
625+
super.viewDidLoad()
626+
reactNativeFactoryDelegate = ReactNativeDelegate()
627+
reactNativeFactoryDelegate!.dependencyProvider = RCTAppDependencyProvider()
628+
reactNativeFactory = RCTReactNativeFactory(delegate: reactNativeFactoryDelegate!)
629+
- view = reactNativeFactory!.rootViewFactory.view(withModuleName: "HelloWorld")
630+
+ view = reactNativeFactory!.rootViewFactory.view(withModuleName: "HelloWorld" initialProperties: [
631+
+ "userID": "12345678",
632+
+ "token": "secretToken"
633+
+])
634+
635+
}
636+
}
637+
```
638+
639+
</TabItem>
640+
</Tabs>
641+
642+
3. Run your app once again. You should see the following screen after you present the `ReactViewController`:
643+
644+
<center>
645+
<img src="/docs/assets/brownfield-with-initial-props.png" width="30%" height="30%"/>
646+
</center>
647+
648+
## Now what?
517649

518650
At this point you can continue developing your app as usual. Refer to our [debugging](debugging) and [deployment](running-on-device) docs to learn more about working with React Native.

docs/build-speed.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ This can be problematic as your project grows and generally in bigger organizati
88

99
To mitigate this performance hit, this page shares some suggestions on how to **improve your build time**.
1010

11+
:::info
12+
13+
Please note that those suggestions are advanced feature that requires some amount of understanding of how the native build tools work.
14+
15+
:::
16+
1117
## Build only one ABI during development (Android-only)
1218

1319
When building your android app locally, by default you build all the 4 [Application Binary Interfaces (ABIs)](https://developer.android.com/ndk/guides/abis) : `armeabi-v7a`, `arm64-v8a`, `x86` & `x86_64`.
@@ -50,6 +56,31 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
5056

5157
Once you build a **release version** of your app, don't forget to remove those flags as you want to build an apk/app bundle that works for all the ABIs and not only for the one you're using in your daily development workflow.
5258

59+
## Enable Configuration Caching (Android-only)
60+
61+
Since React Native 0.79, you can also enable Gradle Configuration Caching.
62+
63+
When you’re running an Android build with `yarn android`, you will be executing a Gradle build that is composed by two steps ([source](https://docs.gradle.org/current/userguide/build_lifecycle.html)):
64+
65+
- Configuration phase, when all the `.gradle` files are evaluated.
66+
- Execution phase, when the tasks are actually executed so the Java/Kotlin code is compiled and so on.
67+
68+
You will now be able to enable Configuration Caching, which will allow you to skip the Configuration phase on subsequent builds.
69+
70+
This is beneficial when making frequent changes to the native code as it improves build times.
71+
72+
For example here you can see how rebuilding faster it is to rebuild RN-Tester after a change in the native code:
73+
74+
![gradle config caching](/docs/assets/gradle-config-caching.gif)
75+
76+
You can enable Gradle Configuration Caching by adding the following line in your `android/gradle.properties` file:
77+
78+
```
79+
org.gradle.configuration-cache=true
80+
```
81+
82+
Please refer to the [official Gradle documentation](https://docs.gradle.org/current/userguide/configuration_cache.html) for more resources on Configuration Caching.
83+
5384
## Use a compiler cache
5485

5586
If you're running frequent native builds (either C++ or Objective-C), you might benefit from using a **compiler cache**.

docs/linking.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ If you wish to receive the intent in an existing instance of MainActivity, you m
5353

5454
> **NOTE:** On iOS, you'll need to add the `LinkingIOS` folder into your header search paths as described in step 3 [here](linking-libraries-ios#step-3). If you also want to listen to incoming app links during your app's execution, you'll need to add the following lines to your `*AppDelegate.m`:
5555
56-
```objectivec
56+
<Tabs groupId="ios-language" queryString defaultValue={constants.defaultAppleLanguage} values={constants.appleLanguages}>
57+
<TabItem value="objc">
58+
59+
```objc title="AppDelegate.mm"
5760
// iOS 9.x or newer
5861
#import <React/RCTLinkingManager.h>
5962

@@ -65,23 +68,9 @@ If you wish to receive the intent in an existing instance of MainActivity, you m
6568
}
6669
```
6770

68-
If you're targeting iOS 8.x or older, you can use the following code instead:
69-
70-
```objectivec
71-
// iOS 8.x or older
72-
#import <React/RCTLinkingManager.h>
73-
74-
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
75-
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
76-
{
77-
return [RCTLinkingManager application:application openURL:url
78-
sourceApplication:sourceApplication annotation:annotation];
79-
}
80-
```
81-
8271
If your app is using [Universal Links](https://developer.apple.com/ios/universal-links/), you'll need to add the following code as well:
8372

84-
```objectivec
73+
```objc title="AppDelegate.mm"
8574
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity
8675
restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
8776
{
@@ -91,6 +80,33 @@ If your app is using [Universal Links](https://developer.apple.com/ios/universal
9180
}
9281
```
9382
83+
</TabItem>
84+
<TabItem value="swift">
85+
86+
```swift title="AppDelegate.swift"
87+
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
88+
return RCTLinkingManager.application(app, open: url, options: options)
89+
}
90+
```
91+
92+
If your app is using [Universal Links](https://developer.apple.com/ios/universal-links/), you'll need to add the following code as well:
93+
94+
```swift title="AppDelegate.swift"
95+
func application(
96+
_ application: UIApplication,
97+
continue userActivity: NSUserActivity,
98+
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
99+
return RCTLinkingManager.application(
100+
application,
101+
continue: userActivity,
102+
restorationHandler: restorationHandler
103+
)
104+
}
105+
```
106+
107+
</TabItem>
108+
</Tabs>
109+
94110
</TabItem>
95111
</Tabs>
96112

docs/text.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ On the web, the usual way to set a font family and size for the entire document
134134

135135
```css
136136
html {
137-
font-family: 'lucida grande', tahoma, verdana, arial, sans-serif;
137+
font-family:
138+
'lucida grande', tahoma, verdana, arial, sans-serif;
138139
font-size: 11px;
139140
color: #141823;
140141
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Advanced Topics on Native Modules Development
2+
3+
This document contains a set of advanced topics to implement more complex functionalities of Native Components. It is recommended to first read the [Codegen](/docs/the-new-architecture/what-is-codegen) section and the guides on [Native Components](/docs/fabric-native-components-introduction).
4+
5+
This guide will cover the following topics:
6+
7+
- [Direct Manipulation](/docs/the-new-architecture/direct-manipulation-new-architecture)
8+
- [Measuring the Layout](/docs/the-new-architecture/layout-measurements)
9+
- [Invoking native functions on your native component](/docs/next/the-new-architecture/fabric-component-native-commands)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Advanced Topics on Native Modules Development
2+
3+
This document contains a set of advanced topics to implement more complex functionalities of Native Modules. It is recommended to first read the [Codegen](/docs/the-new-architecture/what-is-codegen) section and the guides on [Native Modules](/docs/turbo-native-modules-introduction).
4+
5+
This guide will cover the following topics:
6+
7+
- [Add custom C++ types to your C++ modules](/docs/the-new-architecture/custom-cxx-types)
8+
- [Use Swift in your Module](/docs/next/the-new-architecture/turbo-modules-with-swift)
9+
- [Emit custom events from your Native Modules](/docs/next/the-new-architecture/native-modules-custom-events)
10+
- [Native Modules Lifecycle](/docs/next/the-new-architecture/native-modules-lifecycle)

0 commit comments

Comments
 (0)