Skip to content

Commit 8c088e8

Browse files
committed
Update getting started guide
1 parent 35b05d3 commit 8c088e8

File tree

1 file changed

+44
-18
lines changed

1 file changed

+44
-18
lines changed

versioned_docs/version-7.x/getting-started.md

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,37 @@ If you're on a Mac and developing for iOS, you need to install the pods (via [Co
8484
npx pod-install ios
8585
```
8686

87-
`react-native-screens` package requires one additional configuration step to properly
88-
work on Android devices. Edit `MainActivity.kt` or `MainActivity.java` file which is located under `android/app/src/main/java/<your package name>/`.
87+
:::info
88+
89+
When you use a navigator (such as stack navigator), you'll need to follow the installation instructions of that navigator for any additional dependencies. If you're getting an error "Unable to resolve module", you need to install that module in your project.
90+
91+
:::
92+
93+
#### Configuring `react-native-screens` on Android
8994

90-
Add the highlighted code to the body of `MainActivity` class:
95+
[`react-native-screens`](https://github.com/software-mansion/react-native-screens) requires one additional configuration to properly work on Android.
96+
97+
Edit `MainActivity.kt` or `MainActivity.java` file under `android/app/src/main/java/<your package name>/`, and add the highlighted code to the body of `MainActivity` class:
9198

9299
<Tabs>
93100
<TabItem value='kotlin' label='Kotlin' default>
94101

95102
```kotlin
103+
// highlight-start
104+
import android.os.Bundle
105+
import com.swmansion.rnscreens.fragment.restoration.RNScreensFragmentFactory
106+
// highlight-end
107+
108+
// ...
109+
96110
class MainActivity: ReactActivity() {
97111
// ...
98-
// highlight-start
99112
override fun onCreate(savedInstanceState: Bundle?) {
100-
super.onCreate(null)
113+
// highlight-start
114+
supportFragmentManager.fragmentFactory = RNScreensFragmentFactory()
115+
super.onCreate(savedInstanceState)
116+
// highlight-end
101117
}
102-
// highlight-end
103118
// ...
104119
}
105120
```
@@ -108,34 +123,45 @@ class MainActivity: ReactActivity() {
108123
<TabItem value='java' label='Java'>
109124

110125
```java
126+
// highlight-start
127+
import android.os.Bundle;
128+
import com.swmansion.rnscreens.fragment.restoration.RNScreensFragmentFactory;
129+
// highlight-end
130+
131+
// ...
132+
111133
public class MainActivity extends ReactActivity {
112134
// ...
113-
// highlight-start
114135
@Override
115136
protected void onCreate(Bundle savedInstanceState) {
116-
super.onCreate(null);
137+
// highlight-start
138+
getSupportFragmentManager().setFragmentFactory(new RNScreensFragmentFactory());
139+
super.onCreate(savedInstanceState);
140+
// highlight-end
117141
}
118-
// highlight-end
119142
// ...
120143
}
121144
```
122145

123146
</TabItem>
124147
</Tabs>
125148

126-
and make sure to add the following import statement at the top of this file below your package statement:
127-
128-
```java
129-
import android.os.Bundle;
130-
```
131-
132149
This change is required to avoid crashes related to View state being not persisted consistently across Activity restarts.
133150

134-
:::info
151+
#### Opting-out of predictive back on Android
135152

136-
When you use a navigator (such as stack navigator), you'll need to follow the installation instructions of that navigator for any additional dependencies. If you're getting an error "Unable to resolve module", you need to install that module in your project.
153+
React Navigation doesn't yet support Android's predictive back gesture. Disabling it is necessary for the system back gesture to work properly with React Navigation.
137154

138-
:::
155+
To opt out, in `AndroidManifest.xml`, in the `<application>` tag (or `<activity>` tag to opt-out at activity level), set the `android:enableOnBackInvokedCallback` flag to `false`:
156+
157+
```xml
158+
<application
159+
// highlight-next-line
160+
android:enableOnBackInvokedCallback="false"
161+
>
162+
<!-- ... -->
163+
</application>
164+
```
139165

140166
## Setting up React Navigation
141167

0 commit comments

Comments
 (0)