Skip to content

Commit 619d5d6

Browse files
alloyfacebook-github-bot
authored andcommitted
Smoothen Flipper iOS integration (#28044)
Summary: Addresses my feedback [here](#27565 (comment)), [here](#27565 (comment)), and [here](#27565 (comment)). ## Changelog [iOS] [Changed] - Updated Flipper iOS integration to be included by default in the `Debug` configuration Pull Request resolved: #28044 Test Plan: Manually tested that a new application from this template still works and that the Flipper integration works. <img width="912" alt="Screenshot 2020-02-13 at 02 09 42" src="https://user-images.githubusercontent.com/2320/74391951-eb6fd800-4e05-11ea-9fde-7e0eb42c1ec4.png"> Differential Revision: D19871482 Pulled By: TheSavior fbshipit-source-id: a805808fdd0c2dfdfe47dd59ffee02c81f3fdfa7
1 parent 9b7958c commit 619d5d6

File tree

4 files changed

+43
-59
lines changed

4 files changed

+43
-59
lines changed

scripts/autolink-ios.rb

+19-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# LICENSE file in the root directory of this source tree.
55

66
def use_react_native! (options={})
7-
87
# The prefix to the react-native
98
prefix = options[:path] ||= "../node_modules/react-native"
109

@@ -56,5 +55,24 @@ def use_react_native! (options={})
5655
pod 'React-RCTFabric', :path => "#{prefix}/React"
5756
pod 'Folly/Fabric', :podspec => "#{prefix}/third-party-podspecs/Folly.podspec"
5857
end
58+
end
5959

60+
def add_flipper_pods!
61+
version = '~> 0.30.0'
62+
pod 'FlipperKit', version, :configuration => 'Debug'
63+
pod 'FlipperKit/FlipperKitLayoutPlugin', version, :configuration => 'Debug'
64+
pod 'FlipperKit/SKIOSNetworkPlugin', version, :configuration => 'Debug'
65+
pod 'FlipperKit/FlipperKitUserDefaultsPlugin', version, :configuration => 'Debug'
66+
pod 'FlipperKit/FlipperKitReactPlugin', version, :configuration => 'Debug'
6067
end
68+
69+
# Post Install processing for Flipper
70+
def flipper_post_install(installer)
71+
installer.pods_project.targets.each do |target|
72+
if target.name == 'YogaKit'
73+
target.build_configurations.each do |config|
74+
config.build_settings['SWIFT_VERSION'] = '4.1'
75+
end
76+
end
77+
end
78+
end

template/ios/HelloWorld.xcodeproj/project.pbxproj

+5
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,11 @@
495495
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
496496
CLANG_ENABLE_MODULES = YES;
497497
CURRENT_PROJECT_VERSION = 1;
498+
ENABLE_BITCODE = NO;
499+
GCC_PREPROCESSOR_DEFINITIONS = (
500+
"$(inherited)",
501+
"FB_SONARKIT_ENABLED=1",
502+
);
498503
INFOPLIST_FILE = HelloWorld/Info.plist;
499504
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
500505
OTHER_LDFLAGS = (

template/ios/HelloWorld/AppDelegate.m

+14-18
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,32 @@
55
#import <React/RCTRootView.h>
66

77
#if DEBUG
8-
#ifdef FB_SONARKIT_ENABLED
98
#import <FlipperKit/FlipperClient.h>
109
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
1110
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
1211
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
1312
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
1413
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
15-
#endif
14+
15+
static void InitializeFlipper(UIApplication *application) {
16+
FlipperClient *client = [FlipperClient sharedClient];
17+
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
18+
[client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]];
19+
[client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
20+
[client addPlugin:[FlipperKitReactPlugin new]];
21+
[client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
22+
[client start];
23+
}
1624
#endif
1725

1826
@implementation AppDelegate
1927

2028
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
2129
{
22-
[AppDelegate initializeFlipper:application];
30+
#if DEBUG
31+
InitializeFlipper(application);
32+
#endif
33+
2334
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
2435
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
2536
moduleName:@"HelloWorld"
@@ -44,19 +55,4 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
4455
#endif
4556
}
4657

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

template/ios/Podfile

+5-40
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,6 @@ platform :ios, '10.0'
22
require_relative '../node_modules/react-native/scripts/autolink-ios'
33
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
44

5-
# Add Flipper Pods
6-
def flipper_pods()
7-
flipperkit_version = '0.30.0'
8-
pod 'FlipperKit', '~>' + flipperkit_version, :configuration => 'Debug'
9-
pod 'FlipperKit/FlipperKitLayoutPlugin', '~>' + flipperkit_version, :configuration => 'Debug'
10-
pod 'FlipperKit/SKIOSNetworkPlugin', '~>' + flipperkit_version, :configuration => 'Debug'
11-
pod 'FlipperKit/FlipperKitUserDefaultsPlugin', '~>' + flipperkit_version, :configuration => 'Debug'
12-
pod 'FlipperKit/FlipperKitReactPlugin', '~>' + flipperkit_version, :configuration => 'Debug'
13-
end
14-
15-
# Post Install processing for Flipper
16-
def flipper_post_install(installer)
17-
installer.pods_project.targets.each do |target|
18-
if target.name == 'YogaKit'
19-
target.build_configurations.each do |config|
20-
config.build_settings['SWIFT_VERSION'] = '4.1'
21-
end
22-
end
23-
end
24-
file_name = Dir.glob("*.xcodeproj")[0]
25-
app_project = Xcodeproj::Project.open(file_name)
26-
app_project.native_targets.each do |target|
27-
target.build_configurations.each do |config|
28-
cflags = config.build_settings['OTHER_CFLAGS'] || '$(inherited) '
29-
unless cflags.include? '-DFB_SONARKIT_ENABLED=1'
30-
puts 'Adding -DFB_SONARKIT_ENABLED=1 in OTHER_CFLAGS...'
31-
cflags << '-DFB_SONARKIT_ENABLED=1'
32-
end
33-
config.build_settings['OTHER_CFLAGS'] = cflags
34-
end
35-
app_project.save
36-
end
37-
installer.pods_project.save
38-
end
39-
40-
415
target 'HelloWorld' do
426
# Pods for HelloWorld
437
use_react_native!
@@ -49,10 +13,11 @@ target 'HelloWorld' do
4913

5014
use_native_modules!
5115

52-
# For enabling Flipper.
53-
# Note that if you have use_frameworks!, flipper will not work.
54-
# Disable these lines if you are using use_frameworks!
55-
flipper_pods()
16+
# Enables Flipper.
17+
#
18+
# Note that if you have use_frameworks! enabled, Flipper will not work and
19+
# you should disable these next few lines.
20+
add_flipper_pods!
5621
post_install do |installer|
5722
flipper_post_install(installer)
5823
end

0 commit comments

Comments
 (0)