Skip to content

Commit

Permalink
Enable Flipper on RNTester (iOS)
Browse files Browse the repository at this point in the history
Summary:
By enabling Flipper on RNTester, we can ensure that Flipper continues to work with ReactNative.
Note that Flipper is disabled when RNTester is built with `USE_FRAMEWORKS=1 pod install`

Reviewed By: PeteTheHeat

Differential Revision: D6976784

fbshipit-source-id: 4e16a47949d7ed6400e0b8ccd640be0754203c69
  • Loading branch information
axe-fb authored and facebook-github-bot committed Sep 5, 2019
1 parent 0cc4306 commit 0a5c43f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
40 changes: 40 additions & 0 deletions RNTester/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,40 @@ if ENV['USE_FRAMEWORKS'] == '1'
use_frameworks!
end

# 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

def pods()
project 'RNTesterPods.xcodeproj'

Expand All @@ -26,6 +60,9 @@ end

target 'RNTester' do
pods()
if ENV['USE_FRAMEWORKS'] != '1'
flipper_pods()
end
end

target 'RNTesterUnitTests' do
Expand All @@ -39,6 +76,9 @@ target 'RNTesterIntegrationTests' do
end

post_install do |installer|
if ENV['USE_FRAMEWORKS'] != '1'
flipper_post_install(installer)
end
installer.pods_project.targets.each do |target|
puts target.name
end
Expand Down
27 changes: 27 additions & 0 deletions RNTester/RNTester/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@

#import <ReactCommon/RCTTurboModuleManager.h>

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

#import "RNTesterTurboModuleProvider.h"

@interface AppDelegate() <RCTCxxBridgeDelegate, RCTTurboModuleManagerDelegate>{
Expand All @@ -45,6 +55,7 @@ @implementation AppDelegate

- (BOOL)application:(__unused UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[AppDelegate initializeFlipper:application];
RCTEnableTurboModule(YES);

_bridge = [[RCTBridge alloc] initWithDelegate:self
Expand Down Expand Up @@ -181,6 +192,22 @@ - (void)application:(__unused UIApplication *)application didReceiveLocalNotific
[RCTPushNotificationManager didReceiveLocalNotification:notification];
}


+ (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 start];
[client addPlugin: [[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
[client start];
#endif
#endif
}

#endif

@end

0 comments on commit 0a5c43f

Please sign in to comment.