Sfoglia il codice sorgente

update splash flow

Daniel Zlotin 8 anni fa
parent
commit
0e67defdf5

+ 6
- 1
android/app/src/main/AndroidManifest.xml Vedi File

@@ -1,8 +1,13 @@
1 1
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2 2
     package="com.reactnativenavigation">
3 3
 
4
-    <application>
4
+    <application
5
+        android:allowBackup="false"
6
+        android:theme="@style/Theme.AppCompat.Light.NoActionBar">
5 7
         <activity android:name=".controllers.NavigationActivity" />
8
+        <activity
9
+            android:name="com.facebook.react.devsupport.DevSettingsActivity"
10
+            android:exported="false" />
6 11
     </application>
7 12
 
8 13
 </manifest>

+ 11
- 8
android/app/src/main/java/com/reactnativenavigation/controllers/SplashActivity.java Vedi File

@@ -16,27 +16,30 @@ public abstract class SplashActivity extends AppCompatActivity {
16 16
     protected void onCreate(@Nullable Bundle savedInstanceState) {
17 17
         super.onCreate(savedInstanceState);
18 18
         setSplashLayout();
19
+    }
19 20
 
20
-        if (NavigationApplication.instance.isReactContextInitialized()) {
21
-            finish();
21
+    @Override
22
+    protected void onResume() {
23
+        super.onResume();
24
+
25
+        if (NavigationApplication.instance.getReactGateway().hasStartedCreatingContext()) {
22 26
             return;
23 27
         }
24 28
 
25 29
         if (ReactDevPermission.shouldAskPermission()) {
26 30
             ReactDevPermission.askPermission(this);
31
+            return;
32
+        }
33
+
34
+        if (NavigationApplication.instance.isReactContextInitialized()) {
27 35
             finish();
28 36
             return;
29 37
         }
30 38
 
39
+        // TODO I'm starting to think this entire flow is incorrect and should be done in Application
31 40
         NavigationApplication.instance.startReactContextOnceInBackgroundAndExecuteJS();
32 41
     }
33 42
 
34
-    @Override
35
-    protected void onPause() {
36
-        super.onPause();
37
-        finish();
38
-    }
39
-
40 43
     private void setSplashLayout() {
41 44
         final int splashLayout = getSplashLayout();
42 45
         if (splashLayout > 0) {

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/react/NavigationReactGateway.java Vedi File

@@ -38,6 +38,11 @@ public class NavigationReactGateway implements ReactGateway {
38 38
         return host.hasInstance() && getReactInstanceManager().getCurrentReactContext() != null;
39 39
     }
40 40
 
41
+    @Override
42
+    public boolean hasStartedCreatingContext() {
43
+        return getReactInstanceManager().hasStartedCreatingInitialContext();
44
+    }
45
+
41 46
     public ReactContext getReactContext() {
42 47
         return getReactInstanceManager().getCurrentReactContext();
43 48
     }

+ 2
- 0
android/app/src/main/java/com/reactnativenavigation/react/ReactGateway.java Vedi File

@@ -29,4 +29,6 @@ public interface ReactGateway {
29 29
     void onBackPressed();
30 30
 
31 31
     void onActivityResult(int requestCode, int resultCode, Intent data);
32
+
33
+    boolean hasStartedCreatingContext();
32 34
 }

+ 1
- 4
example/android/app/src/main/AndroidManifest.xml Vedi File

@@ -7,18 +7,15 @@
7 7
         android:name=".MyApplication"
8 8
         android:allowBackup="false"
9 9
         android:icon="@mipmap/ic_launcher"
10
-        android:label="@string/app_name"
11
-        android:theme="@style/AppTheme">
10
+        android:label="@string/app_name">
12 11
         <activity
13 12
             android:name=".MainActivity"
14
-            android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
15 13
             android:label="@string/app_name">
16 14
             <intent-filter>
17 15
                 <action android:name="android.intent.action.MAIN" />
18 16
                 <category android:name="android.intent.category.LAUNCHER" />
19 17
             </intent-filter>
20 18
         </activity>
21
-        <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
22 19
     </application>
23 20
 
24 21
 </manifest>

+ 0
- 8
example/android/app/src/main/res/values/styles.xml Vedi File

@@ -1,8 +0,0 @@
1
-<resources>
2
-
3
-    <!-- Base application theme. -->
4
-    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
5
-        <!-- Customize your theme here. -->
6
-    </style>
7
-
8
-</resources>

+ 1
- 1
example/package.json Vedi File

@@ -3,7 +3,7 @@
3 3
   "version": "0.0.1",
4 4
   "private": true,
5 5
   "scripts": {
6
-    "start": "watchman watch-del-all && (adb reverse tcp:8081 tcp:8081 || true) && node node_modules/react-native/local-cli/cli.js start",
6
+    "start": "watchman watch-del-all && (adb reverse tcp:8081 tcp:8081 || true) && node node_modules/react-native/local-cli/cli.js start --reset-cache",
7 7
     "xcode": "open ios/example.xcodeproj",
8 8
     "android": "cd android && ./gradlew installDebug"
9 9
   },