Search in sources :

Example 11 with ReactInstanceManager

use of com.facebook.react.ReactInstanceManager in project react-native-fcm by evollu.

the class InstanceIdService method onTokenRefresh.

/**
 * Called if InstanceID token is updated. This may occur if the security of
 * the previous token had been compromised. This call is initiated by the
 * InstanceID provider.
 */
// [START refresh_token]
@Override
public void onTokenRefresh() {
    // Get updated InstanceID token.
    String refreshedToken = FirebaseInstanceId.getInstance().getToken();
    Log.d(TAG, "Refreshed token: " + refreshedToken);
    // Broadcast refreshed token
    Intent i = new Intent("com.evollu.react.fcm.FCMRefreshToken");
    Bundle bundle = new Bundle();
    bundle.putString("token", refreshedToken);
    i.putExtras(bundle);
    final Intent message = i;
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {

        public void run() {
            // Construct and load our normal React JS code bundle
            ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();
            ReactContext context = mReactInstanceManager.getCurrentReactContext();
            // If it's constructed, send a notification
            if (context != null) {
                LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
            } else {
                // Otherwise wait for construction, then send the notification
                mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {

                    public void onReactContextInitialized(ReactContext context) {
                        LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
                    }
                });
                if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
                    // Construct it in the background
                    mReactInstanceManager.createReactContextInBackground();
                }
            }
        }
    });
}
Also used : ReactInstanceManager(com.facebook.react.ReactInstanceManager) ReactContext(com.facebook.react.bridge.ReactContext) Bundle(android.os.Bundle) Handler(android.os.Handler) Intent(android.content.Intent) ReactApplication(com.facebook.react.ReactApplication)

Example 12 with ReactInstanceManager

use of com.facebook.react.ReactInstanceManager in project react-native-fcm by evollu.

the class MessagingService method onMessageReceived.

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    Log.d(TAG, "Remote message received");
    Intent i = new Intent("com.evollu.react.fcm.ReceiveNotification");
    i.putExtra("data", remoteMessage);
    handleBadge(remoteMessage);
    buildLocalNotification(remoteMessage);
    final Intent message = i;
    // We need to run this on the main thread, as the React code assumes that is true.
    // Namely, DevServerHelper constructs a Handler() without a Looper, which triggers:
    // "Can't create handler inside thread that has not called Looper.prepare()"
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {

        public void run() {
            // Construct and load our normal React JS code bundle
            ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager();
            ReactContext context = mReactInstanceManager.getCurrentReactContext();
            // If it's constructed, send a notification
            if (context != null) {
                LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
            } else {
                // Otherwise wait for construction, then send the notification
                mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {

                    public void onReactContextInitialized(ReactContext context) {
                        LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(message);
                    }
                });
                if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
                    // Construct it in the background
                    mReactInstanceManager.createReactContextInBackground();
                }
            }
        }
    });
}
Also used : ReactInstanceManager(com.facebook.react.ReactInstanceManager) ReactContext(com.facebook.react.bridge.ReactContext) Handler(android.os.Handler) Intent(android.content.Intent) ReactApplication(com.facebook.react.ReactApplication)

Example 13 with ReactInstanceManager

use of com.facebook.react.ReactInstanceManager in project react-native-navigation by wix.

the class NavigatorTest method beforeEach.

