Ver código fonte

Remove finger tracking scroll logic

Guy Carmeli 8 anos atrás
pai
commit
b42ab00207

+ 4
- 1
android/app/src/main/java/com/reactnativenavigation/screens/FragmentScreen.java Ver arquivo

38
     }
38
     }
39
 
39
 
40
     private void addContent() {
40
     private void addContent() {
41
-        ContentView contentView = new ContentView(getContext(), screenParams.screenId, screenParams.passProps, screenParams.navigationParams, topBar);
41
+        ContentView contentView = new ContentView(getContext(),
42
+                screenParams.screenId,
43
+                screenParams.passProps,
44
+                screenParams.navigationParams);
42
         addView(contentView, 0, 0);
45
         addView(contentView, 0, 0);
43
         LayoutParams params = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
46
         LayoutParams params = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
44
         if (screenParams.styleParams.drawScreenBelowTopBar) {
47
         if (screenParams.styleParams.drawScreenBelowTopBar) {

+ 18
- 1
android/app/src/main/java/com/reactnativenavigation/screens/Screen.java Ver arquivo

9
 import android.view.Window;
9
 import android.view.Window;
10
 import android.widget.RelativeLayout;
10
 import android.widget.RelativeLayout;
11
 
11
 
12
+import com.reactnativenavigation.animation.VisibilityAnimator;
12
 import com.reactnativenavigation.params.ScreenParams;
13
 import com.reactnativenavigation.params.ScreenParams;
13
 import com.reactnativenavigation.params.StyleParams;
14
 import com.reactnativenavigation.params.StyleParams;
14
 import com.reactnativenavigation.params.TitleBarButtonParams;
15
 import com.reactnativenavigation.params.TitleBarButtonParams;
15
 import com.reactnativenavigation.params.TitleBarLeftButtonParams;
16
 import com.reactnativenavigation.params.TitleBarLeftButtonParams;
16
 import com.reactnativenavigation.utils.SdkSupports;
17
 import com.reactnativenavigation.utils.SdkSupports;
18
+import com.reactnativenavigation.utils.ViewUtils;
17
 import com.reactnativenavigation.views.TitleBarBackButtonListener;
19
 import com.reactnativenavigation.views.TitleBarBackButtonListener;
18
 import com.reactnativenavigation.views.TopBar;
20
 import com.reactnativenavigation.views.TopBar;
19
 
21
 
28
     protected final ScreenParams screenParams;
30
     protected final ScreenParams screenParams;
29
     protected TopBar topBar;
31
     protected TopBar topBar;
30
     private final TitleBarBackButtonListener titleBarBackButtonListener;
32
     private final TitleBarBackButtonListener titleBarBackButtonListener;
33
+    private VisibilityAnimator topBarVisibilityAnimator;
31
 
34
 
32
     public Screen(AppCompatActivity activity, ScreenParams screenParams, TitleBarBackButtonListener titleBarBackButtonListener) {
35
     public Screen(AppCompatActivity activity, ScreenParams screenParams, TitleBarBackButtonListener titleBarBackButtonListener) {
33
         super(activity);
36
         super(activity);
63
 
66
 
64
     private void createTopBar() {
67
     private void createTopBar() {
65
         topBar = new TopBar(getContext());
68
         topBar = new TopBar(getContext());
69
+        createTopBarVisibilityAnimator();
66
         addView(topBar, new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
70
         addView(topBar, new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
67
     }
71
     }
68
 
72
 
73
+    private void createTopBarVisibilityAnimator() {
74
+        ViewUtils.runOnPreDraw(topBar, new Runnable() {
75
+            @Override
76
+            public void run() {
77
+                if (topBarVisibilityAnimator == null) {
78
+                    topBarVisibilityAnimator = new VisibilityAnimator(topBar,
79
+                            VisibilityAnimator.HideDirection.Up,
80
+                            topBar.getHeight());
81
+                }
82
+            }
83
+        });
84
+    }
85
+
69
     private void setStyle(StyleParams styleParams) {
86
     private void setStyle(StyleParams styleParams) {
70
         setStatusBarColor(styleParams.statusBarColor);
87
         setStatusBarColor(styleParams.statusBarColor);
71
         setNavigationBarColor(styleParams.navigationBarColor);
88
         setNavigationBarColor(styleParams.navigationBarColor);
125
     }
142
     }
126
 
143
 
127
     public void setTopBarVisible(boolean visible, boolean animate) {
144
     public void setTopBarVisible(boolean visible, boolean animate) {
128
-        //        topBarVisibilityAnimator.setVisible(visible, animate); TODO
145
+        topBarVisibilityAnimator.setVisible(visible, animate);
129
     }
146
     }
130
 
147
 
131
     public void setTitleBarTitle(String title) {
148
     public void setTitleBarTitle(String title) {

+ 4
- 1
android/app/src/main/java/com/reactnativenavigation/screens/SingleScreen.java Ver arquivo

19
 
19
 
20
     @Override
20
     @Override
21
     protected void createContent() {
21
     protected void createContent() {
22
-        contentView = new ContentView(getContext(), screenParams.screenId, screenParams.passProps, screenParams.navigationParams, topBar);
22
+        contentView = new ContentView(getContext(),
23
+                screenParams.screenId,
24
+                screenParams.passProps,
25
+                screenParams.navigationParams);
23
         LayoutParams params = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
26
         LayoutParams params = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
24
         if (screenParams.styleParams.drawScreenBelowTopBar) {
27
         if (screenParams.styleParams.drawScreenBelowTopBar) {
25
             params.addRule(BELOW, topBar.getId());
28
             params.addRule(BELOW, topBar.getId());

+ 3
- 3
android/app/src/main/java/com/reactnativenavigation/screens/ViewPagerScreen.java Ver arquivo

21
 
21
 
22
     private List<ContentView> contentViews;
22
     private List<ContentView> contentViews;
23
     private ViewPager viewPager;
23
     private ViewPager viewPager;
24
-    private ContentViewPagerAdapter adapter;
25
 
24
 
26
     public ViewPagerScreen(AppCompatActivity activity, ScreenParams screenParams, TitleBarBackButtonListener backButtonListener) {
25
     public ViewPagerScreen(AppCompatActivity activity, ScreenParams screenParams, TitleBarBackButtonListener backButtonListener) {
27
         super(activity, screenParams, backButtonListener);
26
         super(activity, screenParams, backButtonListener);
39
             ContentView contentView = new ContentView(getContext(),
38
             ContentView contentView = new ContentView(getContext(),
40
                     topTabParam.screenId,
39
                     topTabParam.screenId,
41
                     screenParams.passProps,
40
                     screenParams.passProps,
42
-                    screenParams.navigationParams, topBar);
41
+                    screenParams.navigationParams);
43
             addContent(contentView);
42
             addContent(contentView);
44
             contentViews.add(contentView);
43
             contentViews.add(contentView);
45
         }
44
         }
46
 
45
 
47
-        adapter = new ContentViewPagerAdapter(viewPager, contentViews, screenParams.topTabParams);
46
+        ContentViewPagerAdapter adapter =
47
+                new ContentViewPagerAdapter(viewPager, contentViews, screenParams.topTabParams);
48
         viewPager.setAdapter(adapter);
48
         viewPager.setAdapter(adapter);
49
         tabLayout.setupWithViewPager(viewPager);
49
         tabLayout.setupWithViewPager(viewPager);
50
     }
50
     }

+ 1
- 53
android/app/src/main/java/com/reactnativenavigation/views/ContentView.java Ver arquivo

2
 
2
 
3
 import android.content.Context;
3
 import android.content.Context;
4
 import android.os.Bundle;
4
 import android.os.Bundle;
5
-import android.view.View;
6
-import android.widget.ScrollView;
7
 
5
 
8
 import com.facebook.react.ReactInstanceManager;
6
 import com.facebook.react.ReactInstanceManager;
9
 import com.facebook.react.ReactRootView;
7
 import com.facebook.react.ReactRootView;
15
     private final String screenId;
13
     private final String screenId;
16
     private final Bundle passProps;
14
     private final Bundle passProps;
17
     private Bundle navigationParams;
15
     private Bundle navigationParams;
18
-    private ScrollViewDelegate scrollViewDelegate = new ScrollViewDelegate();
19
 
16
 
20
-    public ContentView(Context context, final String screenId, Bundle passProps, Bundle navigationParams, final TopBar topBar) {
17
+    public ContentView(Context context, final String screenId, Bundle passProps, Bundle navigationParams) {
21
         super(context);
18
         super(context);
22
         this.screenId = screenId;
19
         this.screenId = screenId;
23
         this.passProps = passProps;
20
         this.passProps = passProps;
24
         this.navigationParams = navigationParams;
21
         this.navigationParams = navigationParams;
25
         attachToJS();
22
         attachToJS();
26
-
27
-        scrollViewDelegate.setListener(new ScrollViewDelegate.OnScrollListener() {
28
-
29
-            private ScrollDirection scrollDirectionComputer;
30
-
31
-
32
-            @Override
33
-            public void onScroll(ScrollView scrollView) {
34
-                /**
35
-                 * do our magic
36
-                 */
37
-                if (scrollDirectionComputer == null) {
38
-                    scrollDirectionComputer = new ScrollDirection(scrollView);
39
-                }
40
-
41
-                int currentTopBarTranslation = (int) topBar.getTranslationY();
42
-                int delta = scrollDirectionComputer.getScrollDelta();
43
-
44
-                int minTranslation = -topBar.getTitleBar().getHeight();
45
-                int maxTranslation = 0;
46
-
47
-                ScrollDirection.Direction direction = scrollDirectionComputer.getScrollDirection();
48
-
49
-                boolean reachedMinimum = direction == ScrollDirection.Direction.Up && currentTopBarTranslation <= minTranslation;
50
-                boolean reachedMaximum = direction == ScrollDirection.Direction.Down && currentTopBarTranslation >= maxTranslation;
51
-
52
-                if (direction == ScrollDirection.Direction.None || reachedMinimum || reachedMaximum) {
53
-                    if (reachedMinimum) {
54
-                        topBar.animate().translationY(minTranslation);
55
-                    }
56
-                    if (reachedMaximum) {
57
-                        topBar.animate().translationY(maxTranslation);
58
-                    }
59
-                } else {
60
-
61
-                    int target = currentTopBarTranslation - delta;
62
-                    int bound = Math.min(Math.max(minTranslation, target), maxTranslation);
63
-
64
-                    topBar.setTranslationY(bound);
65
-                }
66
-
67
-            }
68
-        });
69
     }
23
     }
70
 
24
 
71
     private void attachToJS() {
25
     private void attachToJS() {
73
         startReactApplication(react, screenId, mergePropsAndNavigationParams());
27
         startReactApplication(react, screenId, mergePropsAndNavigationParams());
74
     }
28
     }
75
 
29
 
76
-    @Override
77
-    public void onViewAdded(View child) {
78
-        super.onViewAdded(child);
79
-        scrollViewDelegate.onViewAdded(child);
80
-    }
81
-
82
     private Bundle mergePropsAndNavigationParams() {
30
     private Bundle mergePropsAndNavigationParams() {
83
         if (passProps != null) {
31
         if (passProps != null) {
84
             navigationParams.putAll(passProps);
32
             navigationParams.putAll(passProps);

+ 0
- 50
android/app/src/main/java/com/reactnativenavigation/views/ScrollDirection.java Ver arquivo

1
-package com.reactnativenavigation.views;
2
-
3
-import android.widget.ScrollView;
4
-
5
-public class ScrollDirection {
6
-
7
-    public enum Direction {
8
-        Up, Down, None
9
-    }
10
-
11
-    private final ScrollView scrollView;
12
-    private int lastScrollY = 0;
13
-
14
-    public ScrollDirection(ScrollView scrollView) {
15
-        this.scrollView = scrollView;
16
-    }
17
-
18
-    public Direction getScrollDirection() {
19
-        Direction direction = Direction.None;
20
-
21
-        final int scrollY = scrollView.getScrollY();
22
-        if (isScrollPositionChanged(scrollY) && !isTopOverscroll(scrollY) && !isBottomOverscroll(scrollY)) {
23
-            direction = getScrollDirection(scrollY);
24
-            lastScrollY = scrollY;
25
-        }
26
-        return direction;
27
-    }
28
-
29
-    public int getScrollDelta() {
30
-        return scrollView.getScrollY() - lastScrollY;
31
-    }
32
-
33
-
34
-    private Direction getScrollDirection(int scrollY) {
35
-        return scrollY > lastScrollY ? Direction.Up : Direction.Down;
36
-    }
37
-
38
-    private boolean isBottomOverscroll(int scrollY) {
39
-        return scrollY >= (scrollView.getChildAt(0).getHeight() - scrollView.getHeight());
40
-    }
41
-
42
-    private boolean isTopOverscroll(int scrollY) {
43
-        return scrollY <= 0;
44
-    }
45
-
46
-    private boolean isScrollPositionChanged(int scrollY) {
47
-        return scrollY != lastScrollY;
48
-    }
49
-
50
-}