Browse Source

Apply stack options when stacks are attached to BottomTabs

Currently options are applied when a view is visible. This caused some noticeable flickering when
switching to tabs for the first time.
This commit adds a new callback which ViewController can override - onAttachToParent.
StackController now uses it to apply options which prevents flickering.
Guy Carmeli 6 years ago
parent
commit
0683ccbd00

+ 9
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ViewController.java View File

31
 
31
 
32
     private Runnable onAppearedListener;
32
     private Runnable onAppearedListener;
33
     private boolean appearEventPosted;
33
     private boolean appearEventPosted;
34
+    private boolean isFirstayout = true;
34
     private Bool waitForRender = new NullBool();
35
     private Bool waitForRender = new NullBool();
35
 
36
 
36
     public interface ViewVisibilityListener {
37
     public interface ViewVisibilityListener {
238
 
239
 
239
     @Override
240
     @Override
240
     public void onGlobalLayout() {
241
     public void onGlobalLayout() {
242
+        if (isFirstayout) {
243
+            onAttachToParent();
244
+            isFirstayout = false;
245
+        }
241
         if (!isShown && isViewShown()) {
246
         if (!isShown && isViewShown()) {
242
             if (!viewVisibilityListener.onViewAppeared(view)) {
247
             if (!viewVisibilityListener.onViewAppeared(view)) {
243
                 isShown = true;
248
                 isShown = true;
251
         }
256
         }
252
     }
257
     }
253
 
258
 
259
+    protected void onAttachToParent() {
260
+
261
+    }
262
+
254
     @Override
263
     @Override
255
     public void onChildViewAdded(View parent, View child) {
264
     public void onChildViewAdded(View parent, View child) {
256
         yellowBoxDelegate.onChildViewAdded(parent, child);
265
         yellowBoxDelegate.onChildViewAdded(parent, child);

+ 9
- 2
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackController.java View File

68
         return stack.peek();
68
         return stack.peek();
69
     }
69
     }
70
 
70
 
71
+    @Override
72
+    public void onAttachToParent() {
73
+        if (!isViewShown() && !isEmpty()) {
74
+            presenter.applyChildOptions(resolveCurrentOptions(), (Component) getCurrentChild().getView());
75
+        }
76
+    }
77
+
71
     @Override
78
     @Override
72
     public void mergeOptions(Options options) {
79
     public void mergeOptions(Options options) {
73
         presenter.mergeOptions(options, (Component) getCurrentChild().getView());
80
         presenter.mergeOptions(options, (Component) getCurrentChild().getView());
276
         controller.destroy();
283
         controller.destroy();
277
     }
284
     }
278
 
285
 
279
-    public ViewController peek() {
286
+    ViewController peek() {
280
         return stack.peek();
287
         return stack.peek();
281
     }
288
     }
282
 
289
 
298
     }
305
     }
299
 
306
 
300
     @VisibleForTesting()
307
     @VisibleForTesting()
301
-    public boolean canPop() {
308
+    boolean canPop() {
302
         return stack.size() > 1;
309
         return stack.size() > 1;
303
     }
310
     }
304
 
311
 

+ 16
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerTest.java View File

5
 import android.content.Context;
5
 import android.content.Context;
6
 import android.view.View;
6
 import android.view.View;
7
 import android.view.ViewGroup;
7
 import android.view.ViewGroup;
8
+import android.widget.FrameLayout;
8
 
9
 
9
 import com.reactnativenavigation.BaseTest;
10
 import com.reactnativenavigation.BaseTest;
10
 import com.reactnativenavigation.TestUtils;
11
 import com.reactnativenavigation.TestUtils;
915
         verify(presenter, times(0)).mergeChildOptions(any(), any(), any());
916
         verify(presenter, times(0)).mergeChildOptions(any(), any(), any());
916
     }
917
     }
917
 
918
 
919
+    @Test
920
+    public void resolvedOptionsAreAppliedWhenStackIsAttachedToParentAndNotVisible() {
921
+        FrameLayout parent = new FrameLayout(activity);
922
+        activity.setContentView(parent);
923
+
924
+        ViewController child = new SimpleViewController(activity, childRegistry, "child1", new Options());
925
+        StackController stack = createStack(Collections.singletonList(child));
926
+        stack.getView().setVisibility(View.INVISIBLE);
927
+
928
+        parent.addView(stack.getView());
929
+
930
+        Component component = (Component) child.getView();
931
+        verify(presenter).applyChildOptions(any(), eq(component));
932
+    }
933
+
918
     @Test
934
     @Test
919
     public void destroy() {
935
     public void destroy() {
920
         uut.ensureViewIsCreated();
936
         uut.ensureViewIsCreated();