1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * <p>This source code is licensed under the MIT license found in the LICENSE file in the root
5
+ * directory of this source tree.
6
+ */
7
+ package com .<%= project .name %>Example ;
8
+
9
+ import android .content .Context ;
10
+ import com .facebook .flipper .android .AndroidFlipperClient ;
11
+ import com .facebook .flipper .android .utils .FlipperUtils ;
12
+ import com .facebook .flipper .core .FlipperClient ;
13
+ import com .facebook .flipper .plugins .crashreporter .CrashReporterPlugin ;
14
+ import com .facebook .flipper .plugins .databases .DatabasesFlipperPlugin ;
15
+ import com .facebook .flipper .plugins .fresco .FrescoFlipperPlugin ;
16
+ import com .facebook .flipper .plugins .inspector .DescriptorMapping ;
17
+ import com .facebook .flipper .plugins .inspector .InspectorFlipperPlugin ;
18
+ import com .facebook .flipper .plugins .network .FlipperOkhttpInterceptor ;
19
+ import com .facebook .flipper .plugins .network .NetworkFlipperPlugin ;
20
+ import com .facebook .flipper .plugins .react .ReactFlipperPlugin ;
21
+ import com .facebook .flipper .plugins .sharedpreferences .SharedPreferencesFlipperPlugin ;
22
+ import com .facebook .react .ReactInstanceManager ;
23
+ import com .facebook .react .bridge .ReactContext ;
24
+ import com .facebook .react .modules .network .NetworkingModule ;
25
+ import okhttp3 .OkHttpClient ;
26
+
27
+ public class ReactNativeFlipper {
28
+ public static void initializeFlipper (Context context , ReactInstanceManager reactInstanceManager ) {
29
+ if (FlipperUtils .shouldEnableFlipper (context )) {
30
+ final FlipperClient client = AndroidFlipperClient .getInstance (context );
31
+ client .addPlugin (new InspectorFlipperPlugin (context , DescriptorMapping .withDefaults ()));
32
+ client .addPlugin (new ReactFlipperPlugin ());
33
+ client .addPlugin (new DatabasesFlipperPlugin (context ));
34
+ client .addPlugin (new SharedPreferencesFlipperPlugin (context ));
35
+ client .addPlugin (CrashReporterPlugin .getInstance ());
36
+ NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin ();
37
+ NetworkingModule .setCustomClientBuilder (
38
+ new NetworkingModule .CustomClientBuilder () {
39
+ @ Override
40
+ public void apply (OkHttpClient .Builder builder ) {
41
+ builder .addNetworkInterceptor (new FlipperOkhttpInterceptor (networkFlipperPlugin ));
42
+ }
43
+ });
44
+ client .addPlugin (networkFlipperPlugin );
45
+ client .start ();
46
+ // Fresco Plugin needs to ensure that ImagePipelineFactory is initialized
47
+ // Hence we run if after all native modules have been initialized
48
+ ReactContext reactContext = reactInstanceManager .getCurrentReactContext ();
49
+ if (reactContext == null ) {
50
+ reactInstanceManager .addReactInstanceEventListener (
51
+ new ReactInstanceManager .ReactInstanceEventListener () {
52
+ @ Override
53
+ public void onReactContextInitialized (ReactContext reactContext ) {
54
+ reactInstanceManager .removeReactInstanceEventListener (this );
55
+ reactContext .runOnNativeModulesQueueThread (
56
+ new Runnable () {
57
+ @ Override
58
+ public void run () {
59
+ client .addPlugin (new FrescoFlipperPlugin ());
60
+ }
61
+ });
62
+ }
63
+ });
64
+ } else {
65
+ client .addPlugin (new FrescoFlipperPlugin ());
66
+ }
67
+ }
68
+ }
69
+ }
0 commit comments