@Override
public void beforeEach() {
    super.beforeEach();
    childRegistry = new ChildControllersRegistry();
    eventEmitter = Mockito.mock(EventEmitter.class);
    reactInstanceManager = Mockito.mock(ReactInstanceManager.class);
    overlayManager = spy(new OverlayManager());
    imageLoaderMock = ImageLoaderMock.mock();
    activityController = newActivityController(TestActivity.class);
    activity = activityController.create().get();
    modalStack = spy(new ModalStack(activity));
    rootPresenter = spy(new RootPresenter());
    modalStack.setEventEmitter(Mockito.mock(EventEmitter.class));
    uut = new Navigator(activity, childRegistry, modalStack, overlayManager, rootPresenter);
    activity.setNavigator(uut);
    ViewController<?> initialChild = new SimpleViewController(activity, childRegistry, "initialChild", Options.EMPTY);
    parentController = newStack(initialChild);
    parentVisibilityListener = spy(new ViewController.ViewVisibilityListener() {

        @Override
        public boolean onViewAppeared(View view) {
            return false;
        }

        @Override
        public boolean onViewDisappear(View view) {
            return false;
        }
    });
    parentController.setViewVisibilityListener(parentVisibilityListener);
    child1 = new SimpleViewController(activity, childRegistry, "child1", tabOptions);
    child2 = new SimpleViewController(activity, childRegistry, "child2", tabOptions);
    child3 = new SimpleViewController(activity, childRegistry, "child3", tabOptions);
    child4 = new SimpleViewController(activity, childRegistry, "child4", tabOptions);
    child5 = new SimpleViewController(activity, childRegistry, "child5", tabOptions);
    uut.bindViews();
    activityController.visible();
    activityController.postCreate(Bundle.EMPTY);
    idleMainLooper();
}
Also used : OverlayManager(com.reactnativenavigation.viewcontrollers.overlay.OverlayManager) ModalStack(com.reactnativenavigation.viewcontrollers.modal.ModalStack) ReactInstanceManager(com.facebook.react.ReactInstanceManager) EventEmitter(com.reactnativenavigation.react.events.EventEmitter) ChildControllersRegistry(com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry) TestActivity(com.reactnativenavigation.TestActivity) RootPresenter(com.reactnativenavigation.viewcontrollers.viewcontroller.RootPresenter) SimpleViewController(com.reactnativenavigation.mocks.SimpleViewController) View(android.view.View)

Example 14 with ReactInstanceManager

use of com.facebook.react.ReactInstanceManager in project react-native-camera by lwansbrough.

the class ReactNativeFlipper method initializeFlipper.

public static void initializeFlipper(Context context, final ReactInstanceManager reactInstanceManager) {
    if (FlipperUtils.shouldEnableFlipper(context)) {
        final FlipperClient client = AndroidFlipperClient.getInstance(context);
        client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults()));
        client.addPlugin(new ReactFlipperPlugin());
        client.addPlugin(new DatabasesFlipperPlugin(context));
        client.addPlugin(new SharedPreferencesFlipperPlugin(context));
        client.addPlugin(CrashReporterPlugin.getInstance());
        final NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin();
        NetworkingModule.setCustomClientBuilder(new NetworkingModule.CustomClientBuilder() {

            @Override
            public void apply(OkHttpClient.Builder builder) {
                builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin));
            }
        });
        client.addPlugin(networkFlipperPlugin);
        client.start();
        // Fresco Plugin needs to ensure that ImagePipelineFactory is initialized
        // Hence we run if after all native modules have been initialized
        ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
        if (reactContext == null) {
            reactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {

                @Override
                public void onReactContextInitialized(ReactContext reactContext) {
                    reactInstanceManager.removeReactInstanceEventListener(this);
                    reactContext.runOnNativeModulesQueueThread(new Runnable() {

                        @Override
                        public void run() {
                            client.addPlugin(new FrescoFlipperPlugin());
                        }
                    });
                }
            });
        } else {
            client.addPlugin(new FrescoFlipperPlugin());
        }
    }
}
Also used : FlipperOkhttpInterceptor(com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor) AndroidFlipperClient(com.facebook.flipper.android.AndroidFlipperClient) FlipperClient(com.facebook.flipper.core.FlipperClient) OkHttpClient(okhttp3.OkHttpClient) ReactInstanceManager(com.facebook.react.ReactInstanceManager) InspectorFlipperPlugin(com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin) ReactFlipperPlugin(com.facebook.flipper.plugins.react.ReactFlipperPlugin) DatabasesFlipperPlugin(com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin) ReactContext(com.facebook.react.bridge.ReactContext) FrescoFlipperPlugin(com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin) NetworkFlipperPlugin(com.facebook.flipper.plugins.network.NetworkFlipperPlugin) SharedPreferencesFlipperPlugin(com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin) NetworkingModule(com.facebook.react.modules.network.NetworkingModule)

