From b4d1fcfb2f15d39aaab606d99dce7be37ac47032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Wed, 12 Feb 2020 18:25:42 -0800 Subject: [PATCH] Smoothen Flipper iOS integration (#28044) Summary: Addresses my feedback [here](https://github.com/facebook/react-native/issues/27565#issuecomment-580950480), [here](https://github.com/facebook/react-native/issues/27565#issuecomment-582490074), and [here](https://github.com/facebook/react-native/issues/27565#issuecomment-585456768). ## Changelog [iOS] [Changed] - Updated Flipper iOS integration to be included by default in the `Debug` configuration Pull Request resolved: https://github.com/facebook/react-native/pull/28044 Test Plan: Manually tested that a new application from this template still works and that the Flipper integration works. Screenshot 2020-02-13 at 02 09 42 Differential Revision: D19871482 Pulled By: TheSavior fbshipit-source-id: a805808fdd0c2dfdfe47dd59ffee02c81f3fdfa7 --- scripts/autolink-ios.rb | 20 +++++++++- .../ios/HelloWorld.xcodeproj/project.pbxproj | 5 +++ template/ios/HelloWorld/AppDelegate.m | 32 +++++++-------- template/ios/Podfile | 39 ++++++------------- 4 files changed, 50 insertions(+), 46 deletions(-) diff --git a/scripts/autolink-ios.rb b/scripts/autolink-ios.rb index 13e7a377aa9473..b941b6764b9526 100644 --- a/scripts/autolink-ios.rb +++ b/scripts/autolink-ios.rb @@ -4,7 +4,6 @@ # LICENSE file in the root directory of this source tree. def use_react_native! (options={}) - # The prefix to the react-native prefix = options[:path] ||= "../node_modules/react-native" @@ -56,5 +55,24 @@ def use_react_native! (options={}) pod 'React-RCTFabric', :path => "#{prefix}/React" pod 'Folly/Fabric', :podspec => "#{prefix}/third-party-podspecs/Folly.podspec" end +end +def add_flipper_pods! + version = '~> 0.30.0' + pod 'FlipperKit', version, :configuration => 'Debug' + pod 'FlipperKit/FlipperKitLayoutPlugin', version, :configuration => 'Debug' + pod 'FlipperKit/SKIOSNetworkPlugin', version, :configuration => 'Debug' + pod 'FlipperKit/FlipperKitUserDefaultsPlugin', version, :configuration => 'Debug' + pod 'FlipperKit/FlipperKitReactPlugin', 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 +end \ No newline at end of file diff --git a/template/ios/HelloWorld.xcodeproj/project.pbxproj b/template/ios/HelloWorld.xcodeproj/project.pbxproj index 1da27c4b29860f..6177361c401b66 100644 --- a/template/ios/HelloWorld.xcodeproj/project.pbxproj +++ b/template/ios/HelloWorld.xcodeproj/project.pbxproj @@ -495,6 +495,11 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = 1; + ENABLE_BITCODE = NO; + GCC_PREPROCESSOR_DEFINITIONS = ( + "$(inherited)", + "FB_SONARKIT_ENABLED=1", + ); INFOPLIST_FILE = HelloWorld/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; OTHER_LDFLAGS = ( diff --git a/template/ios/HelloWorld/AppDelegate.m b/template/ios/HelloWorld/AppDelegate.m index da94b0023fb3dd..c680572d44cce3 100644 --- a/template/ios/HelloWorld/AppDelegate.m +++ b/template/ios/HelloWorld/AppDelegate.m @@ -5,21 +5,32 @@ #import #if DEBUG -#ifdef FB_SONARKIT_ENABLED #import #import #import #import #import #import -#endif + +static void InitializeFlipper(UIApplication *application) { + FlipperClient *client = [FlipperClient sharedClient]; + SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults]; + [client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]]; + [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; + [client addPlugin:[FlipperKitReactPlugin new]]; + [client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]]; + [client start]; +} #endif @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - [AppDelegate initializeFlipper:application]; +#if DEBUG + InitializeFlipper(application); +#endif + RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"HelloWorld" @@ -44,19 +55,4 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge #endif } -+ (void) initializeFlipper:(UIApplication *)application -{ -#if DEBUG -#ifdef FB_SONARKIT_ENABLED - FlipperClient *client = [FlipperClient sharedClient]; - SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults]; - [client addPlugin: [[FlipperKitLayoutPlugin alloc] initWithRootNode: application withDescriptorMapper: layoutDescriptorMapper]]; - [client addPlugin: [[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; - [client addPlugin: [FlipperKitReactPlugin new]]; - [client addPlugin: [[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]]; - [client start]; -#endif -#endif -} - @end diff --git a/template/ios/Podfile b/template/ios/Podfile index 11b121d6a5ae9b..f74c8a614ad171 100644 --- a/template/ios/Podfile +++ b/template/ios/Podfile @@ -1,14 +1,13 @@ platform :ios, '9.0' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' -# Add Flipper Pods -def flipper_pods() - flipperkit_version = '0.30.0' - 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' - pod 'FlipperKit/FlipperKitReactPlugin', '~>' + flipperkit_version, :configuration => 'Debug' +def add_flipper_pods! + version = '~> 0.30.2' + pod 'FlipperKit', version, :configuration => 'Debug' + pod 'FlipperKit/FlipperKitLayoutPlugin', version, :configuration => 'Debug' + pod 'FlipperKit/SKIOSNetworkPlugin', version, :configuration => 'Debug' + pod 'FlipperKit/FlipperKitUserDefaultsPlugin', version, :configuration => 'Debug' + pod 'FlipperKit/FlipperKitReactPlugin', version, :configuration => 'Debug' end # Post Install processing for Flipper @@ -20,23 +19,8 @@ def flipper_post_install(installer) 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" @@ -77,10 +61,11 @@ target 'HelloWorld' do use_native_modules! - # For enabling Flipper. - # Note that if you have use_frameworks!, flipper will not work. - # Disable these lines if you are using use_frameworks! - flipper_pods() + # Enables Flipper. + # + # Note that if you have use_frameworks! enabled, Flipper will not work and + # you should disable these next few lines. + add_flipper_pods! post_install do |installer| flipper_post_install(installer) end