diff --git a/iOS/FlipperKit/CppBridge/FlipperCppBridgingConnection.mm b/iOS/FlipperKit/CppBridge/FlipperCppBridgingConnection.mm index 3d74237e5..817c097a4 100644 --- a/iOS/FlipperKit/CppBridge/FlipperCppBridgingConnection.mm +++ b/iOS/FlipperKit/CppBridge/FlipperCppBridgingConnection.mm @@ -44,4 +44,9 @@ conn_->receive([method UTF8String], lambda); } +- (void)errorWithMessage:(NSString *)message stackTrace:(NSString *)stacktrace { + conn_->error([message UTF8String], [stacktrace UTF8String]); +} + + @end diff --git a/iOS/FlipperKit/FlipperConnection.h b/iOS/FlipperKit/FlipperConnection.h index b2fb798f3..b7489776e 100644 --- a/iOS/FlipperKit/FlipperConnection.h +++ b/iOS/FlipperKit/FlipperConnection.h @@ -28,4 +28,9 @@ plugin with a matching identifier. */ - (void)receive:(NSString *)method withBlock:(SonarReceiver)receiver; +/** +Report an error to the Flipper desktop app +*/ +- (void)errorWithMessage:(NSString *)message stackTrace:(NSString *)stacktrace; + @end diff --git a/iOS/FlipperKitTestUtils/FlipperConnectionMock.m b/iOS/FlipperKitTestUtils/FlipperConnectionMock.m index 39b7bbcf5..392cecc75 100644 --- a/iOS/FlipperKitTestUtils/FlipperConnectionMock.m +++ b/iOS/FlipperKitTestUtils/FlipperConnectionMock.m @@ -9,8 +9,7 @@ @implementation FlipperConnectionMock -- (instancetype)init -{ +- (instancetype)init { if (self = [super init]) { _connected = YES; _receivers = @{}; @@ -19,29 +18,31 @@ return self; } - -- (void)send:(NSString *)method withParams:(NSDictionary *)params -{ +- (void)send:(NSString*)method withParams:(NSDictionary*)params { if (_connected) { - NSMutableDictionary *newSent = [NSMutableDictionary new]; + NSMutableDictionary* newSent = [NSMutableDictionary new]; [newSent addEntriesFromDictionary:_sent]; if (newSent[method]) { newSent[method] = [_sent[method] arrayByAddingObject:params]; } else { - newSent[method] = @[params]; + newSent[method] = @[ params ]; } _sent = newSent; } } -- (void)receive:(NSString *)method withBlock:(SonarReceiver)receiver -{ +- (void)receive:(NSString*)method withBlock:(SonarReceiver)receiver { if (_connected) { - NSMutableDictionary *newReceivers = [NSMutableDictionary new]; + NSMutableDictionary* newReceivers = [NSMutableDictionary new]; [newReceivers addEntriesFromDictionary:_receivers]; newReceivers[method] = receiver; _receivers = newReceivers; } } +- (void)errorWithMessage:(NSString*)message stackTrace:(NSString*)stacktrace { + // Empty Implementation + // TODO: Test this method too. +} + @end diff --git a/react-native/ReactNativeFlipperExample/ios/Podfile b/react-native/ReactNativeFlipperExample/ios/Podfile index b48808e63..3b854c537 100644 --- a/react-native/ReactNativeFlipperExample/ios/Podfile +++ b/react-native/ReactNativeFlipperExample/ios/Podfile @@ -1,14 +1,15 @@ -platform :ios, '9.0' +platform :ios, '10.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' + flipperkit_version = '0.31.1' + pod 'FlipperKit', :path => "../../../FlipperKit.podspec", :configuration => 'Debug' + pod 'FlipperKit/FlipperKitLayoutPlugin', :path => "../../../FlipperKit.podspec", :configuration => 'Debug' + pod 'FlipperKit/SKIOSNetworkPlugin', :path => "../../../FlipperKit.podspec", :configuration => 'Debug' + pod 'FlipperKit/FlipperKitUserDefaultsPlugin', :path => "../../../FlipperKit.podspec", :configuration => 'Debug' + pod 'FlipperKit/FlipperKitReactPlugin', :path => "../../../FlipperKit.podspec", :configuration => 'Debug' + pod 'Flipper', :path => "../../../Flipper.podspec", :configuration => 'Debug' end # Post Install processing for Flipper @@ -70,12 +71,7 @@ target 'ReactNativeFlipperExample' do pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec' pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec' - target 'ReactNativeFlipperExampleTests' do - inherit! :complete - # Pods for testing - end - - use_native_modules! + pod 'react-native-flipper', :path => "../../react-native-flipper/react-native-flipper.podspec", :configuration => 'Debug' # For enabling Flipper. # Note that if you use_frameworks!, flipper will no work. @@ -85,12 +81,3 @@ target 'ReactNativeFlipperExample' do flipper_post_install(installer) end end - -target 'ReactNativeFlipperExample-tvOS' do - # Pods for ReactNativeFlipperExample-tvOS - - target 'ReactNativeFlipperExample-tvOSTests' do - inherit! :search_paths - # Pods for testing - end -end diff --git a/react-native/ReactNativeFlipperExample/ios/ReactNativeFlipperExample.xcodeproj/project.pbxproj b/react-native/ReactNativeFlipperExample/ios/ReactNativeFlipperExample.xcodeproj/project.pbxproj new file mode 100644 index 000000000..b4237b100 --- /dev/null +++ b/react-native/ReactNativeFlipperExample/ios/ReactNativeFlipperExample.xcodeproj/project.pbxproj @@ -0,0 +1,489 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; }; + 13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB11A68108700A75B9A /* LaunchScreen.xib */; }; + 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; + 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; + 1D5631221A467F1A2FB9C834 /* libPods-ReactNativeFlipperExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 677ABAC4D0DB1742356A7207 /* libPods-ReactNativeFlipperExample.a */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 008F07F21AC5B25A0029DE68 /* main.jsbundle */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = main.jsbundle; sourceTree = ""; }; + 00E356F11AD99517003FC87E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 00E356F21AD99517003FC87E /* ReactNativeFlipperExampleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ReactNativeFlipperExampleTests.m; sourceTree = ""; }; + 0A53C1501254161A3B2DFDAC /* libPods-ReactNativeFlipperExample-ReactNativeFlipperExampleTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ReactNativeFlipperExample-ReactNativeFlipperExampleTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 0CEE2A7C797C0ED00CCB7AF6 /* Pods-ReactNativeFlipperExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeFlipperExample.release.xcconfig"; path = "Target Support Files/Pods-ReactNativeFlipperExample/Pods-ReactNativeFlipperExample.release.xcconfig"; sourceTree = ""; }; + 13B07F961A680F5B00A75B9A /* ReactNativeFlipperExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ReactNativeFlipperExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = ReactNativeFlipperExample/AppDelegate.h; sourceTree = ""; }; + 13B07FB01A68108700A75B9A /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppDelegate.m; path = ReactNativeFlipperExample/AppDelegate.m; sourceTree = ""; }; + 13B07FB21A68108700A75B9A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; + 13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = ReactNativeFlipperExample/Images.xcassets; sourceTree = ""; }; + 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = ReactNativeFlipperExample/Info.plist; sourceTree = ""; }; + 13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = ReactNativeFlipperExample/main.m; sourceTree = ""; }; + 524E86AAFC753C7A7834B6DC /* Pods-ReactNativeFlipperExample-tvOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeFlipperExample-tvOS.debug.xcconfig"; path = "Target Support Files/Pods-ReactNativeFlipperExample-tvOS/Pods-ReactNativeFlipperExample-tvOS.debug.xcconfig"; sourceTree = ""; }; + 677ABAC4D0DB1742356A7207 /* libPods-ReactNativeFlipperExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ReactNativeFlipperExample.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 69EBE15FA3A6D07374D767D1 /* libPods-ReactNativeFlipperExample-tvOSTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ReactNativeFlipperExample-tvOSTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 90E34B4265657E54E57ED11D /* Pods-ReactNativeFlipperExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeFlipperExample.debug.xcconfig"; path = "Target Support Files/Pods-ReactNativeFlipperExample/Pods-ReactNativeFlipperExample.debug.xcconfig"; sourceTree = ""; }; + 9365E1B366F6A5531B2CF068 /* Pods-ReactNativeFlipperExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeFlipperExampleTests.release.xcconfig"; path = "Target Support Files/Pods-ReactNativeFlipperExampleTests/Pods-ReactNativeFlipperExampleTests.release.xcconfig"; sourceTree = ""; }; + 9F62F65844BF18E65490D30D /* Pods-ReactNativeFlipperExample-tvOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeFlipperExample-tvOS.release.xcconfig"; path = "Target Support Files/Pods-ReactNativeFlipperExample-tvOS/Pods-ReactNativeFlipperExample-tvOS.release.xcconfig"; sourceTree = ""; }; + A0919DB2D65CD9DF8D8E2980 /* Pods-ReactNativeFlipperExample-tvOSTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeFlipperExample-tvOSTests.debug.xcconfig"; path = "Target Support Files/Pods-ReactNativeFlipperExample-tvOSTests/Pods-ReactNativeFlipperExample-tvOSTests.debug.xcconfig"; sourceTree = ""; }; + A1BF03F1A57774672BDD345B /* Pods-ReactNativeFlipperExample-ReactNativeFlipperExampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeFlipperExample-ReactNativeFlipperExampleTests.debug.xcconfig"; path = "Target Support Files/Pods-ReactNativeFlipperExample-ReactNativeFlipperExampleTests/Pods-ReactNativeFlipperExample-ReactNativeFlipperExampleTests.debug.xcconfig"; sourceTree = ""; }; + B7395A3F08333DA54AF2D7E2 /* Pods-ReactNativeFlipperExampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeFlipperExampleTests.debug.xcconfig"; path = "Target Support Files/Pods-ReactNativeFlipperExampleTests/Pods-ReactNativeFlipperExampleTests.debug.xcconfig"; sourceTree = ""; }; + CCFF2A2614AA2128BC0B8A3C /* Pods-ReactNativeFlipperExample-ReactNativeFlipperExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeFlipperExample-ReactNativeFlipperExampleTests.release.xcconfig"; path = "Target Support Files/Pods-ReactNativeFlipperExample-ReactNativeFlipperExampleTests/Pods-ReactNativeFlipperExample-ReactNativeFlipperExampleTests.release.xcconfig"; sourceTree = ""; }; + CE468610D4E1250F3DB650B8 /* Pods-ReactNativeFlipperExample-tvOSTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeFlipperExample-tvOSTests.release.xcconfig"; path = "Target Support Files/Pods-ReactNativeFlipperExample-tvOSTests/Pods-ReactNativeFlipperExample-tvOSTests.release.xcconfig"; sourceTree = ""; }; + E07034EC3D3D9C978BB88DA3 /* libPods-ReactNativeFlipperExample-tvOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ReactNativeFlipperExample-tvOS.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; + ED2971642150620600B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS12.0.sdk/System/Library/Frameworks/JavaScriptCore.framework; sourceTree = DEVELOPER_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 13B07F8C1A680F5B00A75B9A /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 1D5631221A467F1A2FB9C834 /* libPods-ReactNativeFlipperExample.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 00E356EF1AD99517003FC87E /* ReactNativeFlipperExampleTests */ = { + isa = PBXGroup; + children = ( + 00E356F21AD99517003FC87E /* ReactNativeFlipperExampleTests.m */, + 00E356F01AD99517003FC87E /* Supporting Files */, + ); + path = ReactNativeFlipperExampleTests; + sourceTree = ""; + }; + 00E356F01AD99517003FC87E /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 00E356F11AD99517003FC87E /* Info.plist */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 13B07FAE1A68108700A75B9A /* ReactNativeFlipperExample */ = { + isa = PBXGroup; + children = ( + 008F07F21AC5B25A0029DE68 /* main.jsbundle */, + 13B07FAF1A68108700A75B9A /* AppDelegate.h */, + 13B07FB01A68108700A75B9A /* AppDelegate.m */, + 13B07FB51A68108700A75B9A /* Images.xcassets */, + 13B07FB61A68108700A75B9A /* Info.plist */, + 13B07FB11A68108700A75B9A /* LaunchScreen.xib */, + 13B07FB71A68108700A75B9A /* main.m */, + ); + name = ReactNativeFlipperExample; + sourceTree = ""; + }; + 2D16E6871FA4F8E400B85C8A /* Frameworks */ = { + isa = PBXGroup; + children = ( + ED297162215061F000B7C4FE /* JavaScriptCore.framework */, + ED2971642150620600B7C4FE /* JavaScriptCore.framework */, + 677ABAC4D0DB1742356A7207 /* libPods-ReactNativeFlipperExample.a */, + E07034EC3D3D9C978BB88DA3 /* libPods-ReactNativeFlipperExample-tvOS.a */, + 69EBE15FA3A6D07374D767D1 /* libPods-ReactNativeFlipperExample-tvOSTests.a */, + 0A53C1501254161A3B2DFDAC /* libPods-ReactNativeFlipperExample-ReactNativeFlipperExampleTests.a */, + ); + name = Frameworks; + sourceTree = ""; + }; + 5225F89096E7C25B23FC3F9C /* Pods */ = { + isa = PBXGroup; + children = ( + 90E34B4265657E54E57ED11D /* Pods-ReactNativeFlipperExample.debug.xcconfig */, + 0CEE2A7C797C0ED00CCB7AF6 /* Pods-ReactNativeFlipperExample.release.xcconfig */, + 524E86AAFC753C7A7834B6DC /* Pods-ReactNativeFlipperExample-tvOS.debug.xcconfig */, + 9F62F65844BF18E65490D30D /* Pods-ReactNativeFlipperExample-tvOS.release.xcconfig */, + A0919DB2D65CD9DF8D8E2980 /* Pods-ReactNativeFlipperExample-tvOSTests.debug.xcconfig */, + CE468610D4E1250F3DB650B8 /* Pods-ReactNativeFlipperExample-tvOSTests.release.xcconfig */, + B7395A3F08333DA54AF2D7E2 /* Pods-ReactNativeFlipperExampleTests.debug.xcconfig */, + 9365E1B366F6A5531B2CF068 /* Pods-ReactNativeFlipperExampleTests.release.xcconfig */, + A1BF03F1A57774672BDD345B /* Pods-ReactNativeFlipperExample-ReactNativeFlipperExampleTests.debug.xcconfig */, + CCFF2A2614AA2128BC0B8A3C /* Pods-ReactNativeFlipperExample-ReactNativeFlipperExampleTests.release.xcconfig */, + ); + path = Pods; + sourceTree = ""; + }; + 832341AE1AAA6A7D00B99B32 /* Libraries */ = { + isa = PBXGroup; + children = ( + ); + name = Libraries; + sourceTree = ""; + }; + 83CBB9F61A601CBA00E9B192 = { + isa = PBXGroup; + children = ( + 13B07FAE1A68108700A75B9A /* ReactNativeFlipperExample */, + 832341AE1AAA6A7D00B99B32 /* Libraries */, + 00E356EF1AD99517003FC87E /* ReactNativeFlipperExampleTests */, + 83CBBA001A601CBA00E9B192 /* Products */, + 2D16E6871FA4F8E400B85C8A /* Frameworks */, + 5225F89096E7C25B23FC3F9C /* Pods */, + ); + indentWidth = 2; + sourceTree = ""; + tabWidth = 2; + usesTabs = 0; + }; + 83CBBA001A601CBA00E9B192 /* Products */ = { + isa = PBXGroup; + children = ( + 13B07F961A680F5B00A75B9A /* ReactNativeFlipperExample.app */, + ); + name = Products; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 13B07F861A680F5B00A75B9A /* ReactNativeFlipperExample */ = { + isa = PBXNativeTarget; + buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "ReactNativeFlipperExample" */; + buildPhases = ( + E18E055A1140CFCA68690D78 /* [CP] Check Pods Manifest.lock */, + FD10A7F022414F080027D42C /* Start Packager */, + 13B07F871A680F5B00A75B9A /* Sources */, + 13B07F8C1A680F5B00A75B9A /* Frameworks */, + 13B07F8E1A680F5B00A75B9A /* Resources */, + 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = ReactNativeFlipperExample; + productName = ReactNativeFlipperExample; + productReference = 13B07F961A680F5B00A75B9A /* ReactNativeFlipperExample.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 83CBB9F71A601CBA00E9B192 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0940; + ORGANIZATIONNAME = Facebook; + TargetAttributes = { + 13B07F861A680F5B00A75B9A = { + LastSwiftMigration = 1130; + }; + }; + }; + buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "ReactNativeFlipperExample" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + English, + en, + Base, + ); + mainGroup = 83CBB9F61A601CBA00E9B192; + productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 13B07F861A680F5B00A75B9A /* ReactNativeFlipperExample */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 13B07F8E1A680F5B00A75B9A /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */, + 13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Bundle React Native code and images"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh"; + }; + E18E055A1140CFCA68690D78 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-ReactNativeFlipperExample-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; + FD10A7F022414F080027D42C /* Start Packager */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = "Start Packager"; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "export RCT_METRO_PORT=\"${RCT_METRO_PORT:=8081}\"\necho \"export RCT_METRO_PORT=${RCT_METRO_PORT}\" > \"${SRCROOT}/../node_modules/react-native/scripts/.packager.env\"\nif [ -z \"${RCT_NO_LAUNCH_PACKAGER+xxx}\" ] ; then\n if nc -w 5 -z localhost ${RCT_METRO_PORT} ; then\n if ! curl -s \"http://localhost:${RCT_METRO_PORT}/status\" | grep -q \"packager-status:running\" ; then\n echo \"Port ${RCT_METRO_PORT} already in use, packager is either not running or not running correctly\"\n exit 2\n fi\n else\n open \"$SRCROOT/../node_modules/react-native/scripts/launchPackager.command\" || echo \"Can't start packager automatically\"\n fi\nfi\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 13B07F871A680F5B00A75B9A /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */, + 13B07FC11A68108700A75B9A /* main.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 13B07FB11A68108700A75B9A /* LaunchScreen.xib */ = { + isa = PBXVariantGroup; + children = ( + 13B07FB21A68108700A75B9A /* Base */, + ); + name = LaunchScreen.xib; + path = ReactNativeFlipperExample; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 13B07F941A680F5B00A75B9A /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 90E34B4265657E54E57ED11D /* Pods-ReactNativeFlipperExample.debug.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = 1; + DEAD_CODE_STRIPPING = YES; + INFOPLIST_FILE = ReactNativeFlipperExample/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "/usr/lib/swift $(inherited) @executable_path/Frameworks"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"", + "\"$(TOOLCHAIN_DIR)/usr/lib/swift-$(SWIFT_VERSION)/$(PLATFORM_NAME)\"", + ); + OTHER_CFLAGS = ( + "$(inherited)", + "-DFB_SONARKIT_ENABLED=1", + ); + OTHER_LDFLAGS = ( + "$(inherited)", + "-ObjC", + "-lc++", + ); + PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_NAME = ReactNativeFlipperExample; + REEXPORTED_LIBRARY_PATHS = ""; + SWIFT_OBJC_BRIDGING_HEADER = "ReactNativeFlipperExample-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Debug; + }; + 13B07F951A680F5B00A75B9A /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 0CEE2A7C797C0ED00CCB7AF6 /* Pods-ReactNativeFlipperExample.release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = 1; + INFOPLIST_FILE = ReactNativeFlipperExample/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "/usr/lib/swift $(inherited) @executable_path/Frameworks"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"", + "\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"", + ); + OTHER_CFLAGS = ( + "$(inherited)", + "-DFB_SONARKIT_ENABLED=1", + ); + OTHER_LDFLAGS = ( + "$(inherited)", + "-ObjC", + "-lc++", + ); + PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_NAME = ReactNativeFlipperExample; + REEXPORTED_LIBRARY_PATHS = ""; + SWIFT_OBJC_BRIDGING_HEADER = "ReactNativeFlipperExample-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Release; + }; + 83CBBA201A601CBA00E9B192 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + }; + name = Debug; + }; + 83CBBA211A601CBA00E9B192 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = YES; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "ReactNativeFlipperExample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 13B07F941A680F5B00A75B9A /* Debug */, + 13B07F951A680F5B00A75B9A /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "ReactNativeFlipperExample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 83CBBA201A601CBA00E9B192 /* Debug */, + 83CBBA211A601CBA00E9B192 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 83CBB9F71A601CBA00E9B192 /* Project object */; +} diff --git a/react-native/ReactNativeFlipperExample/ios/ReactNativeFlipperExample.xcodeproj/xcshareddata/xcschemes/ReactNativeFlipperExample-tvOS.xcscheme b/react-native/ReactNativeFlipperExample/ios/ReactNativeFlipperExample.xcodeproj/xcshareddata/xcschemes/ReactNativeFlipperExample-tvOS.xcscheme new file mode 100644 index 000000000..31cc6d967 --- /dev/null +++ b/react-native/ReactNativeFlipperExample/ios/ReactNativeFlipperExample.xcodeproj/xcshareddata/xcschemes/ReactNativeFlipperExample-tvOS.xcscheme @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/react-native/ReactNativeFlipperExample/ios/ReactNativeFlipperExample.xcodeproj/xcshareddata/xcschemes/ReactNativeFlipperExample.xcscheme b/react-native/ReactNativeFlipperExample/ios/ReactNativeFlipperExample.xcodeproj/xcshareddata/xcschemes/ReactNativeFlipperExample.xcscheme new file mode 100644 index 000000000..5c7263060 --- /dev/null +++ b/react-native/ReactNativeFlipperExample/ios/ReactNativeFlipperExample.xcodeproj/xcshareddata/xcschemes/ReactNativeFlipperExample.xcscheme @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/react-native/ReactNativeFlipperExample/ios/ReactNativeFlipperExample/AppDelegate.m b/react-native/ReactNativeFlipperExample/ios/ReactNativeFlipperExample/AppDelegate.m index 8bfd2b6df..636b87759 100644 --- a/react-native/ReactNativeFlipperExample/ios/ReactNativeFlipperExample/AppDelegate.m +++ b/react-native/ReactNativeFlipperExample/ios/ReactNativeFlipperExample/AppDelegate.m @@ -12,7 +12,6 @@ #import #if DEBUG -#ifdef FB_SONARKIT_ENABLED #import #import #import @@ -20,12 +19,13 @@ #import #import #endif -#endif @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + [AppDelegate initializeFlipper:application]; + RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"ReactNativeFlipperExample" @@ -53,7 +53,6 @@ + (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]]; @@ -62,7 +61,6 @@ [client addPlugin: [[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]]; [client start]; #endif -#endif } @end diff --git a/react-native/ReactNativeFlipperExample/ios/Swift.swift b/react-native/ReactNativeFlipperExample/ios/Swift.swift deleted file mode 100644 index 1e49e70b0..000000000 --- a/react-native/ReactNativeFlipperExample/ios/Swift.swift +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// Flipper requires Swift, feel free to delete this file if you do not plan to use Flipper. - -import Foundation diff --git a/react-native/react-native-flipper/ios/Flipper.m b/react-native/react-native-flipper/ios/Flipper.m deleted file mode 100644 index bae46dee9..000000000 --- a/react-native/react-native-flipper/ios/Flipper.m +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#import "Flipper.h" - - -@implementation Flipper - -RCT_EXPORT_MODULE() - -RCT_EXPORT_METHOD(sampleMethod:(NSString *)stringArgument numberParameter:(nonnull NSNumber *)numberArgument callback:(RCTResponseSenderBlock)callback) -{ - // TODO: Implement some actually useful functionality - callback(@[[NSString stringWithFormat: @"numberArgument: %@ stringArgument: %@", numberArgument, stringArgument]]); -} - -@end diff --git a/react-native/react-native-flipper/ios/Flipper.h b/react-native/react-native-flipper/ios/FlipperModule.h similarity index 70% rename from react-native/react-native-flipper/ios/Flipper.h rename to react-native/react-native-flipper/ios/FlipperModule.h index 483f3681e..32827b59e 100644 --- a/react-native/react-native-flipper/ios/Flipper.h +++ b/react-native/react-native-flipper/ios/FlipperModule.h @@ -5,8 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -#import +#import -@interface Flipper : NSObject +@interface FlipperModule : RCTEventEmitter @end diff --git a/react-native/react-native-flipper/ios/FlipperModule.m b/react-native/react-native-flipper/ios/FlipperModule.m new file mode 100644 index 000000000..b5d5edb9c --- /dev/null +++ b/react-native/react-native-flipper/ios/FlipperModule.m @@ -0,0 +1,98 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import "FlipperModule.h" + +#import "FlipperReactNativeJavaScriptPluginManager.h" + +@implementation FlipperModule +{ + __weak FlipperReactNativeJavaScriptPluginManager *_manager; +} + +- (instancetype)init +{ + return [self initWithManager:[FlipperReactNativeJavaScriptPluginManager sharedInstance]]; +} + +- (instancetype)initWithManager:(FlipperReactNativeJavaScriptPluginManager *)manager +{ + if (self = [super init]) { + _manager = manager; + } + return self; +} + +RCT_EXPORT_MODULE(Flipper) + ++ (BOOL)requiresMainQueueSetup +{ + return NO; +} + +- (NSArray *)supportedEvents +{ + return @[ + @"react-native-flipper-plugin-connect", + @"react-native-flipper-plugin-disconnect", + @"react-native-flipper-receive-event", + ]; +} + +- (void)startObserving +{ + +} + +- (void)stopObserving +{ + +} + +RCT_EXPORT_METHOD(registerPlugin:(NSString *)pluginId + inBackground:(BOOL)inBackground + statusCallback:(RCTResponseSenderBlock)statusCallback) +{ + [_manager registerPluginWithModule:self + pluginId:pluginId + inBackground:inBackground + statusCallback:statusCallback]; +} + +RCT_EXPORT_METHOD(send:(NSString *)pluginId method:(NSString *)method data:(NSString *)data) +{ + [_manager sendWithPluginId:pluginId method:method data:data]; +} + +RCT_EXPORT_METHOD(reportErrorWithMetadata:(NSString *)pluginId + reason:(NSString *)reason + stackTrace:(NSString *)stackTrace) +{ + [_manager reportErrorWithMetadata:reason stackTrace:stackTrace pluginId:pluginId]; +} + +RCT_EXPORT_METHOD(reportError:(NSString *)pluginId error:(NSString *)error) +{ + [_manager reportError:error pluginId:pluginId]; +} + +RCT_EXPORT_METHOD(subscribe:(NSString *)pluginId method:(NSString *)method) +{ + [_manager subscribeWithModule:self pluginId:pluginId method:method]; +} + +RCT_EXPORT_METHOD(respondSuccess:(NSString *)responderId data:(NSString *)data) +{ + [_manager respondSuccessWithResponderId:responderId data:data]; +} + +RCT_EXPORT_METHOD(respondError:(NSString *)responderId data:(NSString *)data) +{ + [_manager respondErrorWithResponderId:responderId data:data]; +} + +@end diff --git a/react-native/react-native-flipper/ios/FlipperReactNativeJavaScriptPlugin.h b/react-native/react-native-flipper/ios/FlipperReactNativeJavaScriptPlugin.h new file mode 100644 index 000000000..3c596ec63 --- /dev/null +++ b/react-native/react-native-flipper/ios/FlipperReactNativeJavaScriptPlugin.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@class FlipperModule; + +@interface FlipperReactNativeJavaScriptPlugin : NSObject + +@property (nonatomic, weak) FlipperModule *module; +@property (nonatomic, strong, readonly) id connection; + +- (instancetype)initWithFlipperModule:(FlipperModule *)module + pluginId:(NSString *)pluginId + inBackground:(BOOL)inBackground; + +- (BOOL)isConnected; + +- (void)fireOnConnect; + +@end + +NS_ASSUME_NONNULL_END diff --git a/react-native/react-native-flipper/ios/FlipperReactNativeJavaScriptPlugin.m b/react-native/react-native-flipper/ios/FlipperReactNativeJavaScriptPlugin.m new file mode 100644 index 000000000..43b5b279f --- /dev/null +++ b/react-native/react-native-flipper/ios/FlipperReactNativeJavaScriptPlugin.m @@ -0,0 +1,72 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import "FlipperReactNativeJavaScriptPlugin.h" + +#import +#import + +#import "FlipperModule.h" + +@implementation FlipperReactNativeJavaScriptPlugin +{ + NSString *_pluginId; + BOOL _inBackground; +} + +- (instancetype)initWithFlipperModule:(FlipperModule *)module + pluginId:(NSString *)pluginId + inBackground:(BOOL)inBackground +{ + if (self = [super init]) { + _module = module; + _pluginId = pluginId; + _inBackground = inBackground; + } + return self; +} + +- (NSString *)identifier +{ + return _pluginId; +} + +- (BOOL)runInBackground +{ + return _inBackground; +} + +- (void)didConnect:(id)connection +{ + _connection = connection; + [self fireOnConnect]; +} + +- (void)didDisconnect +{ + _connection = nil; + [_module sendEventWithName:@"react-native-flipper-plugin-disconnect" + body:[self pluginParams]]; +} + +- (BOOL)isConnected +{ + return _connection != nil; +} + +- (void)fireOnConnect +{ + [_module sendEventWithName:@"react-native-flipper-plugin-connect" + body:[self pluginParams]]; +} + +- (id)pluginParams +{ + return @{@"plugin": _pluginId}; +} + +@end diff --git a/react-native/react-native-flipper/ios/FlipperReactNativeJavaScriptPluginManager.h b/react-native/react-native-flipper/ios/FlipperReactNativeJavaScriptPluginManager.h new file mode 100644 index 000000000..0a39a2dd5 --- /dev/null +++ b/react-native/react-native-flipper/ios/FlipperReactNativeJavaScriptPluginManager.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import + +#import + +NS_ASSUME_NONNULL_BEGIN + +@class FlipperModule; + +@interface FlipperReactNativeJavaScriptPluginManager : NSObject + ++ (instancetype)sharedInstance; + +- (void)registerPluginWithModule:(FlipperModule *)module + pluginId:(NSString *)pluginId + inBackground:(BOOL)inBackground + statusCallback:(RCTResponseSenderBlock)statusCallback; + +- (void)sendWithPluginId:(NSString *)pluginId method:(NSString *)method data:(NSString *)data; + +- (void)reportErrorWithMetadata:(NSString *)reason + stackTrace:(NSString *)stackTrace + pluginId:(NSString *)pluginId; + +- (void)reportError:(NSString *)error pluginId:(NSString *)pluginId; + +- (void)subscribeWithModule:(FlipperModule *)module + pluginId:(NSString *)pluginId + method:(NSString *)method; + +- (void)respondSuccessWithResponderId:(NSString *)responderId data:(NSString *)data; + +- (void)respondErrorWithResponderId:(NSString *)responderId data:(NSString *)data; + +@end + +NS_ASSUME_NONNULL_END diff --git a/react-native/react-native-flipper/ios/FlipperReactNativeJavaScriptPluginManager.m b/react-native/react-native-flipper/ios/FlipperReactNativeJavaScriptPluginManager.m new file mode 100644 index 000000000..2427d2812 --- /dev/null +++ b/react-native/react-native-flipper/ios/FlipperReactNativeJavaScriptPluginManager.m @@ -0,0 +1,144 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + + +#import "FlipperReactNativeJavaScriptPluginManager.h" +#import +#import +#import +#import "FlipperModule.h" +#import "FlipperReactNativeJavaScriptPlugin.h" + +static uint32_t FlipperResponderKeyGenerator = 0; + +@implementation FlipperReactNativeJavaScriptPluginManager +{ + __weak FlipperClient *_flipperClient; + NSMutableDictionary> *_responders; +} + ++ (instancetype)sharedInstance +{ + static FlipperReactNativeJavaScriptPluginManager *sharedInstance = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + sharedInstance = [self new]; + }); + return sharedInstance; +} + +- (instancetype)init +{ + if (self = [super init]) { + _flipperClient = [FlipperClient sharedClient]; + _responders = [NSMutableDictionary new]; + } + return self; +} + +- (void)registerPluginWithModule:(FlipperModule *)module + pluginId:(NSString *)pluginId + inBackground:(BOOL)inBackground + statusCallback:(RCTResponseSenderBlock)statusCallback +{ + if (_flipperClient == nil) { + // Flipper is not available in this build + statusCallback(@[@"noflipper"]); + return; + } + + FlipperReactNativeJavaScriptPlugin *existingPlugin = [self jsPluginWithIdentifier:pluginId]; + if (existingPlugin != nil) { + existingPlugin.module = module; + + if (existingPlugin.isConnected) { + [existingPlugin fireOnConnect]; + } + + statusCallback(@[@"ok"]); + return; + } + + FlipperReactNativeJavaScriptPlugin *newPlugin = + [[FlipperReactNativeJavaScriptPlugin alloc] initWithFlipperModule:module + pluginId:pluginId + inBackground:inBackground]; + [_flipperClient addPlugin:newPlugin]; + statusCallback(@[@"ok"]); +} + +- (void)sendWithPluginId:(NSString *)pluginId method:(NSString *)method data:(NSString *)data +{ + [[self jsPluginWithIdentifier:pluginId].connection send:method + withParams:RCTJSONParse(data, NULL)]; +} + +- (void)reportErrorWithMetadata:(NSString *)reason + stackTrace:(NSString *)stackTrace + pluginId:(NSString *)pluginId +{ + [[self jsPluginWithIdentifier:pluginId].connection errorWithMessage:reason stackTrace:stackTrace]; +} + +- (void)reportError:(NSString *)error pluginId:(NSString *)pluginId +{ + + // Stacktrace + NSMutableArray *callstack = NSThread.callStackSymbols.mutableCopy; + NSMutableString *callstackString = callstack.firstObject.mutableCopy; + [callstack removeObject:callstack.firstObject]; + for (NSString *stack in callstack) { + [callstackString appendFormat:@"\n %@", stack]; + } + + [[self jsPluginWithIdentifier:pluginId].connection errorWithMessage:error stackTrace:callstackString]; +} + +- (void)subscribeWithModule:(FlipperModule *)module + pluginId:(NSString *)pluginId + method:(NSString *)method +{ + __weak __typeof(self) weakSelf = self; + [[self jsPluginWithIdentifier: pluginId].connection receive:method withBlock:^(NSDictionary * params, id responder) { + __typeof(self) strongSelf = weakSelf; + + NSMutableDictionary *body = [NSMutableDictionary dictionaryWithDictionary:@{ + @"plugin": pluginId, + @"method": method, + @"params": RCTJSONStringify(params, NULL), + }]; + + if (responder != nil) { + NSString *responderId = [NSString stringWithFormat:@"%d", FlipperResponderKeyGenerator++]; + strongSelf->_responders[responderId] = responder; + body[@"responderId"] = responderId; + } + + [module sendEventWithName:@"react-native-flipper-receive-event" body:body]; + }]; +} + +- (void)respondSuccessWithResponderId:(NSString *)responderId data:(NSString *)data +{ + id responder = _responders[responderId]; + [responder success:RCTJSONParse(data, NULL)]; + [_responders removeObjectForKey:responderId]; +} + +- (void)respondErrorWithResponderId:(NSString *)responderId data:(NSString *)data +{ + id responder = _responders[responderId]; + [responder error:RCTJSONParse(data, NULL)]; + [_responders removeObjectForKey:responderId]; +} + +- (FlipperReactNativeJavaScriptPlugin *)jsPluginWithIdentifier:(NSString *)pluginId +{ + return (FlipperReactNativeJavaScriptPlugin *)[_flipperClient pluginWithIdentifier:pluginId]; +} + +@end diff --git a/react-native/react-native-flipper/react-native-flipper.podspec b/react-native/react-native-flipper/react-native-flipper.podspec index 96eb880b3..935e1d9a0 100644 --- a/react-native/react-native-flipper/react-native-flipper.podspec +++ b/react-native/react-native-flipper/react-native-flipper.podspec @@ -6,6 +6,7 @@ require "json" package = JSON.parse(File.read(File.join(__dir__, "package.json"))) +compiler_flags = '-DFB_SONARKIT_ENABLED=1' Pod::Spec.new do |s| s.name = "react-native-flipper" @@ -22,10 +23,8 @@ Pod::Spec.new do |s| s.source = { :git => "https://github.com/github_account/react-native-flipper.git", :tag => "#{s.version}" } s.source_files = "ios/**/*.{h,m,swift}" + s.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"${PODS_ROOT}/Headers/Public/FlipperKit\"" } s.requires_arc = true - + s.compiler_flags = compiler_flags s.dependency "React" - # ... - # s.dependency "..." end -