Example 15 with ReactInstanceManager

use of com.facebook.react.ReactInstanceManager in project react-native-orientation-locker by wonday.

the class ReactNativeFlipper method initializeFlipper.

public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) {
    if (FlipperUtils.shouldEnableFlipper(context)) {
        final FlipperClient client = AndroidFlipperClient.getInstance(context);
        client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults()));
        client.addPlugin(new ReactFlipperPlugin());
        client.addPlugin(new DatabasesFlipperPlugin(context));
        client.addPlugin(new SharedPreferencesFlipperPlugin(context));
        client.addPlugin(CrashReporterPlugin.getInstance());
        NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin();
        NetworkingModule.setCustomClientBuilder(new NetworkingModule.CustomClientBuilder() {

            @Override
            public void apply(OkHttpClient.Builder builder) {
                builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin));
            }
        });
        client.addPlugin(networkFlipperPlugin);
        client.start();
        // Fresco Plugin needs to ensure that ImagePipelineFactory is initialized
        // Hence we run if after all native modules have been initialized
        ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
        if (reactContext == null) {
            reactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {

                @Override
                public void onReactContextInitialized(ReactContext reactContext) {
                    reactInstanceManager.removeReactInstanceEventListener(this);
                    reactContext.runOnNativeModulesQueueThread(new Runnable() {

                        @Override
                        public void run() {
                            client.addPlugin(new FrescoFlipperPlugin());
                        }
                    });
                }
            });
        } else {
            client.addPlugin(new FrescoFlipperPlugin());
        }
    }
}
Also used : FlipperOkhttpInterceptor(com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor) AndroidFlipperClient(com.facebook.flipper.android.AndroidFlipperClient) FlipperClient(com.facebook.flipper.core.FlipperClient) OkHttpClient(okhttp3.OkHttpClient) ReactInstanceManager(com.facebook.react.ReactInstanceManager) InspectorFlipperPlugin(com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin) ReactFlipperPlugin(com.facebook.flipper.plugins.react.ReactFlipperPlugin) DatabasesFlipperPlugin(com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin) ReactContext(com.facebook.react.bridge.ReactContext) FrescoFlipperPlugin(com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin) NetworkFlipperPlugin(com.facebook.flipper.plugins.network.NetworkFlipperPlugin) SharedPreferencesFlipperPlugin(com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin) NetworkingModule(com.facebook.react.modules.network.NetworkingModule)

Aggregations

ReactInstanceManager (com.facebook.react.ReactInstanceManager)23 ReactContext (com.facebook.react.bridge.ReactContext)19 AndroidFlipperClient (com.facebook.flipper.android.AndroidFlipperClient)11 FlipperClient (com.facebook.flipper.core.FlipperClient)11 DatabasesFlipperPlugin (com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin)11 FrescoFlipperPlugin (com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin)11 InspectorFlipperPlugin (com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin)11 FlipperOkhttpInterceptor (com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor)11 NetworkFlipperPlugin (com.facebook.flipper.plugins.network.NetworkFlipperPlugin)11 ReactFlipperPlugin (com.facebook.flipper.plugins.react.ReactFlipperPlugin)11 SharedPreferencesFlipperPlugin (com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin)11 NetworkingModule (com.facebook.react.modules.network.NetworkingModule)11 OkHttpClient (okhttp3.OkHttpClient)11 Handler (android.os.Handler)7 ReactApplication (com.facebook.react.ReactApplication)6 ReactApplicationContext (com.facebook.react.bridge.ReactApplicationContext)5 Intent (android.content.Intent)4 Bundle (android.os.Bundle)3 EventEmitter (com.reactnativenavigation.react.events.EventEmitter)2 ChildControllersRegistry (com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry)2