Skip to content

Commit e526da5

Browse files
committed
Added Flipper
1 parent 34f29b7 commit e526da5

File tree

7 files changed

+265
-20
lines changed

7 files changed

+265
-20
lines changed

android/app/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ dependencies {
218218
implementation 'com.amazonaws:aws-android-sdk-ddb-mapper:2.2.+'
219219
implementation 'com.amazonaws:aws-android-sdk-cognito:2.2.+'
220220
implementation 'com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.2.+'
221+
222+
debugImplementation("com.facebook.flipper:flipper:+") {
223+
exclude group:'com.facebook.yoga'
224+
exclude group:'com.facebook.flipper', module: 'fbjni'
225+
exclude group:'com.facebook.litho', module: 'litho-annotations'
226+
}
221227
}
222228

223229
// Run this once to be able to run the application with BUCK
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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.chainreactapp;
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+
32+
client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults()));
33+
client.addPlugin(new ReactFlipperPlugin());
34+
client.addPlugin(new DatabasesFlipperPlugin(context));
35+
client.addPlugin(new SharedPreferencesFlipperPlugin(context));
36+
client.addPlugin(CrashReporterPlugin.getInstance());
37+
38+
NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin();
39+
NetworkingModule.setCustomClientBuilder(
40+
new NetworkingModule.CustomClientBuilder() {
41+
@Override
42+
public void apply(OkHttpClient.Builder builder) {
43+
builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin));
44+
}
45+
});
46+
client.addPlugin(networkFlipperPlugin);
47+
client.start();
48+
49+
// Fresco Plugin needs to ensure that ImagePipelineFactory is initialized
50+
// Hence we run if after all native modules have been initialized
51+
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
52+
if (reactContext == null) {
53+
reactInstanceManager.addReactInstanceEventListener(
54+
new ReactInstanceManager.ReactInstanceEventListener() {
55+
@Override
56+
public void onReactContextInitialized(ReactContext reactContext) {
57+
reactInstanceManager.removeReactInstanceEventListener(this);
58+
reactContext.runOnNativeModulesQueueThread(
59+
new Runnable() {
60+
@Override
61+
public void run() {
62+
client.addPlugin(new FrescoFlipperPlugin());
63+
}
64+
});
65+
}
66+
});
67+
} else {
68+
client.addPlugin(new FrescoFlipperPlugin());
69+
}
70+
}
71+
}
72+
}

android/app/src/main/java/com/chainreactapp/MainApplication.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
import com.microsoft.appcenter.reactnative.crashes.AppCenterReactNativeCrashesPackage;
2525
import com.microsoft.appcenter.reactnative.analytics.AppCenterReactNativeAnalyticsPackage;
2626
import com.microsoft.appcenter.reactnative.appcenter.AppCenterReactNativePackage;
27+
import java.lang.reflect.InvocationTargetException;
28+
import android.content.Context;
29+
import com.facebook.react.ReactInstanceManager;
2730

2831
import java.util.Arrays;
2932
import java.util.List;
@@ -72,5 +75,36 @@ public ReactNativeHost getReactNativeHost() {
7275
public void onCreate() {
7376
super.onCreate();
7477
SoLoader.init(this, /* native exopackage */ false);
78+
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
79+
}
80+
81+
/**
82+
* Loads Flipper in React Native templates. Call this in the onCreate method with something like
83+
* initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
84+
*
85+
* @param context
86+
*/
87+
private static void initializeFlipper(
88+
Context context, ReactInstanceManager reactInstanceManager) {
89+
if (BuildConfig.DEBUG) {
90+
try {
91+
/*
92+
We use reflection here to pick up the class that initializes Flipper,
93+
since Flipper library is not available in release mode
94+
*/
95+
Class<?> aClass = Class.forName("com.chainreactapp.ReactNativeFlipper");
96+
aClass
97+
.getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
98+
.invoke(null, context, reactInstanceManager);
99+
} catch (ClassNotFoundException e) {
100+
e.printStackTrace();
101+
} catch (NoSuchMethodException e) {
102+
e.printStackTrace();
103+
} catch (IllegalAccessException e) {
104+
e.printStackTrace();
105+
} catch (InvocationTargetException e) {
106+
e.printStackTrace();
107+
}
108+
}
75109
}
76110
}

