Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Shared ReactInstanceManager in a singleton between multiple activities failing while showing a modal #15108

Closed
yurykorzun opened this issue Jul 19, 2017 · 5 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@yurykorzun
Copy link
Contributor

yurykorzun commented Jul 19, 2017

I integrated a React Native app into an existing Android app. When a native app requests a React Native view, I start a new activity with a React Native view in it. I wrapped ReactInstanceManager in a singleton class and initialize it when the Android app loads.

The problem I experience is that ReactInstanceManager cannot be shared between multiple instances of ReactNative views. For example, if I start one React Native activity and show a share sheet using the Share component, the next time I start a new activity and provide it the cached ReactInstanceManager, it will fail while trying to show a Modal. When the React Native tries to call mDialog.show it fails with android.view.WindowManager$BadTokenException: Unable to add window.
It looks like it tries to attach a dialog to a non-existent activity. It has something to do with the React Themed Context I guess.

It looks like ReactInstanceManager cannot be loaded once and shared safely between multiple instances of React Native views.

If anyone can share insight on how to share ReactInstanceManager properly, I would really appreciate that. Currently I am refreshing the manager every time I close a React Native Activity, but I would like to have a single instance.

  1. react-native -v: 0.42.3
  2. node -v: v6.11.0
  3. npm -v: 5.2.0
  4. platform: Android
@hramos
Copy link
Contributor

hramos commented Jul 19, 2017

Hey, thanks for reporting this issue!

It looks like your description is missing some necessary information, or the list of reproduction steps is not complete. Can you please add all the details specified in the template? This is necessary for people to be able to understand and reproduce the issue being reported.

I am going to close this, but feel free to open a new issue with the additional information provided. Thanks!

@hramos hramos closed this as completed Jul 19, 2017
@ManishPatiyal
Copy link

+1

@ManishPatiyal
Copy link

I also have the same requirement and need to have singleton pattern for ReactInstanceManager as I need to send custom events using RCTDeviceEventEmitter to react. For this I need the ReactInstanceManager which is null at the time I build it on android activities oncreate() method .

@AnyGong
Copy link

AnyGong commented Sep 1, 2017

+1

@KingAlen
Copy link

+1 In https://facebook.github.io/react-native/docs/integration-with-existing-apps.html
It says:
A ReactInstanceManager can be shared by multiple activities and/or fragments. You will want to make your own ReactFragment or ReactActivity and have a singleton holder that holds a ReactInstanceManager. When you need the ReactInstanceManager (e.g., to hook up the ReactInstanceManager to the lifecycle of those Activities or Fragments) use the one provided by the singleton.
But no example

@facebook facebook locked as resolved and limited conversation to collaborators Jul 19, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

6 participants