我一直在编写一个包含BottomSheetBehavior的原生android模块.
一个非常简单的BottomSheetBehavior可以像这样实现 https://gist.github.com/cesardeazevedo/a4dc4ed12df33fe1877fc6cea42475ae
我面对的第一件事,整个页面必须是CoordinatorLayout的子节点和底部的BottomSheetBehavior.
所以我不得不写2个原生模块,<CoordinatorLayout />和<BottomSheetBehavior />.
这是bottomSheetBehavior包装器.
BottomSheetBehaviorManager.java
public class BottomSheetBehaviorManager extends ViewGroupManager<BottomSheetBehaviorView> {
@Override
public BottomSheetBehaviorView createViewInstance(ThemedReactContext context) {
return new BottomSheetBehaviorView(context);
}
}
Run Code Online (Sandbox Code Playgroud)
BottomSheetBehaviorView.java
public class BottomSheetBehaviorView extends RelativeLayout {
public BottomSheetBehaviorView(Context context) {
super(context);
int width = ViewGroup.LayoutParams.WRAP_CONTENT;
int height = ViewGroup.LayoutParams.WRAP_CONTENT;
// int height = 1000; // fixed a height works, it only slide up half of the screen
CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams(width, height);
params.setBehavior(new BottomSheetBehavior());
this.setLayoutParams(params);
BottomSheetBehavior<BottomSheetBehaviorView> …Run Code Online (Sandbox Code Playgroud)