Search in sources :

Example 1 with NetworkFlipperPlugin

use of com.facebook.flipper.plugins.network.NetworkFlipperPlugin 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 2 with NetworkFlipperPlugin

use of com.facebook.flipper.plugins.network.NetworkFlipperPlugin 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 3 with NetworkFlipperPlugin

use of com.facebook.flipper.plugins.network.NetworkFlipperPlugin 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 4 with NetworkFlipperPlugin

use of com.facebook.flipper.plugins.network.NetworkFlipperPlugin 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)

Aggregations

AndroidFlipperClient (com.facebook.flipper.android.AndroidFlipperClient)4 FlipperClient (com.facebook.flipper.core.FlipperClient)4 DatabasesFlipperPlugin (com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin)4 FrescoFlipperPlugin (com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin)4 InspectorFlipperPlugin (com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin)4 FlipperOkhttpInterceptor (com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor)4 NetworkFlipperPlugin (com.facebook.flipper.plugins.network.NetworkFlipperPlugin)4 ReactFlipperPlugin (com.facebook.flipper.plugins.react.ReactFlipperPlugin)4 SharedPreferencesFlipperPlugin (com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin)4 ReactInstanceManager (com.facebook.react.ReactInstanceManager)4 ReactContext (com.facebook.react.bridge.ReactContext)4 NetworkingModule (com.facebook.react.modules.network.NetworkingModule)4 OkHttpClient (okhttp3.OkHttpClient)4