From 6072521a52473952397a6b5f06afd8055e12c179 Mon Sep 17 00:00:00 2001 From: Tadeu Zagallo Date: Wed, 4 Mar 2015 14:04:52 -0800 Subject: [PATCH] [ReactNative] Replace js long constants with strings --- Examples/Movies/SearchScreen.js | 2 +- .../UIExplorer/ActivityIndicatorExample.js | 12 ++-- Examples/UIExplorer/PointerEventsExample.js | 28 ++++---- Examples/UIExplorer/TextInputExample.js | 18 ++--- .../ActivityIndicatorIOS.ios.js | 21 +++--- .../Components/TextInput/TextInput.ios.js | 66 ++++++++----------- Libraries/Components/View/View.js | 15 ++--- ReactKit/Base/RCTConvert.h | 1 - ReactKit/Base/RCTConvert.m | 7 +- ReactKit/Modules/RCTUIManager.m | 22 +++---- 10 files changed, 85 insertions(+), 107 deletions(-) diff --git a/Examples/Movies/SearchScreen.js b/Examples/Movies/SearchScreen.js index ea58deefba0..3c451fd67b0 100644 --- a/Examples/Movies/SearchScreen.js +++ b/Examples/Movies/SearchScreen.js @@ -282,7 +282,7 @@ var SearchBar = React.createClass({ return ( ); } @@ -98,7 +98,7 @@ exports.examples = [ ); } @@ -109,19 +109,19 @@ exports.examples = [ return ( diff --git a/Examples/UIExplorer/PointerEventsExample.js b/Examples/UIExplorer/PointerEventsExample.js index 0bc6c2b13d9..10600d54dd7 100644 --- a/Examples/UIExplorer/PointerEventsExample.js +++ b/Examples/UIExplorer/PointerEventsExample.js @@ -61,7 +61,7 @@ var NoneExample = React.createClass({ A: unspecified this.props.onLog('B none touched')} style={[styles.box, styles.boxPassedThrough]}> @@ -87,7 +87,7 @@ var NoneExample = React.createClass({ var DemoText = React.createClass({ render: function() { return ( - + {this.props.children} @@ -107,11 +107,11 @@ var BoxNoneExample = React.createClass({ A: unspecified this.props.onLog('B boxNone touched')} + pointerEvents="box-none" + onTouchStart={() => this.props.onLog('B box-none touched')} style={[styles.box, styles.boxPassedThrough]}> - B: boxNone + B: box-none this.props.onLog('C unspecified touched')} @@ -121,7 +121,7 @@ var BoxNoneExample = React.createClass({ this.props.onLog('C explicitly unspecified touched')} style={[styles.box]}> @@ -144,11 +144,11 @@ var BoxOnlyExample = React.createClass({ A: unspecified this.props.onLog('B boxOnly touched')} + pointerEvents="box-only" + onTouchStart={() => this.props.onLog('B box-only touched')} style={styles.box}> - B: boxOnly + B: box-only this.props.onLog('C unspecified touched')} @@ -158,7 +158,7 @@ var BoxOnlyExample = React.createClass({ this.props.onLog('C explicitly unspecified touched')} style={[styles.box, styles.boxPassedThrough]}> @@ -179,13 +179,13 @@ var exampleClasses = [ }, { Component: BoxNoneExample, - title: '`boxNone`', - description: '`boxNone` causes touch events on the container to pass through and will only detect touch events on its child components.', + title: '`box-none`', + description: '`box-none` causes touch events on the container to pass through and will only detect touch events on its child components.', }, { Component: BoxOnlyExample, - title: '`boxOnly`', - description: '`boxOnly` causes touch events on the container\'s child components to pass through and will only detect touch events on the container itself.', + title: '`box-only`', + description: '`box-only` causes touch events on the container\'s child components to pass through and will only detect touch events on the container itself.', } ]; diff --git a/Examples/UIExplorer/TextInputExample.js b/Examples/UIExplorer/TextInputExample.js index e10dbc0f1f4..e1f28895be1 100644 --- a/Examples/UIExplorer/TextInputExample.js +++ b/Examples/UIExplorer/TextInputExample.js @@ -45,7 +45,7 @@ var TextEventsExample = React.createClass({ return ( this.updateText('onFocus')} @@ -123,25 +123,25 @@ exports.examples = [ @@ -193,25 +193,25 @@ exports.examples = [ diff --git a/Libraries/Components/ActivityIndicatorIOS/ActivityIndicatorIOS.ios.js b/Libraries/Components/ActivityIndicatorIOS/ActivityIndicatorIOS.ios.js index a281cf97aa9..5bba898303a 100644 --- a/Libraries/Components/ActivityIndicatorIOS/ActivityIndicatorIOS.ios.js +++ b/Libraries/Components/ActivityIndicatorIOS/ActivityIndicatorIOS.ios.js @@ -6,7 +6,7 @@ 'use strict'; var NativeMethodsMixin = require('NativeMethodsMixin'); -var NativeModulesDeprecated = require('NativeModulesDeprecated'); +var NativeModules = require('NativeModules'); var PropTypes = require('ReactPropTypes'); var React = require('React'); var ReactIOSViewAttributes = require('ReactIOSViewAttributes'); @@ -37,12 +37,11 @@ var ActivityIndicatorIOS = React.createClass({ * The foreground color of the spinner (default is gray). */ color: PropTypes.string, - /** - * The size of the spinner, must be one of: - * - ActivityIndicatorIOS.size.large - * - ActivityIndicatorIOS.size.small (default) - */ - size: PropTypes.oneOf([SpinnerSize.large, SpinnerSize.small]), + + size: PropTypes.oneOf([ + 'small', // default + 'large', + ]), }, getDefaultProps: function() { @@ -53,15 +52,11 @@ var ActivityIndicatorIOS = React.createClass({ }; }, - statics: { - size: SpinnerSize, - }, - render: function() { var style = styles.sizeSmall; - var NativeConstants = NativeModulesDeprecated.RKUIManager.UIActivityIndicatorView.Constants; + var NativeConstants = NativeModules.RKUIManager.UIActivityIndicatorView.Constants; var activityIndicatorViewStyle = NativeConstants.StyleWhite; - if (this.props.size == SpinnerSize.large) { + if (this.props.size === 'large') { style = styles.sizeLarge; activityIndicatorViewStyle = NativeConstants.StyleWhiteLarge; } diff --git a/Libraries/Components/TextInput/TextInput.ios.js b/Libraries/Components/TextInput/TextInput.ios.js index fef9c16f01b..aadd6c94a1c 100644 --- a/Libraries/Components/TextInput/TextInput.ios.js +++ b/Libraries/Components/TextInput/TextInput.ios.js @@ -8,7 +8,7 @@ var DocumentSelectionState = require('DocumentSelectionState'); var EventEmitter = require('EventEmitter'); var NativeMethodsMixin = require('NativeMethodsMixin'); -var NativeModulesDeprecated = require('NativeModulesDeprecated'); +var RKUIManager = require('NativeModules').RKUIManager; var PropTypes = require('ReactPropTypes'); var React = require('React'); var ReactChildren = require('ReactChildren'); @@ -59,28 +59,8 @@ var merge = require('merge'); * More example code in `TextInputExample.js`. */ -var nativeConstants = NativeModulesDeprecated.RKUIManager.UIText.AutocapitalizationType; - -var autoCapitalizeMode = { - none: nativeConstants.None, - sentences: nativeConstants.Sentences, - words: nativeConstants.Words, - characters: nativeConstants.AllCharacters -}; - -var clearButtonModeConstants = NativeModulesDeprecated.RKUIManager.UITextField.clearButtonMode; - -var clearButtonModeTypes = { - never: clearButtonModeConstants.Never, - whileEditing: clearButtonModeConstants.WhileEditing, - unlessEditing: clearButtonModeConstants.UnlessEditing, - always: clearButtonModeConstants.Always, -}; - -var keyboardType = { - default: 'default', - numeric: 'numeric', -}; +var autoCapitalizeConsts = RKUIManager.UIText.AutocapitalizationType; +var clearButtonModeConsts = RKUIManager.UITextField.clearButtonMode; var RKTextViewAttributes = merge(ReactIOSViewAttributes.UIView, { autoCorrect: true, @@ -113,12 +93,6 @@ var notMultiline = { }; var TextInput = React.createClass({ - statics: { - autoCapitalizeMode: autoCapitalizeMode, - clearButtonModeTypes: clearButtonModeTypes, - keyboardType: keyboardType, - }, - propTypes: { /** * Can tell TextInput to automatically capitalize certain characters. @@ -127,11 +101,13 @@ var TextInput = React.createClass({ * - words: first letter of each word * - sentences: first letter of each sentence (default) * - none: don't auto capitalize anything - * - * example: - * autoCapitalize={TextInput.autoCapitalizeMode.words} */ - autoCapitalize: PropTypes.oneOf(getObjectValues(autoCapitalizeMode)), + autoCapitalize: PropTypes.oneOf([ + 'none', + 'sentences', + 'words', + 'characters', + ]), /** * If false, disables auto-correct. Default value is true. */ @@ -145,9 +121,12 @@ var TextInput = React.createClass({ */ editable: PropTypes.bool, /** - * Determines which keyboard to open, e.g.`TextInput.keyboardType.numeric`. + * Determines which keyboard to open, e.g.`numeric`. */ - keyboardType: PropTypes.oneOf(getObjectValues(keyboardType)), + keyboardType: PropTypes.oneOf([ + 'default', + 'numeric', + ]), /** * If true, the text input can be multiple lines. Default value is false. */ @@ -202,7 +181,12 @@ var TextInput = React.createClass({ /** * When the clear button should appear on the right side of the text view */ - clearButtonMode: PropTypes.oneOf(getObjectValues(clearButtonModeTypes)), + clearButtonMode: PropTypes.oneOf([ + 'never', + 'while-editing', + 'unless-editing', + 'always', + ]), style: Text.stylePropType, }, @@ -307,6 +291,9 @@ var TextInput = React.createClass({ render: function() { var textContainer; + var autoCapitalize = autoCapitalizeConsts[this.props.autoCapitalize]; + var clearButtonMode = clearButtonModeConsts[this.props.clearButtonMode]; + if (!this.props.multiline) { for (var propKey in onlyMultiline) { if (this.props[propKey]) { @@ -329,9 +316,9 @@ var TextInput = React.createClass({ onSelectionChangeShouldSetResponder={() => true} placeholder={this.props.placeholder} text={this.state.bufferedValue} - autoCapitalize={this.props.autoCapitalize} + autoCapitalize={autoCapitalize} autoCorrect={this.props.autoCorrect} - clearButtonMode={this.props.clearButtonMode} + clearButtonMode={clearButtonMode} />; } else { for (var propKey in notMultiline) { @@ -372,8 +359,9 @@ var TextInput = React.createClass({ placeholder={this.props.placeholder} placeholderTextColor={this.props.placeholderTextColor} text={this.state.bufferedValue} - autoCapitalize={this.props.autoCapitalize} + autoCapitalize={autoCapitalize} autoCorrect={this.props.autoCorrect} + clearButtonMode={clearButtonMode} />; } diff --git a/Libraries/Components/View/View.js b/Libraries/Components/View/View.js index 643eef68a33..060125ea799 100644 --- a/Libraries/Components/View/View.js +++ b/Libraries/Components/View/View.js @@ -6,7 +6,6 @@ 'use strict'; var NativeMethodsMixin = require('NativeMethodsMixin'); -var NativeModules = require('NativeModules'); var PropTypes = require('ReactPropTypes'); var React = require('React'); var ReactIOSViewAttributes = require('ReactIOSViewAttributes'); @@ -45,15 +44,12 @@ var ViewStylePropTypes = require('ViewStylePropTypes'); * examples. */ -var StyleConstants = NativeModules.RKUIManager.StyleConstants; - var createReactIOSNativeComponentClass = require('createReactIOSNativeComponentClass'); var stylePropType = StyleSheetPropType(ViewStylePropTypes); var View = React.createClass({ statics: { - pointerEvents: StyleConstants.PointerEventsValues, stylePropType, }, @@ -96,7 +92,7 @@ var View = React.createClass({ /** * In the absence of `auto` property, `none` is much like `CSS`'s `none` - * value. `boxNone` is as if you had applied the `CSS` class: + * value. `box-none` is as if you had applied the `CSS` class: * * .cantTouchThis * { * pointer-events: auto; @@ -112,10 +108,10 @@ var View = React.createClass({ * implementation detail of the platform. */ pointerEvents: PropTypes.oneOf([ - StyleConstants.PointerEventsValues.boxNone, - StyleConstants.PointerEventsValues.none, - StyleConstants.PointerEventsValues.boxOnly, - StyleConstants.PointerEventsValues.unspecified + 'box-none', + 'none', + 'box-only', + 'auto', ]), /** @@ -151,7 +147,6 @@ if (__DEV__) { ViewToExport = View; } -ViewToExport.pointerEvents = View.pointerEvents; ViewToExport.stylePropType = stylePropType; module.exports = ViewToExport; diff --git a/ReactKit/Base/RCTConvert.h b/ReactKit/Base/RCTConvert.h index 51a6b76cea2..25b8cecc245 100644 --- a/ReactKit/Base/RCTConvert.h +++ b/ReactKit/Base/RCTConvert.h @@ -33,7 +33,6 @@ + (NSTextAlignment)NSTextAlignment:(id)json; + (NSWritingDirection)NSWritingDirection:(id)json; -+ (UITextAutocapitalizationType)UITextAutocapitalizationType:(id)json; + (UIKeyboardType)UIKeyboardType:(id)json; + (CGFloat)CGFloat:(id)json; diff --git a/ReactKit/Base/RCTConvert.m b/ReactKit/Base/RCTConvert.m index 4f3e8b05c60..39b0c6874cf 100644 --- a/ReactKit/Base/RCTConvert.m +++ b/ReactKit/Base/RCTConvert.m @@ -161,7 +161,7 @@ RCT_ENUM_CONVERTER(UITextAutocapitalizationType, (@{ @"none": @(UITextAutocapitalizationTypeNone), @"words": @(UITextAutocapitalizationTypeWords), @"sentences": @(UITextAutocapitalizationTypeSentences), - @"all": @(UITextAutocapitalizationTypeAllCharacters) + @"characters": @(UITextAutocapitalizationTypeAllCharacters) }), UITextAutocapitalizationTypeSentences, integerValue) RCT_ENUM_CONVERTER(UIKeyboardType, (@{ @@ -658,8 +658,9 @@ RCT_ENUM_CONVERTER(css_wrap_type_t, (@{ RCT_ENUM_CONVERTER(RCTPointerEvents, (@{ @"none": @(RCTPointerEventsNone), - @"boxonly": @(RCTPointerEventsBoxOnly), - @"boxnone": @(RCTPointerEventsBoxNone) + @"box-only": @(RCTPointerEventsBoxOnly), + @"box-none": @(RCTPointerEventsBoxNone), + @"auto": @(RCTPointerEventsUnspecified) }), RCTPointerEventsUnspecified, integerValue) RCT_ENUM_CONVERTER(RCTAnimationType, (@{ diff --git a/ReactKit/Modules/RCTUIManager.m b/ReactKit/Modules/RCTUIManager.m index 95101396964..5a65669cd10 100644 --- a/ReactKit/Modules/RCTUIManager.m +++ b/ReactKit/Modules/RCTUIManager.m @@ -1282,25 +1282,25 @@ static void RCTSetShadowViewProps(NSDictionary *props, RCTShadowView *shadowView @"StyleConstants": @{ @"PointerEventsValues": @{ @"none": @(RCTPointerEventsNone), - @"boxNone": @(RCTPointerEventsBoxNone), - @"boxOnly": @(RCTPointerEventsBoxOnly), - @"unspecified": @(RCTPointerEventsUnspecified), + @"box-none": @(RCTPointerEventsBoxNone), + @"box-only": @(RCTPointerEventsBoxOnly), + @"auto": @(RCTPointerEventsUnspecified), }, }, @"UIText": @{ @"AutocapitalizationType": @{ - @"AllCharacters": @(UITextAutocapitalizationTypeAllCharacters), - @"Sentences": @(UITextAutocapitalizationTypeSentences), - @"Words": @(UITextAutocapitalizationTypeWords), - @"None": @(UITextAutocapitalizationTypeNone), + @"characters": @(UITextAutocapitalizationTypeAllCharacters), + @"sentences": @(UITextAutocapitalizationTypeSentences), + @"words": @(UITextAutocapitalizationTypeWords), + @"none": @(UITextAutocapitalizationTypeNone), }, }, @"UITextField": @{ @"clearButtonMode": @{ - @"Never": @(UITextFieldViewModeNever), - @"WhileEditing": @(UITextFieldViewModeWhileEditing), - @"UnlessEditing": @(UITextFieldViewModeUnlessEditing), - @"Always": @(UITextFieldViewModeAlways), + @"never": @(UITextFieldViewModeNever), + @"while-editing": @(UITextFieldViewModeWhileEditing), + @"unless-editing": @(UITextFieldViewModeUnlessEditing), + @"always": @(UITextFieldViewModeAlways), }, }, @"UIView": @{