ios/ChainReactConf.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,10 @@
15841584
INFOPLIST_FILE = ChainReactConf/Info.plist;
15851585
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
15861586
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
1587+
OTHER_CFLAGS = (
1588+
"$(inherited)",
1589+
"-DFB_SONARKIT_ENABLED=1",
1590+
);
15871591
OTHER_LDFLAGS = (
15881592
"$(inherited)",
15891593
"-ObjC",
@@ -1633,6 +1637,10 @@
16331637
INFOPLIST_FILE = ChainReactConf/Info.plist;
16341638
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
16351639
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
1640+
OTHER_CFLAGS = (
1641+
"$(inherited)",
1642+
"-DFB_SONARKIT_ENABLED=1",
1643+
);
16361644
OTHER_LDFLAGS = (
16371645
"$(inherited)",
16381646
"-ObjC",

ios/ChainReactConf/AppDelegate.m

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,19 @@
1515
#import <AppCenterReactNativePush.h>
1616
#import "RNSplashScreen.h"
1717

18+
#if DEBUG
19+
#import <FlipperKit/FlipperClient.h>
20+
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
21+
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
22+
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
23+
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
24+
#endif
25+
1826
@implementation AppDelegate
1927

2028
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
2129
{
30+
[AppDelegate initializeFlipper:application];
2231
[AppCenterReactNativeAnalytics registerWithInitiallyEnabled:true]; // Initialize AppCenter analytics
2332
[AppCenterReactNativeCrashes registerWithAutomaticProcessing]; // Initialize AppCenter crashes
2433
[AppCenterReactNativePush register]; // Initialize AppCenter push
@@ -49,4 +58,17 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
4958
#endif
5059
}
5160

61+
+ (void) initializeFlipper:(UIApplication *)application
62+
{
63+
#if DEBUG
64+
FlipperClient *client = [FlipperClient sharedClient];
65+
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
66+
[client addPlugin: [[FlipperKitLayoutPlugin alloc] initWithRootNode: application withDescriptorMapper: layoutDescriptorMapper]];
67+
[client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; [client start];
68+
[client addPlugin: [[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
69+
[client start];
70+
#endif
71+
}
72+
73+
5274
@end

ios/Podfile

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,40 @@ platform :ios, '10.0'
44
install! 'cocoapods', deterministic_uuids: false
55
project 'ChainReactConf.xcodeworkspace'
66

7+
# Add Flipper Poods
8+
def flipper_pods()
9+
flipperkit_version = '0.23.4'
10+
pod 'FlipperKit', '~>' + flipperkit_version, :configuration => 'Debug'
11+
pod 'FlipperKit/FlipperKitLayoutPlugin', '~>' + flipperkit_version, :configuration => 'Debug'
12+
pod 'FlipperKit/SKIOSNetworkPlugin', '~>' + flipperkit_version, :configuration => 'Debug'
13+
pod 'FlipperKit/FlipperKitUserDefaultsPlugin', '~>' + flipperkit_version, :configuration => 'Debug'
14+
end
15+
16+
# Post Install processing for Flipper
17+
def flipper_post_install(installer)
18+
installer.pods_project.targets.each do |target|
19+
if target.name == 'YogaKit'
20+
target.build_configurations.each do |config|
21+
config.build_settings['SWIFT_VERSION'] = '4.1'
22+
end
23+
end
24+
end
25+
file_name = Dir.glob("*.xcodeproj")[0]
26+
app_project = Xcodeproj::Project.open(file_name)
27+
app_project.native_targets.each do |target|
28+
target.build_configurations.each do |config|
29+
cflags = config.build_settings['OTHER_CFLAGS'] || '$(inherited) '
30+
unless cflags.include? '-DFB_SONARKIT_ENABLED=1'
31+
puts 'Adding -DFB_SONARKIT_ENABLED=1 in OTHER_CFLAGS...'
32+
cflags << '-DFB_SONARKIT_ENABLED=1'
33+
end
34+
config.build_settings['OTHER_CFLAGS'] = cflags
35+
end
36+
app_project.save
37+
end
38+
installer.pods_project.save
39+
end
40+
741
target 'ChainReactConf' do
842
pod 'React', path: '../node_modules/react-native/'
943
pod 'React-Core', path: '../node_modules/react-native/React'
@@ -23,7 +57,7 @@ target 'ChainReactConf' do
2357
pod 'React-jsi', path: '../node_modules/react-native/ReactCommon/jsi'
2458
pod 'React-jsiexecutor', path: '../node_modules/react-native/ReactCommon/jsiexecutor'
2559
pod 'React-jsinspector', path: '../node_modules/react-native/ReactCommon/jsinspector'
26-
pod 'yoga', path: '../node_modules/react-native/ReactCommon/yoga'
60+
pod 'Yoga', path: '../node_modules/react-native/ReactCommon/yoga'
2761
pod 'DoubleConversion', podspec: '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
2862
pod 'glog', podspec: '../node_modules/react-native/third-party-podspecs/glog.podspec'
2963
pod 'Folly', podspec: '../node_modules/react-native/third-party-podspecs/Folly.podspec'
@@ -37,14 +71,15 @@ target 'ChainReactConf' do
3771
pod 'RNGestureHandler', path: '../node_modules/react-native-gesture-handler'
3872
pod 'RNScreens', path: '../node_modules/react-native-screens'
3973
pod 'RNDeviceInfo', path: '../node_modules/react-native-device-info'
40-
74+
flipper_pods()
4175
# use_native_modules!
4276

4377
post_install do |installer|
78+
flipper_post_install(installer)
4479
installer.pods_project.targets.each do |target|
4580
if target.name == "React"
4681
target.remove_from_project
4782
end
4883
end
4984
end
50-
end
85+
end

0 commit comments

Comments
 (0)