Kaynağa Gözat

Remove finger tracking scroll logic

Guy Carmeli 8 yıl önce
ebeveyn
işleme
b42ab00207

+ 4
- 1
android/app/src/main/java/com/reactnativenavigation/screens/FragmentScreen.java Dosyayı Görüntüle

@@ -38,7 +38,10 @@ public class FragmentScreen extends Screen {
38 38
     }
39 39
 
40 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 45
         addView(contentView, 0, 0);
43 46
         LayoutParams params = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
44 47
         if (screenParams.styleParams.drawScreenBelowTopBar) {

+ 18
- 1
android/app/src/main/java/com/reactnativenavigation/screens/Screen.java Dosyayı Görüntüle

@@ -9,11 +9,13 @@ import android.util.Log;
9 9
 import android.view.Window;
10 10
 import android.widget.RelativeLayout;
11 11
 
12
+import com.reactnativenavigation.animation.VisibilityAnimator;
12 13
 import com.reactnativenavigation.params.ScreenParams;
13 14
 import com.reactnativenavigation.params.StyleParams;
14 15
 import com.reactnativenavigation.params.TitleBarButtonParams;
15 16
 import com.reactnativenavigation.params.TitleBarLeftButtonParams;
16 17
 import com.reactnativenavigation.utils.SdkSupports;
18
+import com.reactnativenavigation.utils.ViewUtils;
17 19
 import com.reactnativenavigation.views.TitleBarBackButtonListener;
18 20
 import com.reactnativenavigation.views.TopBar;
19 21
 
@@ -28,6 +30,7 @@ public abstract class Screen extends RelativeLayout {
28 30
     protected final ScreenParams screenParams;
29 31
     protected TopBar topBar;
30 32
     private final TitleBarBackButtonListener titleBarBackButtonListener;
33
+    private VisibilityAnimator topBarVisibilityAnimator;
31 34
 
32 35
     public Screen(AppCompatActivity activity, ScreenParams screenParams, TitleBarBackButtonListener titleBarBackButtonListener) {
33 36
         super(activity);
@@ -63,9 +66,23 @@ public abstract class Screen extends RelativeLayout {
63 66
 
64 67
     private void createTopBar() {
65 68
         topBar = new TopBar(getContext());
69
+        createTopBarVisibilityAnimator();
66 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 86
     private void setStyle(StyleParams styleParams) {
70 87
         setStatusBarColor(styleParams.statusBarColor);
71 88
         setNavigationBarColor(styleParams.navigationBarColor);
@@ -125,7 +142,7 @@ public abstract class Screen extends RelativeLayout {
125 142
     }
126 143
 
127 144
     public void setTopBarVisible(boolean visible, boolean animate) {
128
-        //        topBarVisibilityAnimator.setVisible(visible, animate); TODO
145
+        topBarVisibilityAnimator.setVisible(visible, animate);
129 146
     }
130 147
 
131 148
     public void setTitleBarTitle(String title) {

+ 4
- 1
android/app/src/main/java/com/reactnativenavigation/screens/SingleScreen.java Dosyayı Görüntüle

@@ -19,7 +19,10 @@ public class SingleScreen extends Screen {
19 19
 
20 20
     @Override
21 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 26
         LayoutParams params = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
24 27
         if (screenParams.styleParams.drawScreenBelowTopBar) {
25 28
             params.addRule(BELOW, topBar.getId());

+ 3
- 3
android/app/src/main/java/com/reactnativenavigation/screens/ViewPagerScreen.java Dosyayı Görüntüle

@@ -21,7 +21,6 @@ public class ViewPagerScreen extends Screen {
21 21
 
22 22
     private List<ContentView> contentViews;
23 23
     private ViewPager viewPager;
24
-    private ContentViewPagerAdapter adapter;
25 24
 
26 25
     public ViewPagerScreen(AppCompatActivity activity, ScreenParams screenParams, TitleBarBackButtonListener backButtonListener) {
27 26
         super(activity, screenParams, backButtonListener);
@@ -39,12 +38,13 @@ public class ViewPagerScreen extends Screen {
39 38
             ContentView contentView = new ContentView(getContext(),
40 39
                     topTabParam.screenId,
41 40
                     screenParams.passProps,
42
-                    screenParams.navigationParams, topBar);
41
+                    screenParams.navigationParams);
43 42
             addContent(contentView);
44 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 48
         viewPager.setAdapter(adapter);
49 49
         tabLayout.setupWithViewPager(viewPager);
50 50
     }

+ 1
- 53
android/app/src/main/java/com/reactnativenavigation/views/ContentView.java Dosyayı Görüntüle

@@ -2,8 +2,6 @@ package com.reactnativenavigation.views;
2 2
 
3 3
 import android.content.Context;
4 4
 import android.os.Bundle;
5
-import android.view.View;
6
-import android.widget.ScrollView;
7 5
 
8 6
 import com.facebook.react.ReactInstanceManager;
9 7
 import com.facebook.react.ReactRootView;
@@ -15,57 +13,13 @@ public class ContentView extends ReactRootView {
15 13
     private final String screenId;
16 14
     private final Bundle passProps;
17 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 18
         super(context);
22 19
         this.screenId = screenId;
23 20
         this.passProps = passProps;
24 21
         this.navigationParams = navigationParams;
25 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 25
     private void attachToJS() {
@@ -73,12 +27,6 @@ public class ContentView extends ReactRootView {
73 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 30
     private Bundle mergePropsAndNavigationParams() {
83 31
         if (passProps != null) {
84 32
             navigationParams.putAll(passProps);

+ 0
- 50
android/app/src/main/java/com/reactnativenavigation/views/ScrollDirection.java Dosyayı Görüntüle

@@ -1,50 +0,0 @@
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
-}