diff --git a/Libraries/CameraRoll/RCTCameraRollManager.m b/Libraries/CameraRoll/RCTCameraRollManager.m index f8e6346df6..64cf734b1a 100644 --- a/Libraries/CameraRoll/RCTCameraRollManager.m +++ b/Libraries/CameraRoll/RCTCameraRollManager.m @@ -80,8 +80,8 @@ RCT_EXPORT_MODULE() @synthesize bridge = _bridge; -NSString *const RCTErrorUnableToLoad = @"E_UNABLE_TO_LOAD"; -NSString *const RCTErrorUnableToSave = @"E_UNABLE_TO_SAVE"; +static NSString *const kErrorUnableToLoad = @"E_UNABLE_TO_LOAD"; +static NSString *const kErrorUnableToSave = @"E_UNABLE_TO_SAVE"; RCT_EXPORT_METHOD(saveToCameraRoll:(NSURLRequest *)request type:(NSString *)type @@ -93,7 +93,7 @@ RCT_EXPORT_METHOD(saveToCameraRoll:(NSURLRequest *)request dispatch_async(dispatch_get_main_queue(), ^{ [self->_bridge.assetsLibrary writeVideoAtPathToSavedPhotosAlbum:request.URL completionBlock:^(NSURL *assetURL, NSError *saveError) { if (saveError) { - reject(RCTErrorUnableToSave, nil, saveError); + reject(kErrorUnableToSave, nil, saveError); } else { resolve(assetURL.absoluteString); } @@ -103,7 +103,7 @@ RCT_EXPORT_METHOD(saveToCameraRoll:(NSURLRequest *)request [_bridge.imageLoader loadImageWithURLRequest:request callback:^(NSError *loadError, UIImage *loadedImage) { if (loadError) { - reject(RCTErrorUnableToLoad, nil, loadError); + reject(kErrorUnableToLoad, nil, loadError); return; } // It's unclear if writeImageToSavedPhotosAlbum is thread-safe @@ -111,7 +111,7 @@ RCT_EXPORT_METHOD(saveToCameraRoll:(NSURLRequest *)request [self->_bridge.assetsLibrary writeImageToSavedPhotosAlbum:loadedImage.CGImage metadata:nil completionBlock:^(NSURL *assetURL, NSError *saveError) { if (saveError) { RCTLogWarn(@"Error saving cropped image: %@", saveError); - reject(RCTErrorUnableToSave, nil, saveError); + reject(kErrorUnableToSave, nil, saveError); } else { resolve(assetURL.absoluteString); } @@ -230,7 +230,7 @@ RCT_EXPORT_METHOD(getPhotos:(NSDictionary *)params if (error.code != ALAssetsLibraryAccessUserDeniedError) { RCTLogError(@"Failure while iterating through asset groups %@", error); } - reject(RCTErrorUnableToLoad, nil, error); + reject(kErrorUnableToLoad, nil, error); }]; } diff --git a/Libraries/LinkingIOS/RCTLinkingManager.m b/Libraries/LinkingIOS/RCTLinkingManager.m index b156ab26a5..51a2896cfe 100644 --- a/Libraries/LinkingIOS/RCTLinkingManager.m +++ b/Libraries/LinkingIOS/RCTLinkingManager.m @@ -13,15 +13,14 @@ #import #import -NSString *const RCTOpenURLNotification = @"RCTOpenURLNotification"; - +static NSString *const kOpenURLNotification = @"RCTOpenURLNotification"; static void postNotificationWithURL(NSURL *URL, id sender) { NSDictionary *payload = @{@"url": URL.absoluteString}; - [[NSNotificationCenter defaultCenter] postNotificationName:RCTOpenURLNotification - object:sender - userInfo:payload]; + [[NSNotificationCenter defaultCenter] postNotificationName:kOpenURLNotification + object:sender + userInfo:payload]; } @implementation RCTLinkingManager @@ -37,7 +36,7 @@ RCT_EXPORT_MODULE() { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURLNotification:) - name:RCTOpenURLNotification + name:kOpenURLNotification object:nil]; } @@ -74,7 +73,7 @@ continueUserActivity:(NSUserActivity *)userActivity { if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) { NSDictionary *payload = @{@"url": userActivity.webpageURL.absoluteString}; - [[NSNotificationCenter defaultCenter] postNotificationName:RCTOpenURLNotification + [[NSNotificationCenter defaultCenter] postNotificationName:kOpenURLNotification object:self userInfo:payload]; } diff --git a/Libraries/PushNotificationIOS/RCTPushNotificationManager.m b/Libraries/PushNotificationIOS/RCTPushNotificationManager.m index cdb8bd5802..29656e01a5 100644 --- a/Libraries/PushNotificationIOS/RCTPushNotificationManager.m +++ b/Libraries/PushNotificationIOS/RCTPushNotificationManager.m @@ -16,13 +16,14 @@ #import #import -NSString *const RCTLocalNotificationReceived = @"LocalNotificationReceived"; NSString *const RCTRemoteNotificationReceived = @"RemoteNotificationReceived"; -NSString *const RCTRemoteNotificationsRegistered = @"RemoteNotificationsRegistered"; -NSString *const RCTRegisterUserNotificationSettings = @"RegisterUserNotificationSettings"; -NSString *const RCTErrorUnableToRequestPermissions = @"E_UNABLE_TO_REQUEST_PERMISSIONS"; -NSString *const RCTErrorRemoteNotificationRegistrationFailed = @"E_FAILED_TO_REGISTER_FOR_REMOTE_NOTIFICATIONS"; +static NSString *const kLocalNotificationReceived = @"LocalNotificationReceived"; +static NSString *const kRemoteNotificationsRegistered = @"RemoteNotificationsRegistered"; +static NSString *const kRegisterUserNotificationSettings = @"RegisterUserNotificationSettings"; +static NSString *const kRemoteNotificationRegistrationFailed = @"RemoteNotificationRegistrationFailed"; + +static NSString *const kErrorUnableToRequestPermissions = @"E_UNABLE_TO_REQUEST_PERMISSIONS"; #if !TARGET_OS_TV @implementation RCTConvert (NSCalendarUnit) @@ -139,7 +140,7 @@ RCT_EXPORT_MODULE() { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleLocalNotificationReceived:) - name:RCTLocalNotificationReceived + name:kLocalNotificationReceived object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleRemoteNotificationReceived:) @@ -147,15 +148,15 @@ RCT_EXPORT_MODULE() object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleRegisterUserNotificationSettings:) - name:RCTRegisterUserNotificationSettings + name:kRegisterUserNotificationSettings object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleRemoteNotificationsRegistered:) - name:RCTRemoteNotificationsRegistered + name:kRemoteNotificationsRegistered object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleRemoteNotificationRegistrationError:) - name:RCTErrorRemoteNotificationRegistrationFailed + name:kRemoteNotificationRegistrationFailed object:nil]; } @@ -176,7 +177,7 @@ RCT_EXPORT_MODULE() { if ([UIApplication instancesRespondToSelector:@selector(registerForRemoteNotifications)]) { [RCTSharedApplication() registerForRemoteNotifications]; - [[NSNotificationCenter defaultCenter] postNotificationName:RCTRegisterUserNotificationSettings + [[NSNotificationCenter defaultCenter] postNotificationName:kRegisterUserNotificationSettings object:self userInfo:@{@"notificationSettings": notificationSettings}]; } @@ -190,14 +191,14 @@ RCT_EXPORT_MODULE() for (NSUInteger i = 0; i < deviceTokenLength; i++) { [hexString appendFormat:@"%02x", bytes[i]]; } - [[NSNotificationCenter defaultCenter] postNotificationName:RCTRemoteNotificationsRegistered + [[NSNotificationCenter defaultCenter] postNotificationName:kRemoteNotificationsRegistered object:self userInfo:@{@"deviceToken" : [hexString copy]}]; } + (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { - [[NSNotificationCenter defaultCenter] postNotificationName:RCTErrorRemoteNotificationRegistrationFailed + [[NSNotificationCenter defaultCenter] postNotificationName:kRemoteNotificationRegistrationFailed object:self userInfo:@{@"error": error}]; } @@ -221,7 +222,7 @@ RCT_EXPORT_MODULE() + (void)didReceiveLocalNotification:(UILocalNotification *)notification { - [[NSNotificationCenter defaultCenter] postNotificationName:RCTLocalNotificationReceived + [[NSNotificationCenter defaultCenter] postNotificationName:kLocalNotificationReceived object:self userInfo:RCTFormatLocalNotification(notification)]; } @@ -315,7 +316,7 @@ RCT_EXPORT_METHOD(requestPermissions:(NSDictionary *)permissions rejecter:(RCTPromiseRejectBlock)reject) { if (RCTRunningInAppExtension()) { - reject(RCTErrorUnableToRequestPermissions, nil, RCTErrorWithMessage(@"Requesting push notifications is currently unavailable in an app extension")); + reject(kErrorUnableToRequestPermissions, nil, RCTErrorWithMessage(@"Requesting push notifications is currently unavailable in an app extension")); return; } diff --git a/Libraries/Text/RCTShadowText.m b/Libraries/Text/RCTShadowText.m index 1a0e7980bb..f7fb71110b 100644 --- a/Libraries/Text/RCTShadowText.m +++ b/Libraries/Text/RCTShadowText.m @@ -22,14 +22,14 @@ #import "RCTText.h" #import "RCTTextView.h" -NSString *const RCTShadowViewAttributeName = @"RCTShadowViewAttributeName"; NSString *const RCTIsHighlightedAttributeName = @"IsHighlightedAttributeName"; NSString *const RCTReactTagAttributeName = @"ReactTagAttributeName"; -CGFloat const RCTTextAutoSizeDefaultMinimumFontScale = 0.5f; -CGFloat const RCTTextAutoSizeWidthErrorMargin = 0.05f; -CGFloat const RCTTextAutoSizeHeightErrorMargin = 0.025f; -CGFloat const RCTTextAutoSizeGranularity = 0.001f; +static NSString *const kShadowViewAttributeName = @"RCTShadowViewAttributeName"; + +static CGFloat const kAutoSizeWidthErrorMargin = 0.05f; +static CGFloat const kAutoSizeHeightErrorMargin = 0.025f; +static CGFloat const kAutoSizeGranularity = 0.001f; @implementation RCTShadowText { @@ -165,7 +165,7 @@ static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, f NSTextContainer *textContainer = layoutManager.textContainers.firstObject; NSRange glyphRange = [layoutManager glyphRangeForTextContainer:textContainer]; NSRange characterRange = [layoutManager characterRangeForGlyphRange:glyphRange actualGlyphRange:NULL]; - [layoutManager.textStorage enumerateAttribute:RCTShadowViewAttributeName inRange:characterRange options:0 usingBlock:^(RCTShadowView *child, NSRange range, BOOL *_) { + [layoutManager.textStorage enumerateAttribute:kShadowViewAttributeName inRange:characterRange options:0 usingBlock:^(RCTShadowView *child, NSRange range, BOOL *_) { if (child) { YGNodeRef childNode = child.yogaNode; float width = YGNodeStyleGetWidth(childNode).value; @@ -334,7 +334,7 @@ static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, f attachment.bounds = (CGRect){CGPointZero, {width, height}}; NSMutableAttributedString *attachmentString = [NSMutableAttributedString new]; [attachmentString appendAttributedString:[NSAttributedString attributedStringWithAttachment:attachment]]; - [attachmentString addAttribute:RCTShadowViewAttributeName value:child range:(NSRange){0, attachmentString.length}]; + [attachmentString addAttribute:kShadowViewAttributeName value:child range:(NSRange){0, attachmentString.length}]; [attributedString appendAttributedString:attachmentString]; if (height > heightOfTallestSubview) { heightOfTallestSubview = height; @@ -516,7 +516,7 @@ static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, f prevMid:(CGFloat)prevMid { CGFloat midScale = (minScale + maxScale) / 2.0f; - if (round((prevMid / RCTTextAutoSizeGranularity)) == round((midScale / RCTTextAutoSizeGranularity))) { + if (round((prevMid / kAutoSizeGranularity)) == round((midScale / kAutoSizeGranularity))) { //Bail because we can't meet error margin. return [self calculateSize:textStorage]; } else { @@ -529,12 +529,12 @@ static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, f return [self calculateOptimumScaleInFrame:frame forStorage:textStorage minScale:minScale - maxScale:midScale - RCTTextAutoSizeGranularity + maxScale:midScale - kAutoSizeGranularity prevMid:midScale]; } else { return [self calculateOptimumScaleInFrame:frame forStorage:textStorage - minScale:midScale + RCTTextAutoSizeGranularity + minScale:midScale + kAutoSizeGranularity maxScale:maxScale prevMid:midScale]; } @@ -577,8 +577,8 @@ static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, f textContainer.maximumNumberOfLines == 0; if (fitLines && fitSize) { - if ((requiredSize.width + (CGRectGetWidth(frame) * RCTTextAutoSizeWidthErrorMargin)) > CGRectGetWidth(frame) && - (requiredSize.height + (CGRectGetHeight(frame) * RCTTextAutoSizeHeightErrorMargin)) > CGRectGetHeight(frame)) + if ((requiredSize.width + (CGRectGetWidth(frame) * kAutoSizeWidthErrorMargin)) > CGRectGetWidth(frame) && + (requiredSize.height + (CGRectGetHeight(frame) * kAutoSizeHeightErrorMargin)) > CGRectGetHeight(frame)) { return RCTSizeWithinRange; } else { diff --git a/React/Modules/RCTDevSettings.mm b/React/Modules/RCTDevSettings.mm index 7854c23218..893c6acd4a 100644 --- a/React/Modules/RCTDevSettings.mm +++ b/React/Modules/RCTDevSettings.mm @@ -24,17 +24,17 @@ #import "RCTProfile.h" #import "RCTUtils.h" -NSString *const kRCTDevSettingProfilingEnabled = @"profilingEnabled"; -NSString *const kRCTDevSettingHotLoadingEnabled = @"hotLoadingEnabled"; -NSString *const kRCTDevSettingLiveReloadEnabled = @"liveReloadEnabled"; -NSString *const kRCTDevSettingIsInspectorShown = @"showInspector"; -NSString *const kRCTDevSettingIsDebuggingRemotely = @"isDebuggingRemotely"; -NSString *const kRCTDevSettingExecutorOverrideClass = @"executor-override"; -NSString *const kRCTDevSettingShakeToShowDevMenu = @"shakeToShow"; -NSString *const kRCTDevSettingIsPerfMonitorShown = @"RCTPerfMonitorKey"; -NSString *const kRCTDevSettingStartSamplingProfilerOnLaunch = @"startSamplingProfilerOnLaunch"; +static NSString *const kRCTDevSettingProfilingEnabled = @"profilingEnabled"; +static NSString *const kRCTDevSettingHotLoadingEnabled = @"hotLoadingEnabled"; +static NSString *const kRCTDevSettingLiveReloadEnabled = @"liveReloadEnabled"; +static NSString *const kRCTDevSettingIsInspectorShown = @"showInspector"; +static NSString *const kRCTDevSettingIsDebuggingRemotely = @"isDebuggingRemotely"; +static NSString *const kRCTDevSettingExecutorOverrideClass = @"executor-override"; +static NSString *const kRCTDevSettingShakeToShowDevMenu = @"shakeToShow"; +static NSString *const kRCTDevSettingIsPerfMonitorShown = @"RCTPerfMonitorKey"; +static NSString *const kRCTDevSettingStartSamplingProfilerOnLaunch = @"startSamplingProfilerOnLaunch"; -NSString *const kRCTDevSettingsUserDefaultsKey = @"RCTDevMenu"; +static NSString *const kRCTDevSettingsUserDefaultsKey = @"RCTDevMenu"; #define ENABLE_PACKAGER_CONNECTION RCT_DEV && __has_include("RCTPackagerConnection.h") diff --git a/React/Profiler/RCTProfile.m b/React/Profiler/RCTProfile.m index 9b65302f78..10ce571281 100644 --- a/React/Profiler/RCTProfile.m +++ b/React/Profiler/RCTProfile.m @@ -36,9 +36,9 @@ const uint64_t RCTProfileTagAlways = 1L << 0; #pragma mark - Constants -NSString *const RCTProfileTraceEvents = @"traceEvents"; -NSString *const RCTProfileSamples = @"samples"; -NSString *const RCTProfilePrefix = @"rct_profile_"; +static NSString *const kProfileTraceEvents = @"traceEvents"; +static NSString *const kProfileSamples = @"samples"; +static NSString *const kProfilePrefix = @"rct_profile_"; #pragma mark - Variables @@ -135,7 +135,7 @@ static NSDictionary *RCTProfileGetMemoryUsage(void) static const char *RCTProfileProxyClassName(Class class) { - return [RCTProfilePrefix stringByAppendingString:NSStringFromClass(class)].UTF8String; + return [kProfilePrefix stringByAppendingString:NSStringFromClass(class)].UTF8String; } static dispatch_group_t RCTProfileGetUnhookGroup(void) @@ -459,8 +459,8 @@ void RCTProfileInit(RCTBridge *bridge) RCTProfileStartTime = time; RCTProfileOngoingEvents = [NSMutableDictionary new]; RCTProfileInfo = @{ - RCTProfileTraceEvents: [NSMutableArray new], - RCTProfileSamples: [NSMutableArray new], + kProfileTraceEvents: [NSMutableArray new], + kProfileSamples: [NSMutableArray new], }; }); } @@ -470,7 +470,7 @@ void RCTProfileInit(RCTBridge *bridge) NSArray *orderedThreads = @[@"JS async", @"RCTPerformanceLogger", @"com.facebook.react.JavaScript", @(RCTUIManagerQueueName), @"main"]; [orderedThreads enumerateObjectsUsingBlock:^(NSString *thread, NSUInteger idx, __unused BOOL *stop) { - RCTProfileAddEvent(RCTProfileTraceEvents, + RCTProfileAddEvent(kProfileTraceEvents, @"ph": @"M", // metadata event @"name": @"thread_sort_index", @"tid": thread, @@ -587,7 +587,7 @@ void _RCTProfileEndEvent( } NSNumber *start = event[0]; - RCTProfileAddEvent(RCTProfileTraceEvents, + RCTProfileAddEvent(kProfileTraceEvents, @"tid": threadName, @"name": event[1], @"cat": category, @@ -650,7 +650,7 @@ void RCTProfileEndAsyncEvent( if (event) { NSNumber *endTimestamp = RCTProfileTimestamp(time); - RCTProfileAddEvent(RCTProfileTraceEvents, + RCTProfileAddEvent(kProfileTraceEvents, @"tid": threadName, @"name": event[1], @"cat": category, @@ -680,7 +680,7 @@ void RCTProfileImmediateEvent( NSString *threadName = RCTCurrentThreadName(); dispatch_async(RCTProfileGetQueue(), ^{ - RCTProfileAddEvent(RCTProfileTraceEvents, + RCTProfileAddEvent(kProfileTraceEvents, @"tid": threadName, @"name": name, @"ts": RCTProfileTimestamp(time), @@ -707,7 +707,7 @@ NSUInteger _RCTProfileBeginFlowEvent(void) NSString *threadName = RCTCurrentThreadName(); dispatch_async(RCTProfileGetQueue(), ^{ - RCTProfileAddEvent(RCTProfileTraceEvents, + RCTProfileAddEvent(kProfileTraceEvents, @"tid": threadName, @"name": @"flow", @"id": @(cookie), @@ -734,7 +734,7 @@ void _RCTProfileEndFlowEvent(NSUInteger cookie) NSString *threadName = RCTCurrentThreadName(); dispatch_async(RCTProfileGetQueue(), ^{ - RCTProfileAddEvent(RCTProfileTraceEvents, + RCTProfileAddEvent(kProfileTraceEvents, @"tid": threadName, @"name": @"flow", @"id": @(cookie), diff --git a/React/Views/RCTWebView.m b/React/Views/RCTWebView.m index 2096064458..e4452ecda7 100644 --- a/React/Views/RCTWebView.m +++ b/React/Views/RCTWebView.m @@ -20,7 +20,8 @@ #import "UIView+React.h" NSString *const RCTJSNavigationScheme = @"react-js-navigation"; -NSString *const RCTJSPostMessageHost = @"postMessage"; + +static NSString *const kPostMessageHost = @"postMessage"; @interface RCTWebView () @@ -240,7 +241,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) } } - if (isJSNavigation && [request.URL.host isEqualToString:RCTJSPostMessageHost]) { + if (isJSNavigation && [request.URL.host isEqualToString:kPostMessageHost]) { NSString *data = request.URL.query; data = [data stringByReplacingOccurrencesOfString:@"+" withString:@" "]; data = [data stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; @@ -303,7 +304,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) @"window.originalPostMessage = window.postMessage;" "window.postMessage = function(data) {" "window.location = '%@://%@?' + encodeURIComponent(String(data));" - "};", RCTJSNavigationScheme, RCTJSPostMessageHost + "};", RCTJSNavigationScheme, kPostMessageHost ]; [webView stringByEvaluatingJavaScriptFromString:source]; }