瀏覽代碼

Fix flickering modal on Android

The initial modal screen got animated twice, this regression was introduced in #2761.
Guy Carmeli 6 年之前
父節點
當前提交
9534fe9402

+ 20
- 1
android/app/src/main/java/com/reactnativenavigation/layouts/ModalScreenLayout.java 查看文件

@@ -5,6 +5,8 @@ import android.support.v7.app.AppCompatActivity;
5 5
 import com.reactnativenavigation.params.ScreenParams;
6 6
 import com.reactnativenavigation.views.LeftButtonOnClickListener;
7 7
 
8
+import java.util.List;
9
+
8 10
 public class ModalScreenLayout extends SingleScreenLayout {
9 11
 
10 12
     public ModalScreenLayout(AppCompatActivity activity,
@@ -16,6 +18,23 @@ public class ModalScreenLayout extends SingleScreenLayout {
16 18
 
17 19
     @Override
18 20
     protected void pushInitialScreen(LayoutParams lp) {
19
-        stack.pushInitialModalScreenWithAnimation(screenParams, lp);
21
+        if (screenParams.screens.isEmpty()) {
22
+            stack.pushInitialModalScreenWithAnimation(screenParams, lp);
23
+        } else {
24
+            stack.pushInitialScreen(screenParams, lp);
25
+        }
26
+    }
27
+
28
+    @Override
29
+    protected void pushAdditionalScreens(LayoutParams lp) {
30
+        List<ScreenParams> screens = screenParams.screens;
31
+        for (int i = 0, screensSize = screens.size(); i < screensSize; i++) {
32
+            ScreenParams screen = screens.get(i);
33
+            if (i == screens.size() - 1) {
34
+                stack.pushInitialModalScreenWithAnimation(screen, lp);
35
+            } else {
36
+                stack.pushInitialScreen(screen, lp);
37
+            }
38
+        }
20 39
     }
21 40
 }

+ 2
- 2
android/app/src/main/java/com/reactnativenavigation/layouts/SingleScreenLayout.java 查看文件

@@ -86,17 +86,17 @@ public class SingleScreenLayout extends BaseLayout {
86 86
         LayoutParams lp = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
87 87
         pushInitialScreen(lp);
88 88
         pushAdditionalScreens(lp);
89
-        stack.show(NavigationType.Push);
90 89
     }
91 90
 
92 91
     protected void pushInitialScreen(LayoutParams lp) {
93 92
         stack.pushInitialScreen(screenParams, lp);
94 93
     }
95 94
 
96
-    private void pushAdditionalScreens(LayoutParams lp) {
95
+    protected void pushAdditionalScreens(LayoutParams lp) {
97 96
         for (ScreenParams screen : screenParams.screens) {
98 97
             stack.pushInitialScreen(screen, lp);
99 98
         }
99
+        stack.show(NavigationType.Push);
100 100
     }
101 101
 
102 102
     private void sendScreenChangedEventAfterInitialPush() {