How to get a view of the Android root app from React Native?

Trying to write an adaptive native adapter for the Bottomheet Flipboard Component .

I can create an instance of the BottomSheetLayout just fine, but I'm having trouble adjusting its views.

Per API docs I'm trying to call setContentView with "the view that appears below the presented sheet, usually with the root view of your application", but I can’t get the correct view from the React class.

I tried to save the link to the ReactRootView created in MainActivity , but it rejected it using "The specified child already has a parent."

Is there any other root view that I miss React Native apps? How can I get a link to it from my adapter class?

My component manager class is simplified:

 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 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 own children return true; } } 

ReactBottomSheetLayout is a very simple class that inherits the Flipboard BottomSheetLayout .

Thanks!

+5
source share

Source: https://habr.com/ru/post/1236120/


All Articles