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);
}
}
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> bottomSheetBehavior = BottomSheetBehavior.from(this);
bottomSheetBehavior.setHideable(false);
bottomSheetBehavior.setPeekHeight(200);
}
}
そして、私の反応コンポーネントはこのようになります。
index.android.js
return () {
<CoordinatorLayout style={{flex: 1}}>
<View><!--app--></View>
<BottomSheetBehavior>
<View style={{height: 300}}> <!--height doesnt work-->
<Text>BottomSheetBehavior !</Text>
</View>
</BottomSheetBehavior>
</CoordinatorLayout>
)
そしてそれはうまくいきます!
しかし、BottomSheet で子を でラップするのに苦労してきました。wrap_content
画面全体をスライドさせることは想定されていませんでした。反応コンポーネントでは機能しません。では、RelativeLayout
react<View style={{height: 300}} />
コンポーネントをラップする方法は? また、いくつかのメジャー shadownodeを実装しようとしましたが、期待どおりに機能しませんでした。それらがどのように機能するかわかりません。
誰もが試してみたいと思うように、この例を github に追加しました。 https://github.com/cesardeazevedo/react-native-bottom-sheet-behavior