Browse Source

Stack id (#2917)

* WIP

* Apply default options when screen options are null

* modal animations

* fix tests

* refactor

* refactor

* refactor

* refactor

* test fix

* topBar anim

* child disappear bug

* Update app.js

* Update WelcomeScreen.js

* fix tests

* bottom tabs

* stack id

* fix test

* refactoring

* merge fix

* Update app.js

* merge

* comment to fix test
Roman Kozlov 6 years ago
parent
commit
6c4f3a391a

+ 10
- 2
lib/android/app/src/main/java/com/reactnativenavigation/anim/TopBarAnimator.java View File

@@ -13,6 +13,8 @@ import android.view.animation.DecelerateInterpolator;
13 13
 import com.reactnativenavigation.parse.AnimationOptions;
14 14
 import com.reactnativenavigation.views.topbar.TopBar;
15 15
 
16
+import javax.annotation.Nullable;
17
+
16 18
 public class TopBarAnimator {
17 19
 
18 20
     private static final int DEFAULT_COLLAPSE_DURATION = 100;
@@ -21,6 +23,7 @@ public class TopBarAnimator {
21 23
     private final AccelerateInterpolator accelerateInterpolator = new AccelerateInterpolator();
22 24
 
23 25
     private TopBar topBar;
26
+    private String stackId;
24 27
     private AnimatorSet hideAnimator;
25 28
     private AnimatorSet showAnimator;
26 29
 
@@ -28,8 +31,13 @@ public class TopBarAnimator {
28 31
         this.topBar = topBar;
29 32
     }
30 33
 
34
+    public TopBarAnimator(TopBar topBar, @Nullable String stackId) {
35
+        this.topBar = topBar;
36
+        this.stackId = stackId;
37
+    }
38
+
31 39
     public void show(AnimationOptions options) {
32
-        if (options.hasValue()) {
40
+        if (options.hasValue() && (!options.id.hasValue() || options.id.get().equals(stackId))) {
33 41
             showAnimator = options.getAnimation(topBar);
34 42
         } else {
35 43
             showAnimator = getDefaultShowAnimator(-1 * topBar.getMeasuredHeight(), decelerateInterpolator, DURATION_TOPBAR);
@@ -62,7 +70,7 @@ public class TopBarAnimator {
62 70
     }
63 71
 
64 72
     public void hide(AnimationOptions options, AnimationListener listener) {
65
-        if (options.hasValue()) {
73
+        if (options.hasValue() && (!options.id.hasValue() || options.id.get().equals(stackId))) {
66 74
             hideAnimator = options.getAnimation(topBar);
67 75
         } else {
68 76
             hideAnimator = getDefaultHideAnimator(0, accelerateInterpolator, DURATION_TOPBAR);

+ 5
- 3
lib/android/app/src/main/java/com/reactnativenavigation/anim/TopBarCollapseBehavior.java View File

@@ -22,9 +22,11 @@ public class TopBarCollapseBehavior implements ScrollEventListener.OnScrollListe
22 22
     }
23 23
 
24 24
     public void disableCollapse() {
25
-        scrollEventListener.unregister();
26
-        topBar.setVisibility(View.VISIBLE);
27
-        topBar.setTranslationY(0);
25
+        if (scrollEventListener != null) {
26
+            scrollEventListener.unregister();
27
+            topBar.setVisibility(View.VISIBLE);
28
+            topBar.setTranslationY(0);
29
+        }
28 30
     }
29 31
 
30 32
     @Override

+ 13
- 2
lib/android/app/src/main/java/com/reactnativenavigation/parse/AnimationOptions.java View File

@@ -7,6 +7,10 @@ import android.util.Log;
7 7
 import android.util.Property;
8 8
 import android.view.View;
9 9
 
10
+import com.reactnativenavigation.parse.params.NullText;
11
+import com.reactnativenavigation.parse.params.Text;
12
+import com.reactnativenavigation.parse.parsers.TextParser;
13
+
10 14
 import org.json.JSONObject;
11 15
 
12 16
 import java.util.ArrayList;
@@ -23,7 +27,11 @@ public class AnimationOptions {
23 27
         options.hasValue = true;
24 28
         for (Iterator<String> it = json.keys(); it.hasNext(); ) {
25 29
             String key = it.next();
26
-            options.valueOptions.add(ValueAnimationOptions.parse(json.optJSONObject(key), getAnimProp(key)));
30
+            if ("id".equals(key)) {
31
+                options.id = TextParser.parse(json, key);
32
+            } else {
33
+                options.valueOptions.add(ValueAnimationOptions.parse(json.optJSONObject(key), getAnimProp(key)));
34
+            }
27 35
         }
28 36
 
29 37
         return options;
@@ -31,11 +39,13 @@ public class AnimationOptions {
31 39
 
32 40
     private boolean hasValue = false;
33 41
 
42
+    public Text id = new NullText();
34 43
     private HashSet<ValueAnimationOptions> valueOptions = new HashSet<>();
35 44
 
36 45
     void mergeWith(AnimationOptions other) {
37 46
         if (other.hasValue()) {
38 47
             hasValue = true;
48
+            id = other.id;
39 49
             valueOptions = other.valueOptions;
40 50
         }
41 51
     }
@@ -43,6 +53,7 @@ public class AnimationOptions {
43 53
     void mergeWithDefault(AnimationOptions defaultOptions) {
44 54
         if (defaultOptions.hasValue()) {
45 55
             hasValue = true;
56
+            id = defaultOptions.id;
46 57
             valueOptions = defaultOptions.valueOptions;
47 58
         }
48 59
     }
@@ -54,7 +65,7 @@ public class AnimationOptions {
54 65
     public AnimatorSet getAnimation(View view) {
55 66
         AnimatorSet animationSet = new AnimatorSet();
56 67
         List<Animator> animators = new ArrayList<>();
57
-        for (ValueAnimationOptions options: valueOptions) {
68
+        for (ValueAnimationOptions options : valueOptions) {
58 69
             animators.add(options.getAnimation(view));
59 70
         }
60 71
         animationSet.playTogether(animators);

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/presentation/OptionsPresenter.java View File

@@ -69,7 +69,7 @@ public class OptionsPresenter {
69 69
             if (component instanceof IReactView) {
70 70
                 topBar.enableCollapse(((IReactView) component).getScrollEventListener());
71 71
             }
72
-        } else if (options.hideOnScroll.isTrue()) {
72
+        } else if (options.hideOnScroll.isFalseOrUndefined()) {
73 73
             topBar.disableCollapse();
74 74
         }
75 75
     }

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

@@ -229,7 +229,7 @@ public class StackController extends ParentController<StackLayout> {
229 229
     @NonNull
230 230
     @Override
231 231
     protected StackLayout createView() {
232
-        return new StackLayout(getActivity(), topBarButtonCreator, titleBarReactViewCreator, topBarBackgroundViewCreator, this::sendOnNavigationButtonPressed);
232
+        return new StackLayout(getActivity(), topBarButtonCreator, titleBarReactViewCreator, topBarBackgroundViewCreator, this::sendOnNavigationButtonPressed, getId());
233 233
     }
234 234
 
235 235
     @NonNull

+ 8
- 2
lib/android/app/src/main/java/com/reactnativenavigation/views/StackLayout.java View File

@@ -22,10 +22,12 @@ import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
22 22
 @SuppressLint("ViewConstructor")
23 23
 public class StackLayout extends RelativeLayout {
24 24
     private TopBar topBar;
25
+    private String stackId;
25 26
     private final OptionsPresenter optionsPresenter;
26 27
 
27
-    public StackLayout(Context context, ReactViewCreator topBarButtonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewCreator topBarBackgroundViewCreator, TopBarButtonController.OnClickListener topBarButtonClickListener) {
28
+    public StackLayout(Context context, ReactViewCreator topBarButtonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewCreator topBarBackgroundViewCreator, TopBarButtonController.OnClickListener topBarButtonClickListener, String stackId) {
28 29
         super(context);
30
+        this.stackId = stackId;
29 31
         createLayout(topBarButtonCreator, titleBarReactViewCreator, topBarBackgroundViewCreator, topBarButtonClickListener);
30 32
         optionsPresenter = new OptionsPresenter(topBar);
31 33
         setContentDescription("StackLayout");
@@ -46,7 +48,7 @@ public class StackLayout extends RelativeLayout {
46 48
     }
47 49
 
48 50
     public void onChildWillDisappear(Options disappearing, Options appearing, ChildDisappearListener childDisappearListener) {
49
-        new OptionsPresenter(topBar).onChildWillDisappear(disappearing, appearing, childDisappearListener);
51
+        optionsPresenter.onChildWillDisappear(disappearing, appearing, childDisappearListener);
50 52
     }
51 53
 
52 54
     public void clearOptions() {
@@ -69,4 +71,8 @@ public class StackLayout extends RelativeLayout {
69 71
     public void mergeChildOptions(Options options, Component child) {
70 72
         optionsPresenter.mergeChildOptions(options, child);
71 73
     }
74
+
75
+    public String getStackId() {
76
+        return stackId;
77
+    }
72 78
 }

+ 2
- 1
lib/android/app/src/main/java/com/reactnativenavigation/views/topbar/TopBar.java View File

@@ -53,7 +53,8 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
53 53
         collapsingBehavior = new TopBarCollapseBehavior(this);
54 54
         this.topBarBackgroundViewCreator = topBarBackgroundViewCreator;
55 55
         this.parentView = parentView;
56
-        animator = new TopBarAnimator(this);
56
+        topTabs = new TopTabs(getContext());
57
+        animator = new TopBarAnimator(this, parentView.getStackId());
57 58
         createLayout(buttonCreator, titleBarReactViewCreator, onClickListener);
58 59
     }
59 60
 

+ 1
- 1
lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarBackgroundComponentTest.java View File

@@ -42,7 +42,7 @@ public class TopBarBackgroundComponentTest extends BaseTest {
42 42
                 return backgroundView;
43 43
             }
44 44
         };
45
-        StackLayout parent = new StackLayout(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), backgroundViewCreator, onClickListener);
45
+        StackLayout parent = new StackLayout(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), backgroundViewCreator, onClickListener, null);
46 46
         uut = new TopBar(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), backgroundViewCreator, onClickListener, parent);
47 47
         parent.addView(uut);
48 48
     }

+ 1
- 1
lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarTest.java View File

@@ -41,7 +41,7 @@ public class TopBarTest extends BaseTest {
41 41
                 Log.i("TopBarTest", "onPress: " + buttonId);
42 42
             }
43 43
         });
44
-        StackLayout parent = new StackLayout(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), this.onClickListener);
44
+        StackLayout parent = new StackLayout(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), this.onClickListener, null);
45 45
         uut = new TopBar(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), this.onClickListener, parent);
46 46
         animator = spy(new TopBarAnimator(uut));
47 47
         uut.setAnimator(animator);

+ 21
- 2
playground/src/app.js View File

@@ -27,17 +27,26 @@ function start() {
27 27
       _animations: {
28 28
         push: {
29 29
           topBar: {
30
+            id: 'TEST',
31
+            alpha: {
32
+              from: 0,
33
+              to: 1,
34
+              duration: 500,
35
+              interpolation: 'accelerate'
36
+            }
37
+          },
38
+          bottomTabs: {
30 39
             y: {
31 40
               from: 1000,
32 41
               to: 0,
33 42
               duration: 500,
34
-              interpolation: 'accelerate',
43
+              interpolation: 'decelerate',
35 44
             },
36 45
             alpha: {
37 46
               from: 0,
38 47
               to: 1,
39 48
               duration: 500,
40
-              interpolation: 'accelerate'
49
+              interpolation: 'decelerate'
41 50
             }
42 51
           },
43 52
           bottomTabs: {
@@ -71,6 +80,15 @@ function start() {
71 80
         },
72 81
         pop: {
73 82
           topBar: {
83
+            id: 'TEST',
84
+            alpha: {
85
+              from: 1,
86
+              to: 0,
87
+              duration: 500,
88
+              interpolation: 'accelerate'
89
+            }
90
+          },
91
+          bottomTabs: {
74 92
             y: {
75 93
               from: 0,
76 94
               to: 100,
@@ -118,6 +136,7 @@ function start() {
118 136
 
119 137
     Navigation.setRoot({
120 138
       stack: {
139
+        id: 'TEST',
121 140
         children: [
122 141
           {
123 142
             component: {

+ 4
- 4
playground/src/screens/CustomTopBar.js View File

@@ -17,19 +17,19 @@ class CustomTopBar extends Component {
17 17
   }
18 18
 
19 19
   componentDidAppear() {
20
-    console.log('guyca', 'componentDidAppear');
20
+    // console.log('guyca', 'componentDidAppear');
21 21
   }
22 22
 
23 23
   componentDidDisappear() {
24
-    console.log('guyca', `componentDidDisappear`);
24
+    // console.log('guyca', `componentDidDisappear`);
25 25
   }
26 26
 
27 27
   componentDidMount() {
28
-    console.log('guyca', `componentDidMount`);
28
+    // console.log('guyca', `componentDidMount`);
29 29
   }
30 30
 
31 31
   componentWillUnmount() {
32
-    console.log('guyca', `componentWillUnmount`);
32
+    // console.log('guyca', `componentWillUnmount`);
33 33
   }
34 34
 
35 35
   render() {