Browse Source

Fix flickering when pushing screen

Should consider a better approach
Guy Carmeli 8 years ago
parent
commit
25a14e7dc4

+ 11
- 9
android/app/src/main/java/com/reactnativenavigation/views/ScreenStack.java View File

6
 import android.widget.FrameLayout;
6
 import android.widget.FrameLayout;
7
 
7
 
8
 import com.facebook.react.ReactInstanceManager;
8
 import com.facebook.react.ReactInstanceManager;
9
-import com.facebook.react.ReactRootView;
10
 import com.reactnativenavigation.activities.BaseReactActivity;
9
 import com.reactnativenavigation.activities.BaseReactActivity;
11
 import com.reactnativenavigation.core.RctManager;
10
 import com.reactnativenavigation.core.RctManager;
12
 import com.reactnativenavigation.core.objects.Screen;
11
 import com.reactnativenavigation.core.objects.Screen;
18
 
17
 
19
 public class ScreenStack extends FrameLayout {
18
 public class ScreenStack extends FrameLayout {
20
 
19
 
20
+    private static final int DISAPPEAR_ANIMATION_DELAY = 200;
21
+
21
     private static class ScreenView {
22
     private static class ScreenView {
22
         Screen screen;
23
         Screen screen;
23
         RctView view;
24
         RctView view;
53
     }
54
     }
54
 
55
 
55
     public void push(Screen screen, RctView.OnDisplayedListener onDisplayed) {
56
     public void push(Screen screen, RctView.OnDisplayedListener onDisplayed) {
56
-        RctView oldView = null;
57
-        if (!mStack.isEmpty()) {
58
-            oldView = mStack.peek().view;
59
-        }
57
+        RctView oldView = mStack.isEmpty() ? null : mStack.peek().view;
60
         RctView view = new RctView(mReactActivity, mReactInstanceManager, screen, onDisplayed);
58
         RctView view = new RctView(mReactActivity, mReactInstanceManager, screen, onDisplayed);
61
-        addView(view, MATCH_PARENT, MATCH_PARENT);
62
         if (oldView != null) {
59
         if (oldView != null) {
63
-            ReactRootView reactRootView = oldView.getReactRootView();
64
-            ReflectionUtils.setBooleanField(reactRootView, "mAttachScheduled", true);
60
+            addView(view, MATCH_PARENT, MATCH_PARENT);
61
+
62
+            ReflectionUtils.setBooleanField(oldView.getReactRootView(), "mAttachScheduled", true);
63
+            getLayoutTransition().setStartDelay(LayoutTransition.DISAPPEARING, DISAPPEAR_ANIMATION_DELAY);
65
             removeView(oldView);
64
             removeView(oldView);
65
+            getLayoutTransition().setStartDelay(LayoutTransition.DISAPPEARING, 0);
66
+        } else {
67
+            addView(view, MATCH_PARENT, MATCH_PARENT);
66
         }
68
         }
67
         mStack.push(new ScreenView(screen, view));
69
         mStack.push(new ScreenView(screen, view));
68
     }
70
     }
99
             addView(mStack.peek().view, 0);
101
             addView(mStack.peek().view, 0);
100
         }
102
         }
101
 
103
 
102
-        return oldScreenView.screen;
104
+        return oldScreenView != null ? oldScreenView.screen : null;
103
     }
105
     }
104
 
106
 
105
     public Screen resetTo(Screen screen) {
107
     public Screen resetTo(Screen screen) {