From 520ad05ba07a3442f88f070458c70db5d1c74cc9 Mon Sep 17 00:00:00 2001 From: Nick Lockwood Date: Thu, 10 Mar 2016 10:20:53 -0800 Subject: [PATCH] Removed unnecessary exportedConstants Summary: The exportedConstants method incurrs a penalty at bridge startup time for every module that implements it. This diff removes exportedConstants from a few modules that don't really need to use it. Reviewed By: majak Differential Revision: D2982341 fb-gh-sync-id: be016187d7b731a073311daacfcf88a0402e1688 shipit-source-id: be016187d7b731a073311daacfcf88a0402e1688 --- Libraries/Components/MapView/MapView.js | 31 +++++++++---------- Libraries/Components/ScrollView/ScrollView.js | 4 +-- .../ScrollView/processDecelerationRate.js | 15 +++------ Libraries/Components/WebView/WebView.ios.js | 22 ++++++------- React/Views/RCTMapManager.m | 29 ----------------- React/Views/RCTScrollViewManager.m | 10 ------ React/Views/RCTWebView.m | 17 ++++++++-- React/Views/RCTWebViewManager.m | 15 --------- 8 files changed, 47 insertions(+), 96 deletions(-) diff --git a/Libraries/Components/MapView/MapView.js b/Libraries/Components/MapView/MapView.js index 13ee06ee8..e78a6d048 100644 --- a/Libraries/Components/MapView/MapView.js +++ b/Libraries/Components/MapView/MapView.js @@ -16,8 +16,6 @@ const EdgeInsetsPropType = require('EdgeInsetsPropType'); const Image = require('Image'); const NativeMethodsMixin = require('NativeMethodsMixin'); const Platform = require('Platform'); -const RCTMapConfig = require('UIManager').RCTMap; -const RCTMapConstants = RCTMapConfig && RCTMapConfig.Constants; const React = require('React'); const StyleSheet = require('StyleSheet'); const View = require('View'); @@ -310,6 +308,21 @@ const MapView = React.createClass({ active: React.PropTypes.bool, }, + statics: { + /** + * Standard iOS MapView pin color constants, to be used with the + * `annotation.tintColor` property. On iOS 8 and earlier these are the + * only supported values when using regular pins. On iOS 9 and later + * you are not obliged to use these, but they are useful for matching + * the standard iOS look and feel. + */ + PinColors: { + RED: '#ff3b30', + GREEN: '#4cd964', + PURPLE: '#c969e0', + }, + }, + render: function() { let children = [], {annotations, overlays, followUserLocation} = this.props; annotations = annotations && annotations.map((annotation: Object) => { @@ -491,20 +504,6 @@ const styles = StyleSheet.create({ }, }); -/** - * Standard iOS MapView pin color constants, to be used with the - * `annotation.tintColor` property. On iOS 8 and earlier these are the - * only supported values when using regular pins. On iOS 9 and later - * you are not obliged to use these, but they are useful for matching - * the standard iOS look and feel. - */ -const PinColors = RCTMapConstants && RCTMapConstants.PinColors; -MapView.PinColors = PinColors && { - RED: PinColors.RED, - GREEN: PinColors.GREEN, - PURPLE: PinColors.PURPLE, -}; - const RCTMap = requireNativeComponent('RCTMap', MapView, { nativeOnly: { onAnnotationDragStateChange: true, diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index dfb9e2b61..d3b375a6c 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -134,8 +134,8 @@ var ScrollView = React.createClass({ * shortcuts `"normal"` and `"fast"` which match the underlying iOS settings * for `UIScrollViewDecelerationRateNormal` and * `UIScrollViewDecelerationRateFast` respectively. - * - Normal: 0.998 (the default) - * - Fast: 0.9 + * - normal: 0.998 (the default) + * - fast: 0.99 * @platform ios */ decelerationRate: PropTypes.oneOfType([ diff --git a/Libraries/Components/ScrollView/processDecelerationRate.js b/Libraries/Components/ScrollView/processDecelerationRate.js index 82be66cef..71955a025 100644 --- a/Libraries/Components/ScrollView/processDecelerationRate.js +++ b/Libraries/Components/ScrollView/processDecelerationRate.js @@ -10,18 +10,11 @@ */ 'use strict'; -var ScrollViewConsts = require('UIManager').RCTScrollView.Constants; - function processDecelerationRate(decelerationRate) { - var ScrollViewDecelerationRateNormal = ScrollViewConsts && ScrollViewConsts.DecelerationRate.normal; - var ScrollViewDecelerationRateFast = ScrollViewConsts && ScrollViewConsts.DecelerationRate.fast; - - if (typeof decelerationRate === 'string') { - if (decelerationRate === 'fast') { - return ScrollViewDecelerationRateFast; - } else if (decelerationRate === 'normal') { - return ScrollViewDecelerationRateNormal; - } + if (decelerationRate === 'normal') { + decelerationRate = 0.998; + } else if (decelerationRate === 'fast') { + decelerationRate = 0.99; } return decelerationRate; } diff --git a/Libraries/Components/WebView/WebView.ios.js b/Libraries/Components/WebView/WebView.ios.js index 9fc11a5c5..653bff61e 100644 --- a/Libraries/Components/WebView/WebView.ios.js +++ b/Libraries/Components/WebView/WebView.ios.js @@ -39,16 +39,16 @@ var WebViewState = keyMirror({ ERROR: null, }); -var NavigationType = { - click: RCTWebViewManager.NavigationType.LinkClicked, - formsubmit: RCTWebViewManager.NavigationType.FormSubmitted, - backforward: RCTWebViewManager.NavigationType.BackForward, - reload: RCTWebViewManager.NavigationType.Reload, - formresubmit: RCTWebViewManager.NavigationType.FormResubmitted, - other: RCTWebViewManager.NavigationType.Other, -}; +const NavigationType = keyMirror({ + click: true, + formsubmit: true, + backforward: true, + reload: true, + formresubmit: true, + other: true, +}); -var JSNavigationScheme = RCTWebViewManager.JSNavigationScheme; +const JSNavigationScheme = 'react-js-navigation'; type ErrorEvent = { domain: any; @@ -179,8 +179,8 @@ var WebView = React.createClass({ * shortcuts `"normal"` and `"fast"` which match the underlying iOS settings * for `UIScrollViewDecelerationRateNormal` and * `UIScrollViewDecelerationRateFast` respectively. - * - Normal: 0.998 - * - Fast: 0.9 (the default for iOS WebView) + * - normal: 0.998 + * - fast: 0.99 (the default for iOS WebView) * @platform ios */ decelerationRate: ScrollView.propTypes.decelerationRate, diff --git a/React/Views/RCTMapManager.m b/React/Views/RCTMapManager.m index ec4595a5a..ad623c504 100644 --- a/React/Views/RCTMapManager.m +++ b/React/Views/RCTMapManager.m @@ -106,35 +106,6 @@ RCT_CUSTOM_VIEW_PROPERTY(region, MKCoordinateRegion, RCTMap) [view setRegion:json ? [RCTConvert MKCoordinateRegion:json] : defaultView.region animated:YES]; } -- (NSDictionary *)constantsToExport -{ - NSString *red, *green, *purple; - -#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0 - - if (![MKPinAnnotationView respondsToSelector:@selector(redPinColor)]) { - red = RCTMapPinRed; - green = RCTMapPinGreen; - purple = RCTMapPinPurple; - } else - -#endif - - { - red = RCTColorToHexString([MKPinAnnotationView redPinColor].CGColor); - green = RCTColorToHexString([MKPinAnnotationView greenPinColor].CGColor); - purple = RCTColorToHexString([MKPinAnnotationView purplePinColor].CGColor); - } - - return @{ - @"PinColors": @{ - @"RED": red, - @"GREEN": green, - @"PURPLE": purple, - } - }; -} - #pragma mark MKMapViewDelegate - (void)mapView:(RCTMap *)mapView didSelectAnnotationView:(MKAnnotationView *)view diff --git a/React/Views/RCTScrollViewManager.m b/React/Views/RCTScrollViewManager.m index 9ab7ca806..77f916b4e 100644 --- a/React/Views/RCTScrollViewManager.m +++ b/React/Views/RCTScrollViewManager.m @@ -74,16 +74,6 @@ RCT_EXPORT_VIEW_PROPERTY(snapToAlignment, NSString) RCT_REMAP_VIEW_PROPERTY(contentOffset, scrollView.contentOffset, CGPoint) RCT_EXPORT_VIEW_PROPERTY(onRefreshStart, RCTDirectEventBlock) -- (NSDictionary *)constantsToExport -{ - return @{ - @"DecelerationRate": @{ - @"normal": @(UIScrollViewDecelerationRateNormal), - @"fast": @(UIScrollViewDecelerationRateFast), - }, - }; -} - RCT_EXPORT_METHOD(getContentSize:(nonnull NSNumber *)reactTag callback:(RCTResponseSenderBlock)callback) { diff --git a/React/Views/RCTWebView.m b/React/Views/RCTWebView.m index f7240ec97..48307674f 100644 --- a/React/Views/RCTWebView.m +++ b/React/Views/RCTWebView.m @@ -170,12 +170,25 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) { BOOL isJSNavigation = [request.URL.scheme isEqualToString:RCTJSNavigationScheme]; + static NSDictionary *navigationTypes; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + navigationTypes = @{ + @(UIWebViewNavigationTypeLinkClicked): @"click", + @(UIWebViewNavigationTypeFormSubmitted): @"formsubmit", + @(UIWebViewNavigationTypeBackForward): @"backforward", + @(UIWebViewNavigationTypeReload): @"reload", + @(UIWebViewNavigationTypeFormResubmitted): @"formresubmit", + @(UIWebViewNavigationTypeOther): @"other", + }; + }); + // skip this for the JS Navigation handler if (!isJSNavigation && _onShouldStartLoadWithRequest) { NSMutableDictionary *event = [self baseEvent]; [event addEntriesFromDictionary: @{ @"url": (request.URL).absoluteString, - @"navigationType": @(navigationType) + @"navigationType": navigationTypes[@(navigationType)] }]; if (![self.delegate webView:self shouldStartLoadForRequest:event @@ -191,7 +204,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) NSMutableDictionary *event = [self baseEvent]; [event addEntriesFromDictionary: @{ @"url": (request.URL).absoluteString, - @"navigationType": @(navigationType) + @"navigationType": navigationTypes[@(navigationType)] }]; _onLoadingStart(event); } diff --git a/React/Views/RCTWebViewManager.m b/React/Views/RCTWebViewManager.m index d79e5827c..c8d237dda 100644 --- a/React/Views/RCTWebViewManager.m +++ b/React/Views/RCTWebViewManager.m @@ -47,21 +47,6 @@ RCT_EXPORT_VIEW_PROPERTY(onLoadingError, RCTDirectEventBlock) RCT_EXPORT_VIEW_PROPERTY(onShouldStartLoadWithRequest, RCTDirectEventBlock) RCT_REMAP_VIEW_PROPERTY(allowsInlineMediaPlayback, _webView.allowsInlineMediaPlayback, BOOL) -- (NSDictionary *)constantsToExport -{ - return @{ - @"JSNavigationScheme": RCTJSNavigationScheme, - @"NavigationType": @{ - @"LinkClicked": @(UIWebViewNavigationTypeLinkClicked), - @"FormSubmitted": @(UIWebViewNavigationTypeFormSubmitted), - @"BackForward": @(UIWebViewNavigationTypeBackForward), - @"Reload": @(UIWebViewNavigationTypeReload), - @"FormResubmitted": @(UIWebViewNavigationTypeFormResubmitted), - @"Other": @(UIWebViewNavigationTypeOther) - }, - }; -} - RCT_EXPORT_METHOD(goBack:(nonnull NSNumber *)reactTag) { [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) {