Ped*_*dro 5 android view react-native
尝试为Flipboard底部组件编写反应原生的本机适配器.
我可以实例化他们的BottomSheetLayout正常,但无法尝试使用视图进行设置.
根据API文档,我试图setContentView使用"正在呈现的工作表下显示的视图,通常是应用程序的根视图" 来调用,但我似乎无法从我的React类中获得正确的视图.
尝试保存对ReactRootView实例化的引用MainActivity,但它被拒绝,"指定的子代已经有父代".
我还缺少React Native应用程序的另一个根视图吗?如何从我的适配器类中获取它的引用?
我的组件管理器类,简化:
public class ReactBottomSheetManager extends ViewGroupManager<ReactBottomSheetLayout> {
private View mRootView = null;
private View mContentView = null;
public static final int COMMAND_OPEN = 1;
public ReactBottomSheetManager(View rootView) {
super();
mRootView = rootView; // this is the ReactRootView from MainActivity
}
@Override
public String getName() {
return "BottomSheetAndroid";
}
@Override
protected ReactBottomSheetLayout createViewInstance(ThemedReactContext context) {
ReactBottomSheetLayout view = new ReactBottomSheetLayout(context);
view.setPeekOnDismiss(true);
view.setContentView(mRootView); // here is where things blow up
return view;
}
@Override
public Map<String, Integer> getCommandsMap() {
return MapBuilder.of("open", COMMAND_OPEN);
}
@Override
public void receiveCommand(ReactBottomSheetLayout view, int commandType, @Nullable ReadableArray args) {
switch(commandType) {
case COMMAND_OPEN: {
view.showWithSheetView(mContentView);
return;
}
}
}
// overriding addView to save a reference to the view instead of adding it
// to the bottom sheet layout right away. we'll add/show this view when
// it's time to open the sheet.
@Override
public void addView(ReactBottomSheetLayout parent, View child, int index) {
Log.d("ReactNative", "addView called with index=" + index);
mContentView = child;
}
@Override
public boolean needsCustomLayoutForChildren() {
// BottomSheetLayout will lay out it's own children
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
ReactBottomSheetLayout是一个非常简单的继承Flipboard的类BottomSheetLayout.
谢谢!
| 归档时间: |
|
| 查看次数: |
991 次 |
| 最近记录: |