Browse Source

android: splash min 1 sec

Daniel Zlotin 7 years ago
parent
commit
9de08952f1

+ 1
- 1
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/ApplicationLifecycleTest.java View File

@@ -40,7 +40,7 @@ public class ApplicationLifecycleTest {
40 40
     @Test
41 41
     public void _1_showSplash_AcceptsOverlayPermissions_ShowsWelcomeScreen() throws Exception {
42 42
         launchTheApp();
43
-//        assertThat(uiDevice().wait(Until.hasObject(By.desc("NavigationSplashView")), TIMEOUT)).isTrue();
43
+        assertExists(By.desc("NavigationSplashView"));
44 44
         assertMainShown();
45 45
     }
46 46
 

+ 21
- 3
android/app/src/main/java/com/reactnativenavigation/NavigationApplication.java View File

@@ -14,10 +14,12 @@ import com.facebook.react.shell.MainReactPackage;
14 14
 import com.reactnativenavigation.react.NavigationEventEmitter;
15 15
 import com.reactnativenavigation.react.NavigationPackage;
16 16
 import com.reactnativenavigation.react.ReactDevPermission;
17
+import com.reactnativenavigation.utils.UiThread;
17 18
 
18 19
 import java.util.Arrays;
19 20
 import java.util.List;
20 21
 import java.util.concurrent.atomic.AtomicBoolean;
22
+import java.util.concurrent.atomic.AtomicLong;
21 23
 
22 24
 public abstract class NavigationApplication extends Application implements ReactApplication {
23 25
     public static NavigationApplication instance;
@@ -44,6 +46,7 @@ public abstract class NavigationApplication extends Application implements React
44 46
 
45 47
         registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
46 48
             private AtomicBoolean creating = new AtomicBoolean(true);
49
+            private AtomicLong startTime = new AtomicLong();
47 50
 
48 51
             @Override
49 52
             public void onActivityCreated(final Activity activity, Bundle bundle) {
@@ -65,11 +68,21 @@ public abstract class NavigationApplication extends Application implements React
65 68
                 }
66 69
 
67 70
                 if (!host.getReactInstanceManager().hasStartedCreatingInitialContext()) {
71
+                    startTime.set(System.currentTimeMillis());
68 72
                     host.getReactInstanceManager().addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
69 73
                         @Override
70
-                        public void onReactContextInitialized(ReactContext context) {
74
+                        public void onReactContextInitialized(final ReactContext context) {
71 75
                             host.getReactInstanceManager().removeReactInstanceEventListener(this);
72
-                            new NavigationEventEmitter(context).emitAppLaunched();
76
+
77
+                            long millisPassed = System.currentTimeMillis() - startTime.get();
78
+                            long diff = 1000 - millisPassed;
79
+
80
+                            UiThread.postDelayed(new Runnable() {
81
+                                @Override
82
+                                public void run() {
83
+                                    new NavigationEventEmitter(context).emitAppLaunched();
84
+                                }
85
+                            }, diff);
73 86
                         }
74 87
                     });
75 88
                     host.getReactInstanceManager().createReactContextInBackground();
@@ -80,7 +93,12 @@ public abstract class NavigationApplication extends Application implements React
80 93
                 host.getReactInstanceManager().onHostResume(activity, (DefaultHardwareBackBtnHandler) activity);
81 94
 
82 95
                 if (creating.compareAndSet(true, false)) {
83
-                    new NavigationEventEmitter(host.getReactInstanceManager().getCurrentReactContext()).emitAppLaunched();
96
+                    UiThread.postDelayed(new Runnable() {
97
+                        @Override
98
+                        public void run() {
99
+                            new NavigationEventEmitter(host.getReactInstanceManager().getCurrentReactContext()).emitAppLaunched();
100
+                        }
101
+                    }, 1000);
84 102
                 }
85 103
             }
86 104