2
2
3
3
import android .support .annotation .NonNull ;
4
4
import android .support .v4 .view .ViewCompat ;
5
+ import android .support .v4 .widget .NestedScrollView ;
5
6
import android .view .MotionEvent ;
6
7
import android .view .View ;
8
+ import android .view .ViewGroup ;
7
9
8
10
import com .facebook .react .bridge .Arguments ;
9
11
import com .facebook .react .bridge .JSApplicationIllegalArgumentException ;
@@ -25,6 +27,7 @@ public class BottomSheetBehaviorManager extends ViewGroupManager<BottomSheetBeha
25
27
26
28
public static final int COMMAND_SET_REQUEST_LAYOUT = 1 ;
27
29
public static final int COMMAND_SET_BOTTOM_SHEET_STATE = 2 ;
30
+ public static final int COMMAND_ATTACH_NESTED_SCROLL_CHILD = 3 ;
28
31
29
32
@ Override
30
33
public String getName () {
@@ -71,44 +74,12 @@ public void setElevation(BottomSheetBehaviorView view, float elevation) {
71
74
view .setBottomSheetElevation (elevation );
72
75
}
73
76
74
- /**
75
- * BottomSheetBehaviorView inherits a NestedScrollView in order to work
76
- * with the anchor point, but it breaks any ReactNestedScrollView child,
77
- * so we are changing the behavior of ReactNestedScrollView to disable
78
- * the nested scroll of the bottom sheet, and enable when the child scroll
79
- * reaches the top offset.
80
- */
81
- @ Override
82
- public void addView (final BottomSheetBehaviorView parent , View child , int index ) {
83
- super .addView (parent , child , index );
84
-
85
- final ReactNestedScrollView nestedScroll =
86
- (ReactNestedScrollView ) parent .findViewWithTag (ReactNestedScrollView .TAG );
87
-
88
- if (nestedScroll != null ) {
89
- nestedScroll .setOnTouchListener (new View .OnTouchListener () {
90
- @ Override
91
- public boolean onTouch (View v , MotionEvent event ) {
92
- int action = event .getAction ();
93
- if (action == MotionEvent .ACTION_MOVE ) {
94
- if (nestedScroll .computeVerticalScrollOffset () == 0 ) {
95
- parent .startNestedScroll (ViewCompat .SCROLL_AXIS_VERTICAL );
96
- } else {
97
- parent .stopNestedScroll ();
98
- }
99
- }
100
-
101
- return nestedScroll .onTouchEvent (event );
102
- }
103
- });
104
- }
105
- }
106
-
107
77
@ Override
108
78
public Map <String , Integer > getCommandsMap () {
109
79
return MapBuilder
110
80
.of ("setRequestLayout" , COMMAND_SET_REQUEST_LAYOUT ,
111
- "setBottomSheetState" , COMMAND_SET_BOTTOM_SHEET_STATE );
81
+ "setBottomSheetState" , COMMAND_SET_BOTTOM_SHEET_STATE ,
82
+ "attachNestedScrollChild" , COMMAND_ATTACH_NESTED_SCROLL_CHILD );
112
83
}
113
84
114
85
@ Nullable
@@ -134,13 +105,21 @@ public Map<String, Object> getExportedCustomBubblingEventTypeConstants() {
134
105
public void receiveCommand (BottomSheetBehaviorView view , int commandType , @ Nullable ReadableArray args ) {
135
106
switch (commandType ) {
136
107
case COMMAND_SET_REQUEST_LAYOUT :
137
- setRequestLayout (view );
138
- return ;
108
+ setRequestLayout (view );
109
+ return ;
139
110
case COMMAND_SET_BOTTOM_SHEET_STATE :
140
- setBottomSheetState (view , args );
141
- return ;
111
+ setBottomSheetState (view , args );
112
+ return ;
113
+ case COMMAND_ATTACH_NESTED_SCROLL_CHILD :
114
+ int nestedScrollId = args .getInt (0 );
115
+ ViewGroup child = (ViewGroup ) view .getRootView ().findViewById (nestedScrollId );
116
+ if (child != null && child instanceof NestedScrollView ) {
117
+ this .attachNestedScrollChild (view , (NestedScrollView ) child );
118
+ }
119
+ return ;
120
+
142
121
default :
143
- throw new JSApplicationIllegalArgumentException ("Invalid Command" );
122
+ throw new JSApplicationIllegalArgumentException ("Invalid Command" );
144
123
}
145
124
}
146
125
@@ -155,6 +134,30 @@ private void setBottomSheetState(BottomSheetBehaviorView view, @Nullable Readabl
155
134
}
156
135
}
157
136
137
+ /**
138
+ * BottomSheetBehaviorView inherits a NestedScrollView in order to work
139
+ * with the anchor point, but it breaks any ReactNestedScrollView child,
140
+ * so we are changing the behavior of ReactNestedScrollView to disable
141
+ * the nested scroll of the bottom sheet, and enable when the child scroll
142
+ * reaches the top offset.
143
+ */
144
+ private void attachNestedScrollChild (final BottomSheetBehaviorView parent , final NestedScrollView nestedScroll ) {
145
+ nestedScroll .setOnTouchListener (new View .OnTouchListener () {
146
+ @ Override
147
+ public boolean onTouch (View v , MotionEvent event ) {
148
+ int action = event .getAction ();
149
+ if (action == MotionEvent .ACTION_MOVE ) {
150
+ if (nestedScroll .computeVerticalScrollOffset () == 0 ) {
151
+ parent .startNestedScroll (ViewCompat .SCROLL_AXIS_VERTICAL );
152
+ } else {
153
+ parent .stopNestedScroll ();
154
+ }
155
+ }
156
+ return nestedScroll .onTouchEvent (event );
157
+ }
158
+ });
159
+ }
160
+
158
161
public class BottomSheetBehaviorListener extends RNBottomSheetBehavior .BottomSheetCallback {
159
162
@ Override
160
163
public void onStateChanged (@ NonNull View bottomSheet , int newState ) {
0 commit comments