0

I'm new to react-native and right now I'm trying to make a new react-native app using the Expo framework. As part of my app, I want to show a bar that displays over the screen even when my app is not active. (I know that display overlays are only possible on Android at the moment.) I can't find any expo package that allows me to render stuff as a display overlay, so it looks like I need to write my own native module to allow me to interface with Android's display overlay mechanisms.

Thus, I made a new native module based on Expo's tutorial, and added a new foreground service to handle the display overlay. Within the service, I made a new ViewGroup and added it as a display overlay, as described in this popular SO question. That worked successfully and I'm able to see text overlayed on my screen even when my app is not in the foreground.

The next thing I want to do is render a chip from react-native-paper in my overlay viewgroup. I made a component MyChip that's basically a react-native View with a Chip inside it. Based on the searches I've done, it seems like I need to call AppRegistry.registerComponent("MyChip", () => MyChip); to make my custom view available to react-native. From there, I should be able to do something like this to start up a new react-native view from the Android side that would interface with the MyChip component in react-native:

ReactRootView contentView = new ReactRootView(context);
LinearLayout container = (LinearLayout) parent.findViewById(R.id.view_container);
contentView.startReactApplication(reactInstanceManager, "MyChip", null)
container.addView(contentView, -1, new LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT));

^(this code was copy-pasted from this question)

Unfortunately, it seems ReactRootView is not directly available to import/instantiate within an Expo native module. Thus, I'm wondering whether Expo has its own special way to declare new ReactRootViews from its native modules? Or do I need to add a new dependency in my native module's build.gradle file to make it possible to declare a new ReactRootView?

takanuva15
  • 1,286
  • 1
  • 15
  • 27

0 Answers0