mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-28 20:25:33 +08:00
[ReactNative] Use RCTNullIfNill and (id)kCFNull
Summary: @public Use consistent `null` handling: `value || null` -> `RCTNullIfNil(value)` `value == null ? nil : value` -> `RCTNilIfNull(value)` `[NSNull null]` -> `(id)kCFNull` Test Plan: The tests should be enough.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#import "RCTActionSheetManager.h"
|
||||
|
||||
#import "RCTLog.h"
|
||||
#import "RCTUtils.h"
|
||||
|
||||
@interface RCTActionSheetManager () <UIActionSheetDelegate>
|
||||
|
||||
@@ -90,7 +91,7 @@ RCT_EXPORT_METHOD(showShareActionSheetWithOptions:(NSDictionary *)options
|
||||
if (activityError) {
|
||||
failureCallback(@[[activityError localizedDescription]]);
|
||||
} else {
|
||||
successCallback(@[@(completed), (activityType ?: [NSNull null])]);
|
||||
successCallback(@[@(completed), RCTNullIfNil(activityType)]);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
@@ -100,7 +101,7 @@ RCT_EXPORT_METHOD(showShareActionSheetWithOptions:(NSDictionary *)options
|
||||
if (![UIActivityViewController instancesRespondToSelector:@selector(completionWithItemsHandler)]) {
|
||||
// Legacy iOS 7 implementation
|
||||
share.completionHandler = ^(NSString *activityType, BOOL completed) {
|
||||
successCallback(@[@(completed), (activityType ?: [NSNull null])]);
|
||||
successCallback(@[@(completed), RCTNullIfNil(activityType)]);
|
||||
};
|
||||
} else
|
||||
|
||||
@@ -109,7 +110,7 @@ RCT_EXPORT_METHOD(showShareActionSheetWithOptions:(NSDictionary *)options
|
||||
{
|
||||
// iOS 8 version
|
||||
share.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
|
||||
successCallback(@[@(completed), (activityType ?: [NSNull null])]);
|
||||
successCallback(@[@(completed), RCTNullIfNil(activityType)]);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#import "RCTBridge.h"
|
||||
#import "RCTEventDispatcher.h"
|
||||
#import "RCTUtils.h"
|
||||
|
||||
NSString *const RCTOpenURLNotification = @"RCTOpenURLNotification";
|
||||
|
||||
@@ -76,7 +77,7 @@ RCT_EXPORT_METHOD(canOpenURL:(NSURL *)URL
|
||||
- (NSDictionary *)constantsToExport
|
||||
{
|
||||
NSURL *initialURL = _bridge.launchOptions[UIApplicationLaunchOptionsURLKey];
|
||||
return @{@"initialURL": [initialURL absoluteString] ?: [NSNull null]};
|
||||
return @{@"initialURL": RCTNullIfNil([initialURL absoluteString])};
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -436,7 +436,7 @@ RCT_EXPORT_MODULE()
|
||||
|
||||
NSArray *responseJSON = @[
|
||||
request.requestID,
|
||||
error.localizedDescription ?: [NSNull null],
|
||||
RCTNullIfNil(error.localizedDescription),
|
||||
];
|
||||
|
||||
[_bridge.eventDispatcher sendDeviceEventWithName:@"didCompleteNetworkResponse"
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#import "RCTBridge.h"
|
||||
#import "RCTEventDispatcher.h"
|
||||
#import "RCTUtils.h"
|
||||
|
||||
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0
|
||||
|
||||
@@ -172,7 +173,7 @@ RCT_EXPORT_METHOD(checkPermissions:(RCTResponseSenderBlock)callback)
|
||||
- (NSDictionary *)constantsToExport
|
||||
{
|
||||
return @{
|
||||
@"initialNotification": _initialNotification ?: [NSNull null]
|
||||
@"initialNotification": RCTNullIfNil(_initialNotification),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#import "RCTEventDispatcher.h"
|
||||
#import "RCTSRWebSocket.h"
|
||||
#import "RCTSparseArray.h"
|
||||
#import "RCTUtils.h"
|
||||
|
||||
@implementation RCTSRWebSocket (React)
|
||||
|
||||
@@ -107,7 +108,7 @@ RCT_EXPORT_METHOD(close:(NSNumber *)socketID)
|
||||
{
|
||||
[_bridge.eventDispatcher sendDeviceEventWithName:@"websocketClosed" body:@{
|
||||
@"code": @(code),
|
||||
@"reason": reason ? reason : [NSNull null],
|
||||
@"reason": RCTNullIfNil(reason),
|
||||
@"clean": @(wasClean),
|
||||
@"id": webSocket.reactTag
|
||||
}];
|
||||
|
||||
Reference in New Issue
Block a user