Skip to content

Commit 3e89b79

Browse files
Removed NestedScrollView
NestedScrollView is now on a diferrent repository, it will also serve as more general purpose to other different packages that uses CoordinatorLayout and others stuff. NestedScrollView is NOT a required dependency, since the anchor point has been implemented, once the BottomSheet already scrolls itself, the NestedScrollView is only useful when you are using the BottomSheet with anchorPoint disable and want to add some nested scroll (see the NestedScrollView example view) Now you have to install and attach the NestedScrollView manually on componentDidMount ``` componentDidMount() { this.bottomSheet.attachNestedScrollChild(this.nestedScroll) } ``` See the repository for installation instructions https://github.com/cesardeazevedo/react-native-nested-scroll-view And the NestedScrollView example https://github.com/cesardeazevedo/react-native-bottom-sheet-behavior/blob/master/example/views/NestedScrollView.js
1 parent 47b9102 commit 3e89b79

13 files changed

+67
-1303
lines changed

Diff for: android/src/main/java/com/bottomsheetbehavior/BottomSheetBehaviorManager.java

+42-39
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import android.support.annotation.NonNull;
44
import android.support.v4.view.ViewCompat;
5+
import android.support.v4.widget.NestedScrollView;
56
import android.view.MotionEvent;
67
import android.view.View;
8+
import android.view.ViewGroup;
79

810
import com.facebook.react.bridge.Arguments;
911
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
@@ -25,6 +27,7 @@ public class BottomSheetBehaviorManager extends ViewGroupManager<BottomSheetBeha
2527

2628
public static final int COMMAND_SET_REQUEST_LAYOUT = 1;
2729
public static final int COMMAND_SET_BOTTOM_SHEET_STATE = 2;
30+
public static final int COMMAND_ATTACH_NESTED_SCROLL_CHILD = 3;
2831

2932
@Override
3033
public String getName() {
@@ -71,44 +74,12 @@ public void setElevation(BottomSheetBehaviorView view, float elevation) {
7174
view.setBottomSheetElevation(elevation);
7275
}
7376

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-
10777
@Override
10878
public Map<String, Integer> getCommandsMap() {
10979
return MapBuilder
11080
.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);
11283
}
11384

11485
@Nullable
@@ -134,13 +105,21 @@ public Map<String, Object> getExportedCustomBubblingEventTypeConstants() {
134105
public void receiveCommand(BottomSheetBehaviorView view, int commandType, @Nullable ReadableArray args) {
135106
switch (commandType) {
136107
case COMMAND_SET_REQUEST_LAYOUT:
137-
setRequestLayout(view);
138-
return;
108+
setRequestLayout(view);
109+
return;
139110
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+
142121
default:
143-
throw new JSApplicationIllegalArgumentException("Invalid Command");
122+
throw new JSApplicationIllegalArgumentException("Invalid Command");
144123
}
145124
}
146125

@@ -155,6 +134,30 @@ private void setBottomSheetState(BottomSheetBehaviorView view, @Nullable Readabl
155134
}
156135
}
157136

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+
158161
public class BottomSheetBehaviorListener extends RNBottomSheetBehavior.BottomSheetCallback {
159162
@Override
160163
public void onStateChanged(@NonNull View bottomSheet, int newState) {

Diff for: android/src/main/java/com/bottomsheetbehavior/BottomSheetBehaviorPackage.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ public List<ViewManager> createViewManagers(ReactApplicationContext reactApplica
3131
new BottomSheetBehaviorManager(),
3232
new BackdropBottomSheetManager(),
3333
new CoordinatorLayoutManager(),
34-
new FloatingActionButtonManager(),
35-
new ReactNestedScrollViewManager()
34+
new FloatingActionButtonManager()
3635
);
3736
}
3837
}

0 commit comments

Comments
 (0)