Skip to content

Commit

Permalink
Add code to enable Flipper in React Native iOS Template
Browse files Browse the repository at this point in the history
Reviewed By: rickhanlonii

Differential Revision: D6997542

fbshipit-source-id: c8f7280b52febabb0a987df5dffadf957dadd1fb
  • Loading branch information
axe-fb authored and facebook-github-bot committed Sep 3, 2019
1 parent 755ad3b commit 70274f4
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
20 changes: 20 additions & 0 deletions template/ios/HelloWorld/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>

#if DEBUG
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#endif

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Expand Down Expand Up @@ -39,4 +47,16 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
#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
46 changes: 44 additions & 2 deletions template/ios/Podfile
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -49,5 +92,4 @@ target 'HelloWorld-tvOS' do
inherit! :search_paths
# Pods for testing
end

end

0 comments on commit 70274f4

Please sign in to comment.