Browse Source

Disable TopBar scroll when nestedScrollEnabled is enabled (#5856)

closes #5659
Guy Carmeli 5 years ago
parent
commit
9a361a4fe3

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

245
 
245
 
246
     public void enableCollapse(ScrollEventListener scrollEventListener) {
246
     public void enableCollapse(ScrollEventListener scrollEventListener) {
247
         collapsingBehavior.enableCollapse(scrollEventListener);
247
         collapsingBehavior.enableCollapse(scrollEventListener);
248
+        ((AppBarLayout.LayoutParams) root.getLayoutParams()).setScrollFlags(LayoutParams.SCROLL_FLAG_SCROLL);
248
     }
249
     }
249
 
250
 
250
     public void disableCollapse() {
251
     public void disableCollapse() {
251
         collapsingBehavior.disableCollapse();
252
         collapsingBehavior.disableCollapse();
253
+        ((AppBarLayout.LayoutParams) root.getLayoutParams()).setScrollFlags(0);
252
     }
254
     }
253
 
255
 
254
     public void clearBackgroundComponent() {
256
     public void clearBackgroundComponent() {

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

2
 
2
 
3
 import android.app.Activity;
3
 import android.app.Activity;
4
 
4
 
5
+import com.google.android.material.appbar.AppBarLayout;
5
 import com.reactnativenavigation.BaseTest;
6
 import com.reactnativenavigation.BaseTest;
7
+import com.reactnativenavigation.interfaces.ScrollEventListener;
6
 import com.reactnativenavigation.utils.UiUtils;
8
 import com.reactnativenavigation.utils.UiUtils;
7
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
9
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
8
 import com.reactnativenavigation.views.topbar.TopBar;
10
 import com.reactnativenavigation.views.topbar.TopBar;
9
 
11
 
10
 import org.junit.Test;
12
 import org.junit.Test;
13
+import org.mockito.Mockito;
11
 import org.robolectric.annotation.Config;
14
 import org.robolectric.annotation.Config;
12
 
15
 
13
 import static org.assertj.core.api.Java6Assertions.assertThat;
16
 import static org.assertj.core.api.Java6Assertions.assertThat;
42
         uut.setElevation(Double.valueOf(2));
45
         uut.setElevation(Double.valueOf(2));
43
         assertThat(uut.getElevation()).isEqualTo(UiUtils.dpToPx(activity, 2));
46
         assertThat(uut.getElevation()).isEqualTo(UiUtils.dpToPx(activity, 2));
44
     }
47
     }
48
+
49
+    @Test
50
+    public void disableCollapse_scrollIsDisabled() {
51
+        AppBarLayout.LayoutParams lp = (AppBarLayout.LayoutParams) uut.getChildAt(0).getLayoutParams();
52
+        uut.enableCollapse(Mockito.mock(ScrollEventListener.class));
53
+        assertThat(lp.getScrollFlags()).isEqualTo(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL);
54
+
55
+        uut.disableCollapse();
56
+        assertThat(lp.getScrollFlags()).isZero();
57
+    }
45
 }
58
 }