Просмотр исходного кода

Disable TopBar scroll when nestedScrollEnabled is enabled (#5856)

closes #5659
Guy Carmeli 5 лет назад
Родитель
Сommit
9a361a4fe3

+ 2
- 0
lib/android/app/src/main/java/com/reactnativenavigation/views/topbar/TopBar.java Просмотреть файл

@@ -245,10 +245,12 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
245 245
 
246 246
     public void enableCollapse(ScrollEventListener scrollEventListener) {
247 247
         collapsingBehavior.enableCollapse(scrollEventListener);
248
+        ((AppBarLayout.LayoutParams) root.getLayoutParams()).setScrollFlags(LayoutParams.SCROLL_FLAG_SCROLL);
248 249
     }
249 250
 
250 251
     public void disableCollapse() {
251 252
         collapsingBehavior.disableCollapse();
253
+        ((AppBarLayout.LayoutParams) root.getLayoutParams()).setScrollFlags(0);
252 254
     }
253 255
 
254 256
     public void clearBackgroundComponent() {

+ 13
- 0
lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarTest.java Просмотреть файл

@@ -2,12 +2,15 @@ package com.reactnativenavigation.views;
2 2
 
3 3
 import android.app.Activity;
4 4
 
5
+import com.google.android.material.appbar.AppBarLayout;
5 6
 import com.reactnativenavigation.BaseTest;
7
+import com.reactnativenavigation.interfaces.ScrollEventListener;
6 8
 import com.reactnativenavigation.utils.UiUtils;
7 9
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
8 10
 import com.reactnativenavigation.views.topbar.TopBar;
9 11
 
10 12
 import org.junit.Test;
13
+import org.mockito.Mockito;
11 14
 import org.robolectric.annotation.Config;
12 15
 
13 16
 import static org.assertj.core.api.Java6Assertions.assertThat;
@@ -42,4 +45,14 @@ public class TopBarTest extends BaseTest {
42 45
         uut.setElevation(Double.valueOf(2));
43 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
 }