Skip to content

Commit 70274f4

Browse files
axe-fbfacebook-github-bot
authored andcommitted
Add code to enable Flipper in React Native iOS Template
Reviewed By: rickhanlonii Differential Revision: D6997542 fbshipit-source-id: c8f7280b52febabb0a987df5dffadf957dadd1fb
1 parent 755ad3b commit 70274f4

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

template/ios/HelloWorld/AppDelegate.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
#import <React/RCTBundleURLProvider.h>
1212
#import <React/RCTRootView.h>
1313

14+
#if DEBUG
15+
#import <FlipperKit/FlipperClient.h>
16+
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
17+
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
18+
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
19+
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
20+
#endif
21+
1422
@implementation AppDelegate
1523

1624
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
@@ -39,4 +47,16 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
3947
#endif
4048
}
4149

50+
+ (void) initializeFlipper:(UIApplication *)application
51+
{
52+
#if DEBUG
53+
FlipperClient *client = [FlipperClient sharedClient];
54+
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
55+
[client addPlugin: [[FlipperKitLayoutPlugin alloc] initWithRootNode: application withDescriptorMapper: layoutDescriptorMapper]];
56+
[client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; [client start];
57+
[client addPlugin: [[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
58+
[client start];
59+
#endif
60+
}
61+
4262
@end

template/ios/Podfile

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,41 @@
11
platform :ios, '9.0'
22
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
33

4+
# Add Flipper Poods
5+
def flipper_pods()
6+
flipperkit_version = '0.23.4'
7+
pod 'FlipperKit', '~>' + flipperkit_version, :configuration => 'Debug'
8+
pod 'FlipperKit/FlipperKitLayoutPlugin', '~>' + flipperkit_version, :configuration => 'Debug'
9+
pod 'FlipperKit/SKIOSNetworkPlugin', '~>' + flipperkit_version, :configuration => 'Debug'
10+
pod 'FlipperKit/FlipperKitUserDefaultsPlugin', '~>' + flipperkit_version, :configuration => 'Debug'
11+
end
12+
13+
# Post Install processing for Flipper
14+
def flipper_post_install(installer)
15+
installer.pods_project.targets.each do |target|
16+
if target.name == 'YogaKit'
17+
target.build_configurations.each do |config|
18+
config.build_settings['SWIFT_VERSION'] = '4.1'
19+
end
20+
end
21+
end
22+
file_name = Dir.glob("*.xcodeproj")[0]
23+
app_project = Xcodeproj::Project.open(file_name)
24+
app_project.native_targets.each do |target|
25+
target.build_configurations.each do |config|
26+
cflags = config.build_settings['OTHER_CFLAGS'] || '$(inherited) '
27+
unless cflags.include? '-DFB_SONARKIT_ENABLED=1'
28+
puts 'Adding -DFB_SONARKIT_ENABLED=1 in OTHER_CFLAGS...'
29+
cflags << '-DFB_SONARKIT_ENABLED=1'
30+
end
31+
config.build_settings['OTHER_CFLAGS'] = cflags
32+
end
33+
app_project.save
34+
end
35+
installer.pods_project.save
36+
end
37+
38+
439
target 'HelloWorld' do
540
# Pods for HelloWorld
641
pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
@@ -35,11 +70,19 @@ target 'HelloWorld' do
3570
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
3671

3772
target 'HelloWorldTests' do
38-
inherit! :search_paths
73+
inherit! :complete
3974
# Pods for testing
4075
end
4176

4277
use_native_modules!
78+
79+
# For enabling Flipper.
80+
# Note that if you use_framework!, flipper will no work.
81+
# Disable these lines if you are doing use_framework!
82+
flipper_pods()
83+
post_install do |installer|
84+
flipper_post_install(installer)
85+
end
4386
end
4487

4588
target 'HelloWorld-tvOS' do
@@ -49,5 +92,4 @@ target 'HelloWorld-tvOS' do
4992
inherit! :search_paths
5093
# Pods for testing
5194
end
52-
5395
end

0 commit comments

Comments
 (0)