CLANGFORMAT the remaining files of xplat/sonar
Summary: As per title. Ran `arc lint -a --take CLANGFORMAT --paths-cmd 'hg files ./'` from xplat/sonar Reviewed By: zertosh Differential Revision: D19943131 fbshipit-source-id: c1dc10b27389fd6f54f055803519dac6bf0e7997
This commit is contained in:
committed by
Facebook Github Bot
parent
7db8d300a8
commit
bd388f73e4
@@ -16,16 +16,17 @@ static BOOL prefix(const char *pre, const char *str) {
|
|||||||
return strncmp(pre, str, strlen(pre)) == 0;
|
return strncmp(pre, str, strlen(pre)) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char* argv[]) {
|
||||||
{
|
|
||||||
long connectionsPort = 8081;
|
long connectionsPort = 8081;
|
||||||
long multiplexPort = 8025;
|
long multiplexPort = 8025;
|
||||||
|
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
if (prefix(kPortForwardParamPrefix, argv[i])) {
|
if (prefix(kPortForwardParamPrefix, argv[i])) {
|
||||||
connectionsPort = strtol(argv[i] + strlen(kPortForwardParamPrefix), NULL, 10);
|
connectionsPort =
|
||||||
|
strtol(argv[i] + strlen(kPortForwardParamPrefix), NULL, 10);
|
||||||
} else if (prefix(kMultiplexChannelPortParamPrefix, argv[i])) {
|
} else if (prefix(kMultiplexChannelPortParamPrefix, argv[i])) {
|
||||||
multiplexPort = strtol(argv[i] + strlen(kMultiplexChannelPortParamPrefix), NULL, 10);
|
multiplexPort =
|
||||||
|
strtol(argv[i] + strlen(kMultiplexChannelPortParamPrefix), NULL, 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,8 @@
|
|||||||
* Everything here is expected to be VM-neutral.
|
* Everything here is expected to be VM-neutral.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
|
|
||||||
#ifndef JNI_H_
|
#ifndef JNI_H_
|
||||||
#define JNI_H_
|
#define JNI_H_
|
||||||
|
|
||||||
|
|||||||
@@ -14,24 +14,29 @@
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
#import <FlipperKit/FlipperClient.h>
|
#import <FlipperKit/FlipperClient.h>
|
||||||
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
|
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
|
||||||
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
|
|
||||||
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
|
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
|
||||||
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
|
|
||||||
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
|
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
|
||||||
|
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
|
||||||
|
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@implementation AppDelegate
|
@implementation AppDelegate
|
||||||
|
|
||||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
- (BOOL)application:(UIApplication*)application
|
||||||
{
|
didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
|
||||||
[AppDelegate initializeFlipper:application];
|
[AppDelegate initializeFlipper:application];
|
||||||
|
|
||||||
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
|
RCTBridge* bridge = [[RCTBridge alloc] initWithDelegate:self
|
||||||
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
|
launchOptions:launchOptions];
|
||||||
|
RCTRootView* rootView =
|
||||||
|
[[RCTRootView alloc] initWithBridge:bridge
|
||||||
moduleName:@"ReactNativeFlipperExample"
|
moduleName:@"ReactNativeFlipperExample"
|
||||||
initialProperties:nil];
|
initialProperties:nil];
|
||||||
|
|
||||||
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
|
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f
|
||||||
|
green:1.0f
|
||||||
|
blue:1.0f
|
||||||
|
alpha:1];
|
||||||
|
|
||||||
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
||||||
UIViewController* rootViewController = [UIViewController new];
|
UIViewController* rootViewController = [UIViewController new];
|
||||||
@@ -41,24 +46,29 @@
|
|||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
|
- (NSURL*)sourceURLForBridge:(RCTBridge*)bridge {
|
||||||
{
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
|
return
|
||||||
|
[[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"
|
||||||
|
fallbackResource:nil];
|
||||||
#else
|
#else
|
||||||
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
|
return [[NSBundle mainBundle] URLForResource:@"main"
|
||||||
|
withExtension:@"jsbundle"];
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (void) initializeFlipper:(UIApplication *)application
|
+ (void)initializeFlipper:(UIApplication*)application {
|
||||||
{
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
FlipperClient* client = [FlipperClient sharedClient];
|
FlipperClient* client = [FlipperClient sharedClient];
|
||||||
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
|
SKDescriptorMapper* layoutDescriptorMapper =
|
||||||
[client addPlugin: [[FlipperKitLayoutPlugin alloc] initWithRootNode: application withDescriptorMapper: layoutDescriptorMapper]];
|
[[SKDescriptorMapper alloc] initWithDefaults];
|
||||||
|
[client addPlugin:[[FlipperKitLayoutPlugin alloc]
|
||||||
|
initWithRootNode:application
|
||||||
|
withDescriptorMapper:layoutDescriptorMapper]];
|
||||||
[client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
|
[client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
|
||||||
[client addPlugin:[FlipperKitReactPlugin new]];
|
[client addPlugin:[FlipperKitReactPlugin new]];
|
||||||
[client addPlugin: [[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
|
[client addPlugin:[[FlipperKitNetworkPlugin alloc]
|
||||||
|
initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
|
||||||
[client start];
|
[client start];
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
|
return UIApplicationMain(
|
||||||
|
argc, argv, nil, NSStringFromClass([AppDelegate class]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,7 @@
|
|||||||
|
|
||||||
@implementation ReactNativeFlipperExampleTests
|
@implementation ReactNativeFlipperExampleTests
|
||||||
|
|
||||||
- (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test
|
- (BOOL)findSubviewInView:(UIView*)view matching:(BOOL (^)(UIView* view))test {
|
||||||
{
|
|
||||||
if (test(view)) {
|
if (test(view)) {
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
@@ -33,15 +32,20 @@
|
|||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testRendersWelcomeScreen
|
- (void)testRendersWelcomeScreen {
|
||||||
{
|
UIViewController* vc =
|
||||||
UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController];
|
[[[RCTSharedApplication() delegate] window] rootViewController];
|
||||||
NSDate* date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
|
NSDate* date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
|
||||||
BOOL foundElement = NO;
|
BOOL foundElement = NO;
|
||||||
|
|
||||||
__block NSString* redboxError = nil;
|
__block NSString* redboxError = nil;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
|
RCTSetLogFunction(
|
||||||
|
^(RCTLogLevel level,
|
||||||
|
RCTLogSource source,
|
||||||
|
NSString* fileName,
|
||||||
|
NSNumber* lineNumber,
|
||||||
|
NSString* message) {
|
||||||
if (level >= RCTLogLevelError) {
|
if (level >= RCTLogLevelError) {
|
||||||
redboxError = message;
|
redboxError = message;
|
||||||
}
|
}
|
||||||
@@ -49,11 +53,15 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
|
while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
|
||||||
[[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
|
[[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode
|
||||||
[[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
|
beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
|
||||||
|
[[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes
|
||||||
|
beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
|
||||||
|
|
||||||
foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) {
|
foundElement = [self findSubviewInView:vc.view
|
||||||
if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) {
|
matching:^BOOL(UIView* view) {
|
||||||
|
if ([view.accessibilityLabel
|
||||||
|
isEqualToString:TEXT_TO_LOOK_FOR]) {
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
return NO;
|
return NO;
|
||||||
@@ -65,8 +73,11 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
|
XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
|
||||||
XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
|
XCTAssertTrue(
|
||||||
|
foundElement,
|
||||||
|
@"Couldn't find element with text '%@' in %d seconds",
|
||||||
|
TEXT_TO_LOOK_FOR,
|
||||||
|
TIMEOUT_SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -9,18 +9,17 @@
|
|||||||
|
|
||||||
#import "FlipperReactNativeJavaScriptPluginManager.h"
|
#import "FlipperReactNativeJavaScriptPluginManager.h"
|
||||||
|
|
||||||
@implementation FlipperModule
|
@implementation FlipperModule {
|
||||||
{
|
|
||||||
__weak FlipperReactNativeJavaScriptPluginManager* _manager;
|
__weak FlipperReactNativeJavaScriptPluginManager* _manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)init
|
- (instancetype)init {
|
||||||
{
|
return [self initWithManager:[FlipperReactNativeJavaScriptPluginManager
|
||||||
return [self initWithManager:[FlipperReactNativeJavaScriptPluginManager sharedInstance]];
|
sharedInstance]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithManager:(FlipperReactNativeJavaScriptPluginManager *)manager
|
- (instancetype)initWithManager:
|
||||||
{
|
(FlipperReactNativeJavaScriptPluginManager*)manager {
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
_manager = manager;
|
_manager = manager;
|
||||||
}
|
}
|
||||||
@@ -29,13 +28,11 @@
|
|||||||
|
|
||||||
RCT_EXPORT_MODULE(Flipper)
|
RCT_EXPORT_MODULE(Flipper)
|
||||||
|
|
||||||
+ (BOOL)requiresMainQueueSetup
|
+ (BOOL)requiresMainQueueSetup {
|
||||||
{
|
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray<NSString *> *)supportedEvents
|
- (NSArray<NSString*>*)supportedEvents {
|
||||||
{
|
|
||||||
return @[
|
return @[
|
||||||
@"react-native-flipper-plugin-connect",
|
@"react-native-flipper-plugin-connect",
|
||||||
@"react-native-flipper-plugin-disconnect",
|
@"react-native-flipper-plugin-disconnect",
|
||||||
@@ -43,55 +40,55 @@ RCT_EXPORT_MODULE(Flipper)
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)startObserving
|
- (void)startObserving {
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)stopObserving
|
- (void)stopObserving {
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(registerPlugin:(NSString *)pluginId
|
RCT_EXPORT_METHOD(registerPlugin
|
||||||
inBackground:(BOOL)inBackground
|
: (NSString*)pluginId inBackground
|
||||||
statusCallback:(RCTResponseSenderBlock)statusCallback)
|
: (BOOL)inBackground statusCallback
|
||||||
{
|
: (RCTResponseSenderBlock)statusCallback) {
|
||||||
[_manager registerPluginWithModule:self
|
[_manager registerPluginWithModule:self
|
||||||
pluginId:pluginId
|
pluginId:pluginId
|
||||||
inBackground:inBackground
|
inBackground:inBackground
|
||||||
statusCallback:statusCallback];
|
statusCallback:statusCallback];
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(send:(NSString *)pluginId method:(NSString *)method data:(NSString *)data)
|
RCT_EXPORT_METHOD(send
|
||||||
{
|
: (NSString*)pluginId method
|
||||||
|
: (NSString*)method data
|
||||||
|
: (NSString*)data) {
|
||||||
[_manager sendWithPluginId:pluginId method:method data:data];
|
[_manager sendWithPluginId:pluginId method:method data:data];
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(reportErrorWithMetadata:(NSString *)pluginId
|
RCT_EXPORT_METHOD(reportErrorWithMetadata
|
||||||
reason:(NSString *)reason
|
: (NSString*)pluginId reason
|
||||||
stackTrace:(NSString *)stackTrace)
|
: (NSString*)reason stackTrace
|
||||||
{
|
: (NSString*)stackTrace) {
|
||||||
[_manager reportErrorWithMetadata:reason stackTrace:stackTrace pluginId:pluginId];
|
[_manager reportErrorWithMetadata:reason
|
||||||
|
stackTrace:stackTrace
|
||||||
|
pluginId:pluginId];
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(reportError:(NSString *)pluginId error:(NSString *)error)
|
RCT_EXPORT_METHOD(reportError : (NSString*)pluginId error : (NSString*)error) {
|
||||||
{
|
|
||||||
[_manager reportError:error pluginId:pluginId];
|
[_manager reportError:error pluginId:pluginId];
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(subscribe:(NSString *)pluginId method:(NSString *)method)
|
RCT_EXPORT_METHOD(subscribe : (NSString*)pluginId method : (NSString*)method) {
|
||||||
{
|
|
||||||
[_manager subscribeWithModule:self pluginId:pluginId method:method];
|
[_manager subscribeWithModule:self pluginId:pluginId method:method];
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(respondSuccess:(NSString *)responderId data:(NSString *)data)
|
RCT_EXPORT_METHOD(respondSuccess
|
||||||
{
|
: (NSString*)responderId data
|
||||||
|
: (NSString*)data) {
|
||||||
[_manager respondSuccessWithResponderId:responderId data:data];
|
[_manager respondSuccessWithResponderId:responderId data:data];
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(respondError:(NSString *)responderId data:(NSString *)data)
|
RCT_EXPORT_METHOD(respondError
|
||||||
{
|
: (NSString*)responderId data
|
||||||
|
: (NSString*)data) {
|
||||||
[_manager respondErrorWithResponderId:responderId data:data];
|
[_manager respondErrorWithResponderId:responderId data:data];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import <FlipperKit/FlipperPlugin.h>
|
|
||||||
#import <FlipperKit/FlipperConnection.h>
|
#import <FlipperKit/FlipperConnection.h>
|
||||||
|
#import <FlipperKit/FlipperPlugin.h>
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
|||||||
@@ -12,16 +12,14 @@
|
|||||||
|
|
||||||
#import "FlipperModule.h"
|
#import "FlipperModule.h"
|
||||||
|
|
||||||
@implementation FlipperReactNativeJavaScriptPlugin
|
@implementation FlipperReactNativeJavaScriptPlugin {
|
||||||
{
|
|
||||||
NSString* _pluginId;
|
NSString* _pluginId;
|
||||||
BOOL _inBackground;
|
BOOL _inBackground;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithFlipperModule:(FlipperModule*)module
|
- (instancetype)initWithFlipperModule:(FlipperModule*)module
|
||||||
pluginId:(NSString*)pluginId
|
pluginId:(NSString*)pluginId
|
||||||
inBackground:(BOOL)inBackground
|
inBackground:(BOOL)inBackground {
|
||||||
{
|
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
_module = module;
|
_module = module;
|
||||||
_pluginId = pluginId;
|
_pluginId = pluginId;
|
||||||
@@ -30,42 +28,35 @@
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)identifier
|
- (NSString*)identifier {
|
||||||
{
|
|
||||||
return _pluginId;
|
return _pluginId;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)runInBackground
|
- (BOOL)runInBackground {
|
||||||
{
|
|
||||||
return _inBackground;
|
return _inBackground;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)didConnect:(id<FlipperConnection>)connection
|
- (void)didConnect:(id<FlipperConnection>)connection {
|
||||||
{
|
|
||||||
_connection = connection;
|
_connection = connection;
|
||||||
[self fireOnConnect];
|
[self fireOnConnect];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)didDisconnect
|
- (void)didDisconnect {
|
||||||
{
|
|
||||||
_connection = nil;
|
_connection = nil;
|
||||||
[_module sendEventWithName:@"react-native-flipper-plugin-disconnect"
|
[_module sendEventWithName:@"react-native-flipper-plugin-disconnect"
|
||||||
body:[self pluginParams]];
|
body:[self pluginParams]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)isConnected
|
- (BOOL)isConnected {
|
||||||
{
|
|
||||||
return _connection != nil;
|
return _connection != nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)fireOnConnect
|
- (void)fireOnConnect {
|
||||||
{
|
|
||||||
[_module sendEventWithName:@"react-native-flipper-plugin-connect"
|
[_module sendEventWithName:@"react-native-flipper-plugin-connect"
|
||||||
body:[self pluginParams]];
|
body:[self pluginParams]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)pluginParams
|
- (id)pluginParams {
|
||||||
{
|
|
||||||
return @{@"plugin" : _pluginId};
|
return @{@"plugin" : _pluginId};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
inBackground:(BOOL)inBackground
|
inBackground:(BOOL)inBackground
|
||||||
statusCallback:(RCTResponseSenderBlock)statusCallback;
|
statusCallback:(RCTResponseSenderBlock)statusCallback;
|
||||||
|
|
||||||
- (void)sendWithPluginId:(NSString *)pluginId method:(NSString *)method data:(NSString *)data;
|
- (void)sendWithPluginId:(NSString*)pluginId
|
||||||
|
method:(NSString*)method
|
||||||
|
data:(NSString*)data;
|
||||||
|
|
||||||
- (void)reportErrorWithMetadata:(NSString*)reason
|
- (void)reportErrorWithMetadata:(NSString*)reason
|
||||||
stackTrace:(NSString*)stackTrace
|
stackTrace:(NSString*)stackTrace
|
||||||
@@ -34,7 +36,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
pluginId:(NSString*)pluginId
|
pluginId:(NSString*)pluginId
|
||||||
method:(NSString*)method;
|
method:(NSString*)method;
|
||||||
|
|
||||||
- (void)respondSuccessWithResponderId:(NSString *)responderId data:(NSString *)data;
|
- (void)respondSuccessWithResponderId:(NSString*)responderId
|
||||||
|
data:(NSString*)data;
|
||||||
|
|
||||||
- (void)respondErrorWithResponderId:(NSString*)responderId data:(NSString*)data;
|
- (void)respondErrorWithResponderId:(NSString*)responderId data:(NSString*)data;
|
||||||
|
|
||||||
|
|||||||
@@ -5,24 +5,21 @@
|
|||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#import "FlipperReactNativeJavaScriptPluginManager.h"
|
#import "FlipperReactNativeJavaScriptPluginManager.h"
|
||||||
#import <FlipperKit/FlipperPlugin.h>
|
|
||||||
#import <FlipperKit/FlipperClient.h>
|
#import <FlipperKit/FlipperClient.h>
|
||||||
|
#import <FlipperKit/FlipperPlugin.h>
|
||||||
#import <React/RCTUtils.h>
|
#import <React/RCTUtils.h>
|
||||||
#import "FlipperModule.h"
|
#import "FlipperModule.h"
|
||||||
#import "FlipperReactNativeJavaScriptPlugin.h"
|
#import "FlipperReactNativeJavaScriptPlugin.h"
|
||||||
|
|
||||||
static uint32_t FlipperResponderKeyGenerator = 0;
|
static uint32_t FlipperResponderKeyGenerator = 0;
|
||||||
|
|
||||||
@implementation FlipperReactNativeJavaScriptPluginManager
|
@implementation FlipperReactNativeJavaScriptPluginManager {
|
||||||
{
|
|
||||||
__weak FlipperClient* _flipperClient;
|
__weak FlipperClient* _flipperClient;
|
||||||
NSMutableDictionary<NSString*, id<FlipperResponder>>* _responders;
|
NSMutableDictionary<NSString*, id<FlipperResponder>>* _responders;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (instancetype)sharedInstance
|
+ (instancetype)sharedInstance {
|
||||||
{
|
|
||||||
static FlipperReactNativeJavaScriptPluginManager* sharedInstance = nil;
|
static FlipperReactNativeJavaScriptPluginManager* sharedInstance = nil;
|
||||||
static dispatch_once_t onceToken;
|
static dispatch_once_t onceToken;
|
||||||
dispatch_once(&onceToken, ^{
|
dispatch_once(&onceToken, ^{
|
||||||
@@ -31,8 +28,7 @@ static uint32_t FlipperResponderKeyGenerator = 0;
|
|||||||
return sharedInstance;
|
return sharedInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)init
|
- (instancetype)init {
|
||||||
{
|
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
_flipperClient = [FlipperClient sharedClient];
|
_flipperClient = [FlipperClient sharedClient];
|
||||||
_responders = [NSMutableDictionary new];
|
_responders = [NSMutableDictionary new];
|
||||||
@@ -43,15 +39,15 @@ static uint32_t FlipperResponderKeyGenerator = 0;
|
|||||||
- (void)registerPluginWithModule:(FlipperModule*)module
|
- (void)registerPluginWithModule:(FlipperModule*)module
|
||||||
pluginId:(NSString*)pluginId
|
pluginId:(NSString*)pluginId
|
||||||
inBackground:(BOOL)inBackground
|
inBackground:(BOOL)inBackground
|
||||||
statusCallback:(RCTResponseSenderBlock)statusCallback
|
statusCallback:(RCTResponseSenderBlock)statusCallback {
|
||||||
{
|
|
||||||
if (_flipperClient == nil) {
|
if (_flipperClient == nil) {
|
||||||
// Flipper is not available in this build
|
// Flipper is not available in this build
|
||||||
statusCallback(@[ @"noflipper" ]);
|
statusCallback(@[ @"noflipper" ]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FlipperReactNativeJavaScriptPlugin *existingPlugin = [self jsPluginWithIdentifier:pluginId];
|
FlipperReactNativeJavaScriptPlugin* existingPlugin =
|
||||||
|
[self jsPluginWithIdentifier:pluginId];
|
||||||
if (existingPlugin != nil) {
|
if (existingPlugin != nil) {
|
||||||
existingPlugin.module = module;
|
existingPlugin.module = module;
|
||||||
|
|
||||||
@@ -64,29 +60,31 @@ static uint32_t FlipperResponderKeyGenerator = 0;
|
|||||||
}
|
}
|
||||||
|
|
||||||
FlipperReactNativeJavaScriptPlugin* newPlugin =
|
FlipperReactNativeJavaScriptPlugin* newPlugin =
|
||||||
[[FlipperReactNativeJavaScriptPlugin alloc] initWithFlipperModule:module
|
[[FlipperReactNativeJavaScriptPlugin alloc]
|
||||||
|
initWithFlipperModule:module
|
||||||
pluginId:pluginId
|
pluginId:pluginId
|
||||||
inBackground:inBackground];
|
inBackground:inBackground];
|
||||||
[_flipperClient addPlugin:newPlugin];
|
[_flipperClient addPlugin:newPlugin];
|
||||||
statusCallback(@[ @"ok" ]);
|
statusCallback(@[ @"ok" ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)sendWithPluginId:(NSString *)pluginId method:(NSString *)method data:(NSString *)data
|
- (void)sendWithPluginId:(NSString*)pluginId
|
||||||
{
|
method:(NSString*)method
|
||||||
[[self jsPluginWithIdentifier:pluginId].connection send:method
|
data:(NSString*)data {
|
||||||
|
[[self jsPluginWithIdentifier:pluginId].connection
|
||||||
|
send:method
|
||||||
withParams:RCTJSONParse(data, NULL)];
|
withParams:RCTJSONParse(data, NULL)];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)reportErrorWithMetadata:(NSString*)reason
|
- (void)reportErrorWithMetadata:(NSString*)reason
|
||||||
stackTrace:(NSString*)stackTrace
|
stackTrace:(NSString*)stackTrace
|
||||||
pluginId:(NSString *)pluginId
|
pluginId:(NSString*)pluginId {
|
||||||
{
|
[[self jsPluginWithIdentifier:pluginId].connection
|
||||||
[[self jsPluginWithIdentifier:pluginId].connection errorWithMessage:reason stackTrace:stackTrace];
|
errorWithMessage:reason
|
||||||
|
stackTrace:stackTrace];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)reportError:(NSString *)error pluginId:(NSString *)pluginId
|
- (void)reportError:(NSString*)error pluginId:(NSString*)pluginId {
|
||||||
{
|
|
||||||
|
|
||||||
// Stacktrace
|
// Stacktrace
|
||||||
NSMutableArray<NSString*>* callstack = NSThread.callStackSymbols.mutableCopy;
|
NSMutableArray<NSString*>* callstack = NSThread.callStackSymbols.mutableCopy;
|
||||||
NSMutableString* callstackString = callstack.firstObject.mutableCopy;
|
NSMutableString* callstackString = callstack.firstObject.mutableCopy;
|
||||||
@@ -95,50 +93,57 @@ static uint32_t FlipperResponderKeyGenerator = 0;
|
|||||||
[callstackString appendFormat:@"\n %@", stack];
|
[callstackString appendFormat:@"\n %@", stack];
|
||||||
}
|
}
|
||||||
|
|
||||||
[[self jsPluginWithIdentifier:pluginId].connection errorWithMessage:error stackTrace:callstackString];
|
[[self jsPluginWithIdentifier:pluginId].connection
|
||||||
|
errorWithMessage:error
|
||||||
|
stackTrace:callstackString];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)subscribeWithModule:(FlipperModule*)module
|
- (void)subscribeWithModule:(FlipperModule*)module
|
||||||
pluginId:(NSString*)pluginId
|
pluginId:(NSString*)pluginId
|
||||||
method:(NSString *)method
|
method:(NSString*)method {
|
||||||
{
|
|
||||||
__weak __typeof(self) weakSelf = self;
|
__weak __typeof(self) weakSelf = self;
|
||||||
[[self jsPluginWithIdentifier: pluginId].connection receive:method withBlock:^(NSDictionary * params, id<FlipperResponder> responder) {
|
[[self jsPluginWithIdentifier:pluginId].connection
|
||||||
|
receive:method
|
||||||
|
withBlock:^(NSDictionary* params, id<FlipperResponder> responder) {
|
||||||
__typeof(self) strongSelf = weakSelf;
|
__typeof(self) strongSelf = weakSelf;
|
||||||
|
|
||||||
NSMutableDictionary *body = [NSMutableDictionary dictionaryWithDictionary:@{
|
NSMutableDictionary* body =
|
||||||
|
[NSMutableDictionary dictionaryWithDictionary:@{
|
||||||
@"plugin" : pluginId,
|
@"plugin" : pluginId,
|
||||||
@"method" : method,
|
@"method" : method,
|
||||||
@"params" : RCTJSONStringify(params, NULL),
|
@"params" : RCTJSONStringify(params, NULL),
|
||||||
}];
|
}];
|
||||||
|
|
||||||
if (responder != nil) {
|
if (responder != nil) {
|
||||||
NSString *responderId = [NSString stringWithFormat:@"%d", FlipperResponderKeyGenerator++];
|
NSString* responderId =
|
||||||
|
[NSString stringWithFormat:@"%d", FlipperResponderKeyGenerator++];
|
||||||
strongSelf->_responders[responderId] = responder;
|
strongSelf->_responders[responderId] = responder;
|
||||||
body[@"responderId"] = responderId;
|
body[@"responderId"] = responderId;
|
||||||
}
|
}
|
||||||
|
|
||||||
[module sendEventWithName:@"react-native-flipper-receive-event" body:body];
|
[module sendEventWithName:@"react-native-flipper-receive-event"
|
||||||
|
body:body];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)respondSuccessWithResponderId:(NSString *)responderId data:(NSString *)data
|
- (void)respondSuccessWithResponderId:(NSString*)responderId
|
||||||
{
|
data:(NSString*)data {
|
||||||
id<FlipperResponder> responder = _responders[responderId];
|
id<FlipperResponder> responder = _responders[responderId];
|
||||||
[responder success:RCTJSONParse(data, NULL)];
|
[responder success:RCTJSONParse(data, NULL)];
|
||||||
[_responders removeObjectForKey:responderId];
|
[_responders removeObjectForKey:responderId];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)respondErrorWithResponderId:(NSString *)responderId data:(NSString *)data
|
- (void)respondErrorWithResponderId:(NSString*)responderId
|
||||||
{
|
data:(NSString*)data {
|
||||||
id<FlipperResponder> responder = _responders[responderId];
|
id<FlipperResponder> responder = _responders[responderId];
|
||||||
[responder error:RCTJSONParse(data, NULL)];
|
[responder error:RCTJSONParse(data, NULL)];
|
||||||
[_responders removeObjectForKey:responderId];
|
[_responders removeObjectForKey:responderId];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (FlipperReactNativeJavaScriptPlugin *)jsPluginWithIdentifier:(NSString *)pluginId
|
- (FlipperReactNativeJavaScriptPlugin*)jsPluginWithIdentifier:
|
||||||
{
|
(NSString*)pluginId {
|
||||||
return (FlipperReactNativeJavaScriptPlugin *)[_flipperClient pluginWithIdentifier:pluginId];
|
return (FlipperReactNativeJavaScriptPlugin*)[_flipperClient
|
||||||
|
pluginWithIdentifier:pluginId];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
Reference in New Issue
Block a user