Search in sources :

Example 6 with ReactInstanceManager

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

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)

Example 7 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, 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)

Example 8 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, 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)

Example 9 with ReactInstanceManager

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

the class ExternalComponentViewControllerTest method beforeEach.

@Override
public void beforeEach() {
    componentCreator = spy(new FragmentCreatorMock());
    activity = newActivity();
    ec = createExternalComponent();
    reactInstanceManager = Mockito.mock(ReactInstanceManager.class);
    emitter = Mockito.mock(EventEmitter.class);
    childRegistry = new ChildControllersRegistry();
    uut = spy(new ExternalComponentViewController(activity, childRegistry, "fragmentId", new Presenter(activity, Options.EMPTY), ec, componentCreator, reactInstanceManager, emitter, new ExternalComponentPresenter(), new Options()));
}
Also used : Options(com.reactnativenavigation.options.Options) ReactInstanceManager(com.facebook.react.ReactInstanceManager) EventEmitter(com.reactnativenavigation.react.events.EventEmitter) Presenter(com.reactnativenavigation.viewcontrollers.viewcontroller.Presenter) ChildControllersRegistry(com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry)

Example 10 with ReactInstanceManager

use of com.facebook.react.ReactInstanceManager in project react-native-push-notification by zo0r.

the class RNPushNotificationListenerService method onMessageReceived.

@Override
public void onMessageReceived(String from, final Bundle bundle) {
    JSONObject data = getPushData(bundle.getString("data"));
    if (data != null) {
        if (!bundle.containsKey("message")) {
            bundle.putString("message", data.optString("alert", "Notification received"));
        }
        if (!bundle.containsKey("title")) {
            bundle.putString("title", data.optString("title", null));
        }
        if (!bundle.containsKey("sound")) {
            bundle.putString("soundName", data.optString("sound", null));
        }
        if (!bundle.containsKey("color")) {
            bundle.putString("color", data.optString("color", null));
        }
        final int badge = data.optInt("badge", -1);
        if (badge >= 0) {
            ApplicationBadgeHelper.INSTANCE.setApplicationIconBadgeNumber(this, badge);
        }
    }
    Log.v(LOG_TAG, "onMessageReceived: " + bundle);
    // 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) {
                handleRemotePushNotification((ReactApplicationContext) context, bundle);
            } else {
                // Otherwise wait for construction, then send the notification
                mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {

                    public void onReactContextInitialized(ReactContext context) {
                        handleRemotePushNotification((ReactApplicationContext) context, bundle);
                    }
                });
                if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
                    // Construct it in the background
                    mReactInstanceManager.createReactContextInBackground();
                }
            }
        }
    });
}
Also used : JSONObject(org.json.JSONObject) ReactInstanceManager(com.facebook.react.ReactInstanceManager) ReactContext(com.facebook.react.bridge.ReactContext) Handler(android.os.Handler) ReactApplication(com.facebook.react.ReactApplication) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext)

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