From 70274f4e9166dbe9da2d04953a95c2909b455d1d Mon Sep 17 00:00:00 2001 From: Ram N Date: Tue, 3 Sep 2019 16:19:55 -0700 Subject: [PATCH] Add code to enable Flipper in React Native iOS Template Reviewed By: rickhanlonii Differential Revision: D6997542 fbshipit-source-id: c8f7280b52febabb0a987df5dffadf957dadd1fb --- template/ios/HelloWorld/AppDelegate.m | 20 ++++++++++++ template/ios/Podfile | 46 +++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/template/ios/HelloWorld/AppDelegate.m b/template/ios/HelloWorld/AppDelegate.m index 101fb8c324c..10b744eb01f 100644 --- a/template/ios/HelloWorld/AppDelegate.m +++ b/template/ios/HelloWorld/AppDelegate.m @@ -11,6 +11,14 @@ #import #import +#if DEBUG +#import +#import +#import +#import +#import +#endif + @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions @@ -39,4 +47,16 @@ #endif } ++ (void) initializeFlipper:(UIApplication *)application +{ +#if DEBUG + FlipperClient *client = [FlipperClient sharedClient]; + SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults]; + [client addPlugin: [[FlipperKitLayoutPlugin alloc] initWithRootNode: application withDescriptorMapper: layoutDescriptorMapper]]; + [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; [client start]; + [client addPlugin: [[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]]; + [client start]; +#endif +} + @end diff --git a/template/ios/Podfile b/template/ios/Podfile index 7706b8362a6..b8cf621ad11 100644 --- a/template/ios/Podfile +++ b/template/ios/Podfile @@ -1,6 +1,41 @@ platform :ios, '9.0' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' +# Add Flipper Poods +def flipper_pods() + flipperkit_version = '0.23.4' + pod 'FlipperKit', '~>' + flipperkit_version, :configuration => 'Debug' + pod 'FlipperKit/FlipperKitLayoutPlugin', '~>' + flipperkit_version, :configuration => 'Debug' + pod 'FlipperKit/SKIOSNetworkPlugin', '~>' + flipperkit_version, :configuration => 'Debug' + pod 'FlipperKit/FlipperKitUserDefaultsPlugin', '~>' + flipperkit_version, :configuration => 'Debug' +end + +# Post Install processing for Flipper +def flipper_post_install(installer) + installer.pods_project.targets.each do |target| + if target.name == 'YogaKit' + target.build_configurations.each do |config| + config.build_settings['SWIFT_VERSION'] = '4.1' + end + end + end + file_name = Dir.glob("*.xcodeproj")[0] + app_project = Xcodeproj::Project.open(file_name) + app_project.native_targets.each do |target| + target.build_configurations.each do |config| + cflags = config.build_settings['OTHER_CFLAGS'] || '$(inherited) ' + unless cflags.include? '-DFB_SONARKIT_ENABLED=1' + puts 'Adding -DFB_SONARKIT_ENABLED=1 in OTHER_CFLAGS...' + cflags << '-DFB_SONARKIT_ENABLED=1' + end + config.build_settings['OTHER_CFLAGS'] = cflags + end + app_project.save + end + installer.pods_project.save +end + + target 'HelloWorld' do # Pods for HelloWorld pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector" @@ -35,11 +70,19 @@ target 'HelloWorld' do pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec' target 'HelloWorldTests' do - inherit! :search_paths + inherit! :complete # Pods for testing end use_native_modules! + + # For enabling Flipper. + # Note that if you use_framework!, flipper will no work. + # Disable these lines if you are doing use_framework! + flipper_pods() + post_install do |installer| + flipper_post_install(installer) + end end target 'HelloWorld-tvOS' do @@ -49,5 +92,4 @@ target 'HelloWorld-tvOS' do inherit! :search_paths # Pods for testing end - end