Browse Source

Fix flickering modal on Android

The initial modal screen got animated twice, this regression was introduced in #2761.
Guy Carmeli 6 years ago
parent
commit
9534fe9402

+ 20
- 1
android/app/src/main/java/com/reactnativenavigation/layouts/ModalScreenLayout.java View File

5
 import com.reactnativenavigation.params.ScreenParams;
5
 import com.reactnativenavigation.params.ScreenParams;
6
 import com.reactnativenavigation.views.LeftButtonOnClickListener;
6
 import com.reactnativenavigation.views.LeftButtonOnClickListener;
7
 
7
 
8
+import java.util.List;
9
+
8
 public class ModalScreenLayout extends SingleScreenLayout {
10
 public class ModalScreenLayout extends SingleScreenLayout {
9
 
11
 
10
     public ModalScreenLayout(AppCompatActivity activity,
12
     public ModalScreenLayout(AppCompatActivity activity,
16
 
18
 
17
     @Override
19
     @Override
18
     protected void pushInitialScreen(LayoutParams lp) {
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 View File

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