From cd13c99d001d25296dcf991ea3cb32929d872102 Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Thu, 9 Apr 2020 10:27:12 -0700 Subject: [PATCH 1/6] Update default Podfile to not depend on a path (#28572) Summary: Recently, a default Podfile has been modified to not contain all the React Native pods, but use a helper method `use_react_native!`. While this is great, it assumes a hardcoded path of `../node_modules/react-native` to be always the correct location of the React Native. https://github.com/facebook/react-native/blob/d4d8887b5018782eeb3f26efa85125e6bbff73e4/scripts/autolink-ios.rb#L7-L9 Unfortunately, due to the way Ruby works, this completely hides the path away from the users. Before, they could have seen the wrong path explicitly in a Podfile and knew to update it to resolve path-related issues. With the current version in `master`, I can see a lot of issues where developers wonder how to resolve the path issues and how to pass the path itself. https://github.com/facebook/react-native/blob/4118d798265341061105f3a53550db83c66a71cb/template/ios/Podfile#L5-L10 This PR uses React Native CLI configuration (that is already used to link 3rd party dependencies) to explicitly define the correct path to the React Native. As a result, we don't have to change the paths here whether we're running monorepo or not. ## Changelog [IOS] [INTERNAL] - Always provide an explicit path to React Native Pull Request resolved: https://github.com/facebook/react-native/pull/28572 Differential Revision: D20945194 Pulled By: TheSavior fbshipit-source-id: 010f9754f2ed78ef62fd52f4d201f296f5af6d27 --- template/ios/Podfile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/template/ios/Podfile b/template/ios/Podfile index d6f78d75e05171..6e1ebd6181167f 100644 --- a/template/ios/Podfile +++ b/template/ios/Podfile @@ -4,16 +4,15 @@ require_relative '../node_modules/@react-native-community/cli-platform-ios/nativ platform :ios, '10.0' target 'HelloWorld' do - # Pods for HelloWorld - use_react_native! + config = use_native_modules! + + use_react_native!(:path => config["reactNativePath"]) target 'HelloWorldTests' do inherit! :complete # Pods for testing end - use_native_modules! - # Enables Flipper. # # Note that if you have use_frameworks! enabled, Flipper will not work and From cd347a7e0ed29ae1049e041fcb34588e1aac76f9 Mon Sep 17 00:00:00 2001 From: George Zahariev Date: Thu, 9 Apr 2020 10:55:48 -0700 Subject: [PATCH 2/6] Upgrade Prettier in Xplat to version 1.19.1 Summary: Upgrades Prettier in Xplat to 1.19.1 Ignores upgrading packages on already on versions greater than 1.19.1 Changelog: [Internal] allow-large-files bypass-lint (Note: this ignores all push blocking failures!) Reviewed By: gkz, cpojer Differential Revision: D20879147 fbshipit-source-id: 0deee7ac941e91e1c3c3a1e7d3d3ed20de1d657d --- IntegrationTests/AsyncStorageTest.js | 5 +- .../Animated/src/NativeAnimatedHelper.js | 4 +- .../src/__tests__/AnimatedNative-test.js | 60 +++++++++++++++---- .../__tests__/MessageQueue-test.js | 16 ++++- Libraries/Blob/URL.js | 4 +- .../ActivityIndicator/ActivityIndicator.js | 5 +- .../Keyboard/KeyboardAvoidingView.js | 19 ++---- .../Picker/PickerAndroid.android.js | 5 +- Libraries/Components/Slider/Slider.js | 5 +- Libraries/Components/StatusBar/StatusBar.js | 4 +- Libraries/Interaction/TaskQueue.js | 4 +- Libraries/Lists/FlatList.js | 6 +- Libraries/Lists/VirtualizedList.js | 5 +- .../Lists/__tests__/ViewabilityHelper-test.js | 5 +- .../LogBox/Data/__tests__/LogBoxLog-test.js | 2 +- Libraries/Modal/Modal.js | 4 +- .../__flowtests__/StyleSheet-flowtest.js | 40 +++---------- .../differ/__tests__/deepDiffer-test.js | 24 ++++++-- .../polyfills/__tests__/Object.es7-test.js | 10 +++- Libraries/polyfills/console.js | 4 +- .../js/examples/XHR/XHRExampleDownload.js | 8 +-- package.json | 2 +- .../src/cli/verify_with_old_codegen.js | 4 +- .../generators/components/GeneratePropsCpp.js | 4 +- .../generators/components/GeneratePropsH.js | 8 +-- .../components/GeneratePropsJavaDelegate.js | 16 ++--- .../components/GenerateViewConfigJs.js | 4 +- .../src/generators/modules/GenerateModuleH.js | 8 +-- .../modules/GenerateModuleHObjCpp.js | 8 +-- .../modules/ObjCppUtils/GenerateStructs.js | 4 +- .../src/parsers/flow/components/index.js | 4 +- .../src/parsers/flow/components/props.js | 4 +- .../src/parsers/flow/modules/methods.js | 4 +- .../run-android-ci-instrumentation-tests.js | 4 +- yarn.lock | 8 +-- 35 files changed, 150 insertions(+), 171 deletions(-) diff --git a/IntegrationTests/AsyncStorageTest.js b/IntegrationTests/AsyncStorageTest.js index e33cedfdd82482..12d9f3d620f331 100644 --- a/IntegrationTests/AsyncStorageTest.js +++ b/IntegrationTests/AsyncStorageTest.js @@ -152,7 +152,10 @@ function testMerge() { } function testOptimizedMultiGet() { - let batch = [[KEY_1, VAL_1], [KEY_2, VAL_2]]; + let batch = [ + [KEY_1, VAL_1], + [KEY_2, VAL_2], + ]; let keys = batch.map(([key, value]) => key); AsyncStorage.multiSet(batch, err1 => { // yes, twice on purpose diff --git a/Libraries/Animated/src/NativeAnimatedHelper.js b/Libraries/Animated/src/NativeAnimatedHelper.js index f21066bb07ff65..8cc6aa25b5bd70 100644 --- a/Libraries/Animated/src/NativeAnimatedHelper.js +++ b/Libraries/Animated/src/NativeAnimatedHelper.js @@ -235,9 +235,7 @@ function validateTransform( configs.forEach(config => { if (!TRANSFORM_WHITELIST.hasOwnProperty(config.property)) { throw new Error( - `Property '${ - config.property - }' is not supported by native animated module`, + `Property '${config.property}' is not supported by native animated module`, ); } }); diff --git a/Libraries/Animated/src/__tests__/AnimatedNative-test.js b/Libraries/Animated/src/__tests__/AnimatedNative-test.js index 89024cdb883fe4..4a68f78f3addb6 100644 --- a/Libraries/Animated/src/__tests__/AnimatedNative-test.js +++ b/Libraries/Animated/src/__tests__/AnimatedNative-test.js @@ -357,11 +357,19 @@ describe('Native Animated', () => { expect(additionConnectionCalls.length).toBe(2); expect(NativeAnimatedModule.createAnimatedNode).toBeCalledWith( additionCall[1].input[0], - {type: 'value', value: 1, offset: 0}, + { + type: 'value', + value: 1, + offset: 0, + }, ); expect(NativeAnimatedModule.createAnimatedNode).toBeCalledWith( additionCall[1].input[1], - {type: 'value', value: 2, offset: 0}, + { + type: 'value', + value: 2, + offset: 0, + }, ); }); @@ -391,11 +399,19 @@ describe('Native Animated', () => { expect(subtractionConnectionCalls.length).toBe(2); expect(NativeAnimatedModule.createAnimatedNode).toBeCalledWith( subtractionCall[1].input[0], - {type: 'value', value: 2, offset: 0}, + { + type: 'value', + value: 2, + offset: 0, + }, ); expect(NativeAnimatedModule.createAnimatedNode).toBeCalledWith( subtractionCall[1].input[1], - {type: 'value', value: 1, offset: 0}, + { + type: 'value', + value: 1, + offset: 0, + }, ); }); @@ -425,11 +441,19 @@ describe('Native Animated', () => { expect(multiplicationConnectionCalls.length).toBe(2); expect(NativeAnimatedModule.createAnimatedNode).toBeCalledWith( multiplicationCall[1].input[0], - {type: 'value', value: 2, offset: 0}, + { + type: 'value', + value: 2, + offset: 0, + }, ); expect(NativeAnimatedModule.createAnimatedNode).toBeCalledWith( multiplicationCall[1].input[1], - {type: 'value', value: 1, offset: 0}, + { + type: 'value', + value: 1, + offset: 0, + }, ); }); @@ -459,11 +483,19 @@ describe('Native Animated', () => { expect(divisionConnectionCalls.length).toBe(2); expect(NativeAnimatedModule.createAnimatedNode).toBeCalledWith( divisionCall[1].input[0], - {type: 'value', value: 4, offset: 0}, + { + type: 'value', + value: 4, + offset: 0, + }, ); expect(NativeAnimatedModule.createAnimatedNode).toBeCalledWith( divisionCall[1].input[1], - {type: 'value', value: 2, offset: 0}, + { + type: 'value', + value: 2, + offset: 0, + }, ); }); @@ -491,7 +523,11 @@ describe('Native Animated', () => { expect(moduloConnectionCalls.length).toBe(1); expect(NativeAnimatedModule.createAnimatedNode).toBeCalledWith( moduloCall[1].input, - {type: 'value', value: 4, offset: 0}, + { + type: 'value', + value: 4, + offset: 0, + }, ); }); @@ -588,7 +624,11 @@ describe('Native Animated', () => { expect(diffClampConnectionCalls.length).toBe(1); expect(NativeAnimatedModule.createAnimatedNode).toBeCalledWith( diffClampCall[1].input, - {type: 'value', value: 2, offset: 0}, + { + type: 'value', + value: 2, + offset: 0, + }, ); }); diff --git a/Libraries/BatchedBridge/__tests__/MessageQueue-test.js b/Libraries/BatchedBridge/__tests__/MessageQueue-test.js index 42abd597dd867e..fb720c7b9ba991 100644 --- a/Libraries/BatchedBridge/__tests__/MessageQueue-test.js +++ b/Libraries/BatchedBridge/__tests__/MessageQueue-test.js @@ -81,13 +81,25 @@ describe('MessageQueue', function() { }); it('should throw when calling the same callback twice', () => { - queue.enqueueNativeCall(0, 1, [], () => {}, () => {}); + queue.enqueueNativeCall( + 0, + 1, + [], + () => {}, + () => {}, + ); queue.__invokeCallback(1, []); expect(() => queue.__invokeCallback(1, [])).toThrow(); }); it('should throw when calling both success and failure callback', () => { - queue.enqueueNativeCall(0, 1, [], () => {}, () => {}); + queue.enqueueNativeCall( + 0, + 1, + [], + () => {}, + () => {}, + ); queue.__invokeCallback(1, []); expect(() => queue.__invokeCallback(0, [])).toThrow(); }); diff --git a/Libraries/Blob/URL.js b/Libraries/Blob/URL.js index f2b6f7f277cb7e..bf9ab01bf1a786 100644 --- a/Libraries/Blob/URL.js +++ b/Libraries/Blob/URL.js @@ -119,9 +119,7 @@ export class URL { if (BLOB_URL_PREFIX === null) { throw new Error('Cannot create URL for blob!'); } - return `${BLOB_URL_PREFIX}${blob.data.blobId}?offset=${ - blob.data.offset - }&size=${blob.size}`; + return `${BLOB_URL_PREFIX}${blob.data.blobId}?offset=${blob.data.offset}&size=${blob.size}`; } static revokeObjectURL(url: string) { diff --git a/Libraries/Components/ActivityIndicator/ActivityIndicator.js b/Libraries/Components/ActivityIndicator/ActivityIndicator.js index 9d0df8f0a739e7..62bc6664305a04 100644 --- a/Libraries/Components/ActivityIndicator/ActivityIndicator.js +++ b/Libraries/Components/ActivityIndicator/ActivityIndicator.js @@ -101,10 +101,7 @@ const ActivityIndicator = (props: Props, forwardedRef?: any) => { return ( + style={StyleSheet.compose(styles.container, style)}> {Platform.OS === 'android' ? ( // $FlowFixMe Flow doesn't know when this is the android component diff --git a/Libraries/Components/Keyboard/KeyboardAvoidingView.js b/Libraries/Components/Keyboard/KeyboardAvoidingView.js index 7c794ea5e8dcaf..07513e253b7041 100644 --- a/Libraries/Components/Keyboard/KeyboardAvoidingView.js +++ b/Libraries/Components/Keyboard/KeyboardAvoidingView.js @@ -170,10 +170,7 @@ class KeyboardAvoidingView extends React.Component { return ( {children} @@ -188,12 +185,9 @@ class KeyboardAvoidingView extends React.Component { onLayout={this._onLayout} {...props}> + style={StyleSheet.compose(contentContainerStyle, { + bottom: bottomHeight, + })}> {children} @@ -203,10 +197,7 @@ class KeyboardAvoidingView extends React.Component { return ( {children} diff --git a/Libraries/Components/Picker/PickerAndroid.android.js b/Libraries/Components/Picker/PickerAndroid.android.js index a47d29bd5ec6a7..3b2156c204a369 100644 --- a/Libraries/Components/Picker/PickerAndroid.android.js +++ b/Libraries/Components/Picker/PickerAndroid.android.js @@ -121,10 +121,7 @@ function PickerAndroid(props: Props): React.Node { prompt: props.prompt, ref: pickerRef, selected, - style: StyleSheet.compose( - styles.pickerAndroid, - props.style, - ), + style: StyleSheet.compose(styles.pickerAndroid, props.style), backgroundColor: props.backgroundColor, testID: props.testID, }; diff --git a/Libraries/Components/Slider/Slider.js b/Libraries/Components/Slider/Slider.js index 28c7ff5a72306a..1a5d23f049b884 100644 --- a/Libraries/Components/Slider/Slider.js +++ b/Libraries/Components/Slider/Slider.js @@ -198,10 +198,7 @@ const Slider = ( props: Props, forwardedRef?: ?React.Ref, ) => { - const style = StyleSheet.compose( - styles.slider, - props.style, - ); + const style = StyleSheet.compose(styles.slider, props.style); const { disabled = false, diff --git a/Libraries/Components/StatusBar/StatusBar.js b/Libraries/Components/StatusBar/StatusBar.js index 81ab87e4d3747a..482149fb7be6b0 100644 --- a/Libraries/Components/StatusBar/StatusBar.js +++ b/Libraries/Components/StatusBar/StatusBar.js @@ -467,9 +467,7 @@ class StatusBar extends React.Component { const processedColor = processColor(mergedProps.backgroundColor.value); if (processedColor == null) { console.warn( - `\`StatusBar._updatePropsStack\`: Color ${ - mergedProps.backgroundColor.value - } parsed to null or undefined`, + `\`StatusBar._updatePropsStack\`: Color ${mergedProps.backgroundColor.value} parsed to null or undefined`, ); } else { invariant( diff --git a/Libraries/Interaction/TaskQueue.js b/Libraries/Interaction/TaskQueue.js index bf15d06a090707..15eb69388dc30a 100644 --- a/Libraries/Interaction/TaskQueue.js +++ b/Libraries/Interaction/TaskQueue.js @@ -172,9 +172,7 @@ class TaskQueue { this.hasTasksToProcess() && this._onMoreTasks(); }) .catch(ex => { - ex.message = `TaskQueue: Error resolving Promise in task ${ - task.name - }: ${ex.message}`; + ex.message = `TaskQueue: Error resolving Promise in task ${task.name}: ${ex.message}`; throw ex; }) .done(); diff --git a/Libraries/Lists/FlatList.js b/Libraries/Lists/FlatList.js index 6c268ddeba985a..d72228d33ceaa2 100644 --- a/Libraries/Lists/FlatList.js +++ b/Libraries/Lists/FlatList.js @@ -593,11 +593,7 @@ class FlatList extends React.PureComponent, void> { 'Expected array of items with numColumns > 1', ); return ( - + {item.map((it, kk) => { const element = renderer({ item: it, diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index 9ec105fc32ac92..6a71f04d017065 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -1117,10 +1117,7 @@ class VirtualizedList extends React.PureComponent { element.props.onLayout(event); } }, - style: StyleSheet.compose( - inversionStyle, - element.props.style, - ), + style: StyleSheet.compose(inversionStyle, element.props.style), }), ); } diff --git a/Libraries/Lists/__tests__/ViewabilityHelper-test.js b/Libraries/Lists/__tests__/ViewabilityHelper-test.js index 81ffdb731cc7f5..6240824b68c0a2 100644 --- a/Libraries/Lists/__tests__/ViewabilityHelper-test.js +++ b/Libraries/Lists/__tests__/ViewabilityHelper-test.js @@ -429,7 +429,10 @@ describe('onUpdate', function() { expect(onViewableItemsChanged.mock.calls.length).toBe(2); expect(onViewableItemsChanged.mock.calls[1][0]).toEqual({ - changed: [{isViewable: true, key: 'c'}, {isViewable: false, key: 'a'}], + changed: [ + {isViewable: true, key: 'c'}, + {isViewable: false, key: 'a'}, + ], viewabilityConfig: {viewAreaCoveragePercentThreshold: 0}, viewableItems: [{isViewable: true, key: 'c'}], }); diff --git a/Libraries/LogBox/Data/__tests__/LogBoxLog-test.js b/Libraries/LogBox/Data/__tests__/LogBoxLog-test.js index c08d16786d16d5..2ff36f2292126c 100644 --- a/Libraries/LogBox/Data/__tests__/LogBoxLog-test.js +++ b/Libraries/LogBox/Data/__tests__/LogBoxLog-test.js @@ -19,7 +19,7 @@ jest.mock('../LogBoxSymbolication', () => { }); function getLogBoxLog() { - return new (require('../LogBoxLog')).default({ + return new (require('../LogBoxLog').default)({ level: 'warn', isComponentError: false, message: {content: '...', substitutions: []}, diff --git a/Libraries/Modal/Modal.js b/Libraries/Modal/Modal.js index 71293402c36186..ba842b1746431a 100644 --- a/Libraries/Modal/Modal.js +++ b/Libraries/Modal/Modal.js @@ -190,9 +190,7 @@ class Modal extends React.Component { props.transparent ) { console.warn( - `Modal with '${ - props.presentationStyle - }' presentation style and 'transparent' value is not supported.`, + `Modal with '${props.presentationStyle}' presentation style and 'transparent' value is not supported.`, ); } } diff --git a/Libraries/StyleSheet/__flowtests__/StyleSheet-flowtest.js b/Libraries/StyleSheet/__flowtests__/StyleSheet-flowtest.js index c93c8de63cd9d8..fddb4158f69e1d 100644 --- a/Libraries/StyleSheet/__flowtests__/StyleSheet-flowtest.js +++ b/Libraries/StyleSheet/__flowtests__/StyleSheet-flowtest.js @@ -18,53 +18,29 @@ const textStyle = {color: 'rgb(0, 0, 0)'}; module.exports = { testGoodCompose() { - (StyleSheet.compose( - imageStyle, - imageStyle, - ): ImageStyleProp); + (StyleSheet.compose(imageStyle, imageStyle): ImageStyleProp); - (StyleSheet.compose( - textStyle, - textStyle, - ): TextStyleProp); + (StyleSheet.compose(textStyle, textStyle): TextStyleProp); - (StyleSheet.compose( - null, - null, - ): TextStyleProp); + (StyleSheet.compose(null, null): TextStyleProp); - (StyleSheet.compose( - textStyle, - null, - ): TextStyleProp); + (StyleSheet.compose(textStyle, null): TextStyleProp); (StyleSheet.compose( textStyle, Math.random() < 0.5 ? textStyle : null, ): TextStyleProp); - (StyleSheet.compose( - [textStyle], - null, - ): TextStyleProp); + (StyleSheet.compose([textStyle], null): TextStyleProp); - (StyleSheet.compose( - [textStyle], - null, - ): TextStyleProp); + (StyleSheet.compose([textStyle], null): TextStyleProp); - (StyleSheet.compose( - [textStyle], - [textStyle], - ): TextStyleProp); + (StyleSheet.compose([textStyle], [textStyle]): TextStyleProp); }, testBadCompose() { // $FlowExpectedError - Incompatible type. - (StyleSheet.compose( - textStyle, - textStyle, - ): ImageStyleProp); + (StyleSheet.compose(textStyle, textStyle): ImageStyleProp); // $FlowExpectedError - Incompatible type. (StyleSheet.compose( diff --git a/Libraries/Utilities/differ/__tests__/deepDiffer-test.js b/Libraries/Utilities/differ/__tests__/deepDiffer-test.js index a2aca448f33f37..d1a35a20589a08 100644 --- a/Libraries/Utilities/differ/__tests__/deepDiffer-test.js +++ b/Libraries/Utilities/differ/__tests__/deepDiffer-test.js @@ -129,13 +129,23 @@ describe('deepDiffer', function() { ).toBe(false); }); it('should consider all functions equal', () => { - expect(deepDiffer(() => {}, x => x)).toBe(false); + expect( + deepDiffer( + () => {}, + x => x, + ), + ).toBe(false); const f = () => {}; expect(deepDiffer(f, f)).toBe(false); }); it('should compare functions if unsafelyIgnoreFunctions is false', () => { expect( - deepDiffer(() => {}, x => x, undefined, {unsafelyIgnoreFunctions: false}), + deepDiffer( + () => {}, + x => x, + undefined, + {unsafelyIgnoreFunctions: false}, + ), ).toBe(true); const f = () => {}; expect(deepDiffer(f, f, undefined, {unsafelyIgnoreFunctions: false})).toBe( @@ -143,9 +153,13 @@ describe('deepDiffer', function() { ); // shorthand, omitting maxDepth - expect(deepDiffer(() => {}, x => x, {unsafelyIgnoreFunctions: false})).toBe( - true, - ); + expect( + deepDiffer( + () => {}, + x => x, + {unsafelyIgnoreFunctions: false}, + ), + ).toBe(true); expect(deepDiffer(f, f, {unsafelyIgnoreFunctions: false})).toBe(false); }); it('should log when implicitly considering two different functions equal', () => { diff --git a/Libraries/polyfills/__tests__/Object.es7-test.js b/Libraries/polyfills/__tests__/Object.es7-test.js index a4aa966e646ac4..c51c32c7f9ae76 100644 --- a/Libraries/polyfills/__tests__/Object.es7-test.js +++ b/Libraries/polyfills/__tests__/Object.es7-test.js @@ -48,7 +48,10 @@ describe('Object (ES7)', () => { expect(Object.entries(foo)).toEqual([['x', 10]]); const bar = {x: 10, y: 20}; - expect(Object.entries(bar)).toEqual([['x', 10], ['y', 20]]); + expect(Object.entries(bar)).toEqual([ + ['x', 10], + ['y', 20], + ]); }); it('should work with proto-less objects', () => { @@ -73,7 +76,10 @@ describe('Object (ES7)', () => { }); it('should convert to object primitive string', () => { - expect(Object.entries('ab')).toEqual([['0', 'a'], ['1', 'b']]); + expect(Object.entries('ab')).toEqual([ + ['0', 'a'], + ['1', 'b'], + ]); }); }); diff --git a/Libraries/polyfills/console.js b/Libraries/polyfills/console.js index 585a1a3c872ce6..962e52b5e985ba 100644 --- a/Libraries/polyfills/console.js +++ b/Libraries/polyfills/console.js @@ -65,9 +65,7 @@ const inspect = (function() { function formatValue(ctx, value, recurseTimes) { ctx.formatValueCalls++; if (ctx.formatValueCalls > 200) { - return `[TOO BIG formatValueCalls ${ - ctx.formatValueCalls - } exceeded limit of 200]`; + return `[TOO BIG formatValueCalls ${ctx.formatValueCalls} exceeded limit of 200]`; } // Primitive types cannot have properties diff --git a/RNTester/js/examples/XHR/XHRExampleDownload.js b/RNTester/js/examples/XHR/XHRExampleDownload.js index 41c414c108c06f..f203a7d9a1d068 100644 --- a/RNTester/js/examples/XHR/XHRExampleDownload.js +++ b/RNTester/js/examples/XHR/XHRExampleDownload.js @@ -112,13 +112,9 @@ class XHRExampleDownload extends React.Component<{...}, Object> { return; } if (xhr.status === 200) { - let responseType = `Response is a string, ${ - xhr.response.length - } characters long.`; + let responseType = `Response is a string, ${xhr.response.length} characters long.`; if (xhr.response instanceof ArrayBuffer) { - responseType = `Response is an ArrayBuffer, ${ - xhr.response.byteLength - } bytes long.`; + responseType = `Response is an ArrayBuffer, ${xhr.response.byteLength} bytes long.`; } Alert.alert('Download complete!', responseType); } else if (xhr.status !== 0) { diff --git a/package.json b/package.json index a7c5f920f7812b..abd8835dc34f2b 100644 --- a/package.json +++ b/package.json @@ -144,7 +144,7 @@ "jest-junit": "^6.3.0", "jscodeshift": "^0.7.0", "mkdirp": "^0.5.1", - "prettier": "1.17.0", + "prettier": "1.19.1", "react": "16.13.1", "react-test-renderer": "16.13.1", "shelljs": "^0.7.8", diff --git a/packages/react-native-codegen/src/cli/verify_with_old_codegen.js b/packages/react-native-codegen/src/cli/verify_with_old_codegen.js index f46f6f76fa9ea3..60192bfab7d852 100755 --- a/packages/react-native-codegen/src/cli/verify_with_old_codegen.js +++ b/packages/react-native-codegen/src/cli/verify_with_old_codegen.js @@ -45,9 +45,7 @@ if (t1.length !== t2.length) { for (let i = 0; i < t1.length; i++) { if (t1[i] !== t2[i]) { throw new Error( - `Old and new codegen does not produce similar output! ${i} ${ - t1[i] - } | ${t2[i]}`, + `Old and new codegen does not produce similar output! ${i} ${t1[i]} | ${t2[i]}`, ); } } diff --git a/packages/react-native-codegen/src/generators/components/GeneratePropsCpp.js b/packages/react-native-codegen/src/generators/components/GeneratePropsCpp.js index dfa114376a7167..0cfe41fa8c66ef 100644 --- a/packages/react-native-codegen/src/generators/components/GeneratePropsCpp.js +++ b/packages/react-native-codegen/src/generators/components/GeneratePropsCpp.js @@ -49,9 +49,7 @@ function generatePropsString(componentName: string, component: ComponentShape) { return component.props .map(prop => { const defaultValue = convertDefaultTypeToString(componentName, prop); - return `${prop.name}(convertRawProp(rawProps, "${ - prop.name - }", sourceProps.${prop.name}, {${defaultValue}}))`; + return `${prop.name}(convertRawProp(rawProps, "${prop.name}", sourceProps.${prop.name}, {${defaultValue}}))`; }) .join(',\n' + ' '); } diff --git a/packages/react-native-codegen/src/generators/components/GeneratePropsH.js b/packages/react-native-codegen/src/generators/components/GeneratePropsH.js index 557a7e4d27baa3..fd12096e297854 100644 --- a/packages/react-native-codegen/src/generators/components/GeneratePropsH.js +++ b/packages/react-native-codegen/src/generators/components/GeneratePropsH.js @@ -275,9 +275,7 @@ function getNativeTypeFromAnnotation( default: (typeAnnotation: empty); throw new Error( - `Received invalid typeAnnotation for ${componentName} prop ${ - prop.name - }, received ${typeAnnotation.type}`, + `Received invalid typeAnnotation for ${componentName} prop ${prop.name}, received ${typeAnnotation.type}`, ); } } @@ -727,9 +725,7 @@ function generateStruct( default: (property.typeAnnotation.type: empty); throw new Error( - `Received invalid component property type ${ - property.typeAnnotation.type - }`, + `Received invalid component property type ${property.typeAnnotation.type}`, ); } }); diff --git a/packages/react-native-codegen/src/generators/components/GeneratePropsJavaDelegate.js b/packages/react-native-codegen/src/generators/components/GeneratePropsJavaDelegate.js index 239bf887e3ca4b..a92f7e445f1b51 100644 --- a/packages/react-native-codegen/src/generators/components/GeneratePropsJavaDelegate.js +++ b/packages/react-native-codegen/src/generators/components/GeneratePropsJavaDelegate.js @@ -82,14 +82,10 @@ function getJavaValueForProp( : `"${typeAnnotation.default}"`; return `value == null ? ${defaultValueString} : (String) value`; case 'Int32TypeAnnotation': - return `value == null ? ${ - typeAnnotation.default - } : ((Double) value).intValue()`; + return `value == null ? ${typeAnnotation.default} : ((Double) value).intValue()`; case 'DoubleTypeAnnotation': if (prop.optional) { - return `value == null ? ${ - typeAnnotation.default - }f : ((Double) value).doubleValue()`; + return `value == null ? ${typeAnnotation.default}f : ((Double) value).doubleValue()`; } else { return 'value == null ? Double.NaN : ((Double) value).doubleValue()'; } @@ -97,9 +93,7 @@ function getJavaValueForProp( if (typeAnnotation.default === null) { return 'value == null ? null : ((Double) value).floatValue()'; } else if (prop.optional) { - return `value == null ? ${ - typeAnnotation.default - }f : ((Double) value).floatValue()`; + return `value == null ? ${typeAnnotation.default}f : ((Double) value).floatValue()`; } else { return 'value == null ? Float.NaN : ((Double) value).floatValue()'; } @@ -126,9 +120,7 @@ function getJavaValueForProp( case 'StringEnumTypeAnnotation': return '(String) value'; case 'Int32EnumTypeAnnotation': - return `value == null ? ${ - typeAnnotation.default - } : ((Double) value).intValue()`; + return `value == null ? ${typeAnnotation.default} : ((Double) value).intValue()`; default: (typeAnnotation: empty); throw new Error('Received invalid typeAnnotation'); diff --git a/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js b/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js index 5ccb3dad12cc78..22e76aa785baad 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js +++ b/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js @@ -78,9 +78,7 @@ function getReactDiffProcessValue(typeAnnotation) { return j.literal(true); default: throw new Error( - `Received unknown array native typeAnnotation: "${ - typeAnnotation.elementType.name - }"`, + `Received unknown array native typeAnnotation: "${typeAnnotation.elementType.name}"`, ); } } diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js index d731fe0a3cdf89..afb1b9c2f747ad 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js @@ -110,9 +110,7 @@ module.exports = { .map(param => { const translatedParam = translatePrimitiveJSTypeToCpp( param.typeAnnotation, - `Unspopported type for param "${param.name}" in ${ - prop.name - }. Found: ${param.typeAnnotation.type}`, + `Unspopported type for param "${param.name}" in ${prop.name}. Found: ${param.typeAnnotation.type}`, ); const isObject = translatedParam.startsWith('jsi::'); return ( @@ -128,9 +126,7 @@ module.exports = { '::_RETURN_VALUE_::', translatePrimitiveJSTypeToCpp( prop.typeAnnotation.returnTypeAnnotation, - `Unspopported return type for ${prop.name}. Found: ${ - prop.typeAnnotation.returnTypeAnnotation.type - }`, + `Unspopported return type for ${prop.name}. Found: ${prop.typeAnnotation.returnTypeAnnotation.type}`, ), ) .replace( diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleHObjCpp.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleHObjCpp.js index 184612663b9bbe..1018323e960c77 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleHObjCpp.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleHObjCpp.js @@ -201,9 +201,7 @@ module.exports = { } else { paramObjCType = translatePrimitiveJSTypeToObjCType( param, - `Unspopported type for param "${param.name}" in ${ - prop.name - }. Found: ${param.typeAnnotation.type}`, + `Unspopported type for param "${param.name}" in ${prop.name}. Found: ${param.typeAnnotation.type}`, ); } return `${i === 0 ? '' : param.name}:(${paramObjCType})${ @@ -232,9 +230,7 @@ module.exports = { '::_RETURN_VALUE_::', translatePrimitiveJSTypeToObjCTypeForReturn( returnTypeAnnotation, - `Unspopported return type for ${prop.name}. Found: ${ - prop.typeAnnotation.returnTypeAnnotation.type - }`, + `Unspopported return type for ${prop.name}. Found: ${prop.typeAnnotation.returnTypeAnnotation.type}`, ), ) .replace('::_ARGS_::', nativeArgs); diff --git a/packages/react-native-codegen/src/generators/modules/ObjCppUtils/GenerateStructs.js b/packages/react-native-codegen/src/generators/modules/ObjCppUtils/GenerateStructs.js index 73614202abf857..3c44ef81ec1ab5 100644 --- a/packages/react-native-codegen/src/generators/modules/ObjCppUtils/GenerateStructs.js +++ b/packages/react-native-codegen/src/generators/modules/ObjCppUtils/GenerateStructs.js @@ -66,9 +66,7 @@ function getInlineMethodSignature( case 'AnyTypeAnnotation': return `id ${property.name}() const;`; case 'ArrayTypeAnnotation': - return `facebook::react::LazyVector> ${ - property.name - }() const;`; + return `facebook::react::LazyVector> ${property.name}() const;`; case 'FunctionTypeAnnotation': default: throw new Error(`Unknown prop type, found: ${typeAnnotation.type}"`); diff --git a/packages/react-native-codegen/src/parsers/flow/components/index.js b/packages/react-native-codegen/src/parsers/flow/components/index.js index 2ae19153b94a89..eb8867401d5372 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/index.js +++ b/packages/react-native-codegen/src/parsers/flow/components/index.js @@ -127,9 +127,7 @@ function getCommandProperties(commandTypeName, types, commandOptions) { if (typeAlias.type !== 'InterfaceDeclaration') { throw new Error( - `The type argument for codegenNativeCommands must be an interface, received ${ - typeAlias.type - }`, + `The type argument for codegenNativeCommands must be an interface, received ${typeAlias.type}`, ); } diff --git a/packages/react-native-codegen/src/parsers/flow/components/props.js b/packages/react-native-codegen/src/parsers/flow/components/props.js index 404289cc8a7dc7..24e5889d4a3f56 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/props.js +++ b/packages/react-native-codegen/src/parsers/flow/components/props.js @@ -345,8 +345,8 @@ function buildPropSchema(property, types: TypeMap): ?PropTypeShape { } if ( value.type === 'NullableTypeAnnotation' && - (typeAnnotation.type === 'GenericTypeAnnotation' && - typeAnnotation.id.name === 'WithDefault') + typeAnnotation.type === 'GenericTypeAnnotation' && + typeAnnotation.id.name === 'WithDefault' ) { throw new Error( 'WithDefault<> is optional and does not need to be marked as optional. Please remove the ? annotation in front of it.', diff --git a/packages/react-native-codegen/src/parsers/flow/modules/methods.js b/packages/react-native-codegen/src/parsers/flow/modules/methods.js index 2c07b29dc7ea28..79f0b413716e4a 100644 --- a/packages/react-native-codegen/src/parsers/flow/modules/methods.js +++ b/packages/react-native-codegen/src/parsers/flow/modules/methods.js @@ -406,9 +406,7 @@ function buildMethodSchema( const value = getValueFromTypes(property.value, types); if (value.type !== 'FunctionTypeAnnotation') { throw new Error( - `Only methods are supported as module properties. Found ${ - value.type - } in ${property.key.name}`, + `Only methods are supported as module properties. Found ${value.type} in ${property.key.name}`, ); } const params = value.params.map(param => diff --git a/scripts/run-android-ci-instrumentation-tests.js b/scripts/run-android-ci-instrumentation-tests.js index e4812b004166dc..ec9b61a4074c8b 100644 --- a/scripts/run-android-ci-instrumentation-tests.js +++ b/scripts/run-android-ci-instrumentation-tests.js @@ -56,9 +56,7 @@ testClasses.forEach(testClass => { // any faster means Circle CI crashes exec('sleep 10s'); return exec( - `./scripts/run-instrumentation-tests-via-adb-shell.sh ${ - argv.package - } ${testClass}`, + `./scripts/run-instrumentation-tests-via-adb-shell.sh ${argv.package} ${testClass}`, ).code; }, numberOfRetries) ) { diff --git a/yarn.lock b/yarn.lock index 9dc1fd5552f9ba..14c20dd0311dd2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6202,10 +6202,10 @@ prelude-ls@~1.1.2: resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ= -prettier@1.17.0: - version "1.17.0" - resolved "https://registry.npmjs.org/prettier/-/prettier-1.17.0.tgz#53b303676eed22cc14a9f0cec09b477b3026c008" - integrity sha512-sXe5lSt2WQlCbydGETgfm1YBShgOX4HxQkFPvbxkcwgDvGDeqVau8h+12+lmSVlP3rHPz0oavfddSZg/q+Szjw== +prettier@1.19.1: + version "1.19.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb" + integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew== pretty-format@^24.0.0: version "24.0.0" From ccb7dbe895a4d98e25be181db666578bfeba745b Mon Sep 17 00:00:00 2001 From: Scott Wolchok Date: Thu, 9 Apr 2020 12:24:14 -0700 Subject: [PATCH 3/6] Stop using get_fbobjc_enable_exception_lang_compiler_flags_DEPRECATED in xplat Summary: Old deprecated function. Changelog: [Internal] Reviewed By: nlutsenko Differential Revision: D20148856 fbshipit-source-id: 79d6fb97824b059e50f67ff5a0b4c38ec7a19469 --- React/CoreModules/BUCK | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/React/CoreModules/BUCK b/React/CoreModules/BUCK index 2410d229f665ba..6f3cc25677e544 100644 --- a/React/CoreModules/BUCK +++ b/React/CoreModules/BUCK @@ -1,4 +1,4 @@ -load("@fbsource//tools/build_defs/apple:flag_defs.bzl", "OBJC_ARC_PREPROCESSOR_FLAGS", "get_fbobjc_enable_exception_lang_compiler_flags_DEPRECATED", "get_preprocessor_flags_for_build_mode") +load("@fbsource//tools/build_defs/apple:flag_defs.bzl", "OBJC_ARC_PREPROCESSOR_FLAGS", "get_preprocessor_flags_for_build_mode") load("@fbsource//tools/build_defs/oss:rn_defs.bzl", "rn_apple_library", "rn_extra_build_flags") load( "@fbsource//xplat/configurations/buck/apple/plugins/sad_xplat_hosted_configurations:react_module_registration.bzl", @@ -19,6 +19,7 @@ rn_apple_library( "-Wno-unknown-warning-option", ], contacts = ["oncall+react_native@xmail.facebook.com"], + enable_exceptions = True, exported_linker_flags = [ "-weak_framework", "UserNotifications", @@ -33,7 +34,6 @@ rn_apple_library( ], header_path_prefix = "React", labels = ["supermodule:ios/default/public.react_native.infra"], - lang_compiler_flags = get_fbobjc_enable_exception_lang_compiler_flags_DEPRECATED(), link_whole = True, platform_preprocessor_flags = [( "linux", From 449dc37720b24d9d88661314424c9f982e70ec3a Mon Sep 17 00:00:00 2001 From: Radek Czemerys Date: Thu, 9 Apr 2020 13:46:13 -0700 Subject: [PATCH 4/6] Add ProGuard rule for hermes (#28571) Summary: This adds a ProGuard for `hermes` rule so it does not have to be added by users manually. https://github.com/facebook/react-native/issues/28270 ## Changelog [Android] [Added] - ProGuard rule for hermes Pull Request resolved: https://github.com/facebook/react-native/pull/28571 Test Plan: 1. Create a project with/without hermes. 2. Enable proguard. Reviewed By: cpojer Differential Revision: D20947095 Pulled By: hramos fbshipit-source-id: 79b166ad2dd060f20041d9f5cfe2f794c754843d --- ReactAndroid/proguard-rules.pro | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ReactAndroid/proguard-rules.pro b/ReactAndroid/proguard-rules.pro index 7eeef601f7189a..e13dfef7ec70ad 100644 --- a/ReactAndroid/proguard-rules.pro +++ b/ReactAndroid/proguard-rules.pro @@ -51,6 +51,9 @@ -dontwarn com.facebook.react.** -keep,includedescriptorclasses class com.facebook.react.bridge.** { *; } +# hermes +-keep class com.facebook.jni.** { *; } + # okhttp -keepattributes Signature From dff17effe54dc58dda19fcc81ebacbd8f46e9005 Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Thu, 9 Apr 2020 15:30:28 -0700 Subject: [PATCH 5/6] Move CheckBox JS files to FB Internal Summary: Move CheckBox JS files to FB internal ## Changelog: [General] [Removed] This diff removes the CheckBox export from React Native. Internally, we are requiring CheckBox directly now and externally people will have to use the community maintained module. Reviewed By: cpojer Differential Revision: D20910775 fbshipit-source-id: 809e135dc3f68911ac0a004e6eafa8488f0d5327 --- .../AndroidCheckBoxNativeComponent.js | 74 ------ .../Components/CheckBox/CheckBox.android.js | 228 ------------------ Libraries/Components/CheckBox/CheckBox.ios.js | 13 - .../js/examples/CheckBox/CheckBoxExample.js | 148 ------------ RNTester/js/utils/RNTesterList.android.js | 4 - index.js | 23 +- 6 files changed, 13 insertions(+), 477 deletions(-) delete mode 100644 Libraries/Components/CheckBox/AndroidCheckBoxNativeComponent.js delete mode 100644 Libraries/Components/CheckBox/CheckBox.android.js delete mode 100644 Libraries/Components/CheckBox/CheckBox.ios.js delete mode 100644 RNTester/js/examples/CheckBox/CheckBoxExample.js diff --git a/Libraries/Components/CheckBox/AndroidCheckBoxNativeComponent.js b/Libraries/Components/CheckBox/AndroidCheckBoxNativeComponent.js deleted file mode 100644 index 2afb9892690d05..00000000000000 --- a/Libraries/Components/CheckBox/AndroidCheckBoxNativeComponent.js +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow strict-local - * @format - */ - -'use strict'; - -import * as React from 'react'; - -import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands'; - -const requireNativeComponent = require('../../ReactNative/requireNativeComponent'); - -import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes'; -import type {ViewProps} from '../View/ViewPropTypes'; -import type {SyntheticEvent} from '../../Types/CoreEventTypes'; -import type {ProcessedColorValue} from '../../StyleSheet/processColor'; - -type CheckBoxEvent = SyntheticEvent< - $ReadOnly<{| - target: number, - value: boolean, - |}>, ->; - -type NativeProps = $ReadOnly<{| - ...ViewProps, - - /** - * Used in case the props change removes the component. - */ - onChange?: ?(event: CheckBoxEvent) => mixed, - - /** - * Invoked with the new value when the value changes. - */ - onValueChange?: ?(value: boolean) => mixed, - - /** - * Used to locate this view in end-to-end tests. - */ - testID?: ?string, - - on?: ?boolean, - enabled?: boolean, - tintColors: - | {| - true: ?ProcessedColorValue, - false: ?ProcessedColorValue, - |} - | typeof undefined, -|}>; - -type NativeType = HostComponent; - -interface NativeCommands { - +setNativeValue: ( - viewRef: React.ElementRef, - value: boolean, - ) => void; -} - -export const Commands: NativeCommands = codegenNativeCommands({ - supportedCommands: ['setNativeValue'], -}); - -export default (requireNativeComponent( - 'AndroidCheckBox', -): NativeType); diff --git a/Libraries/Components/CheckBox/CheckBox.android.js b/Libraries/Components/CheckBox/CheckBox.android.js deleted file mode 100644 index aed9cd9eb389c4..00000000000000 --- a/Libraries/Components/CheckBox/CheckBox.android.js +++ /dev/null @@ -1,228 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow strict-local - * @format - */ - -'use strict'; - -const React = require('react'); -const StyleSheet = require('../../StyleSheet/StyleSheet'); -const invariant = require('invariant'); -const processColor = require('../../StyleSheet/processColor'); - -const nullthrows = require('nullthrows'); -const setAndForwardRef = require('../../Utilities/setAndForwardRef'); - -import AndroidCheckBoxNativeComponent, { - Commands as AndroidCheckBoxCommands, -} from './AndroidCheckBoxNativeComponent'; - -import type {ViewProps} from '../View/ViewPropTypes'; -import type {SyntheticEvent} from '../../Types/CoreEventTypes'; -import type {ColorValue} from '../../StyleSheet/StyleSheetTypes'; - -type CheckBoxEvent = SyntheticEvent< - $ReadOnly<{| - target: number, - value: boolean, - |}>, ->; - -type CommonProps = $ReadOnly<{| - ...ViewProps, - - /** - * Used in case the props change removes the component. - */ - onChange?: ?(event: CheckBoxEvent) => mixed, - - /** - * Invoked with the new value when the value changes. - */ - onValueChange?: ?(value: boolean) => mixed, - - /** - * Used to locate this view in end-to-end tests. - */ - testID?: ?string, -|}>; - -type Props = $ReadOnly<{| - ...CommonProps, - - /** - * The value of the checkbox. If true the checkbox will be turned on. - * Default value is false. - */ - value?: ?boolean, - - /** - * If true the user won't be able to toggle the checkbox. - * Default value is false. - */ - disabled?: ?boolean, - - /** - * Used to get the ref for the native checkbox - */ - forwardedRef?: ?React.Ref, - - /** - * Controls the colors the checkbox has in checked and unchecked states. - */ - tintColors?: {|true?: ?ColorValue, false?: ?ColorValue|}, -|}>; - -/** - * Renders a boolean input (Android only). - * - * This is a controlled component that requires an `onValueChange` callback that - * updates the `value` prop in order for the component to reflect user actions. - * If the `value` prop is not updated, the component will continue to render - * the supplied `value` prop instead of the expected result of any user actions. - * - * ``` - * import React from 'react'; - * import { AppRegistry, StyleSheet, Text, View, CheckBox } from 'react-native'; - * - * export default class App extends React.Component { - * constructor(props) { - * super(props); - * this.state = { - * checked: false - * } - * } - * - * toggle() { - * this.setState(({checked}) => { - * return { - * checked: !checked - * }; - * }); - * } - * - * render() { - * const {checked} = this.state; - * return ( - * - * Checked - * - * - * ); - * } - * } - * - * const styles = StyleSheet.create({ - * container: { - * flex: 1, - * flexDirection: 'row', - * alignItems: 'center', - * justifyContent: 'center', - * }, - * }); - * - * // skip this line if using Create React Native App - * AppRegistry.registerComponent('App', () => App); - * ``` - * - * @keyword checkbox - * @keyword toggle - */ -class CheckBox extends React.Component { - _nativeRef: ?React.ElementRef = null; - _setNativeRef = setAndForwardRef({ - getForwardedRef: () => this.props.forwardedRef, - setLocalRef: ref => { - this._nativeRef = ref; - }, - }); - - _onChange = (event: CheckBoxEvent) => { - const value = this.props.value ?? false; - AndroidCheckBoxCommands.setNativeValue(nullthrows(this._nativeRef), value); - // Change the props after the native props are set in case the props - // change removes the component - this.props.onChange && this.props.onChange(event); - this.props.onValueChange && - this.props.onValueChange(event.nativeEvent.value); - }; - - _getTintColors(tintColors) { - if (tintColors) { - const processedTextColorTrue = processColor(tintColors.true); - invariant( - processedTextColorTrue == null || - typeof processedTextColorTrue === 'number', - 'Unexpected color given for tintColors.true', - ); - const processedTextColorFalse = processColor(tintColors.true); - invariant( - processedTextColorFalse == null || - typeof processedTextColorFalse === 'number', - 'Unexpected color given for tintColors.false', - ); - return { - true: processedTextColorTrue, - false: processedTextColorFalse, - }; - } else { - return undefined; - } - } - - render() { - const { - disabled: _, - value: __, - tintColors, - style, - forwardedRef, - ...props - } = this.props; - const disabled = this.props.disabled ?? false; - const value = this.props.value ?? false; - - const nativeProps = { - ...props, - onStartShouldSetResponder: () => true, - onResponderTerminationRequest: () => false, - enabled: !disabled, - on: value, - tintColors: this._getTintColors(tintColors), - style: [styles.rctCheckBox, style], - }; - return ( - - ); - } -} - -const styles = StyleSheet.create({ - rctCheckBox: { - height: 32, - width: 32, - }, -}); - -type CheckBoxType = React.AbstractComponent< - Props, - React.ElementRef, ->; - -const CheckBoxWithRef = React.forwardRef< - Props, - React.ElementRef, ->(function CheckBoxWithRef(props, ref) { - return ; -}); - -module.exports = (CheckBoxWithRef: CheckBoxType); diff --git a/Libraries/Components/CheckBox/CheckBox.ios.js b/Libraries/Components/CheckBox/CheckBox.ios.js deleted file mode 100644 index d3a201fce59c21..00000000000000 --- a/Libraries/Components/CheckBox/CheckBox.ios.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow strict-local - * @format - */ - -'use strict'; - -module.exports = require('../UnimplementedViews/UnimplementedView'); diff --git a/RNTester/js/examples/CheckBox/CheckBoxExample.js b/RNTester/js/examples/CheckBox/CheckBoxExample.js deleted file mode 100644 index c9e795f638db07..00000000000000 --- a/RNTester/js/examples/CheckBox/CheckBoxExample.js +++ /dev/null @@ -1,148 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow - * @format - */ - -'use strict'; - -const React = require('react'); -const {CheckBox, Text, View, StyleSheet} = require('react-native'); - -type BasicState = {| - trueCheckBoxIsOn: boolean, - falseCheckBoxIsOn: boolean, -|}; - -type BasicProps = $ReadOnly<{||}>; -class BasicCheckBoxExample extends React.Component { - state = { - trueCheckBoxIsOn: true, - falseCheckBoxIsOn: false, - }; - - render() { - return ( - - this.setState({falseCheckBoxIsOn: value})} - style={styles.checkbox} - value={this.state.falseCheckBoxIsOn} - tintColors={{false: 'red'}} - /> - this.setState({trueCheckBoxIsOn: value})} - value={this.state.trueCheckBoxIsOn} - tintColors={{true: 'green'}} - /> - - ); - } -} - -type DisabledProps = $ReadOnly<{||}>; -class DisabledCheckBoxExample extends React.Component { - render() { - return ( - - - - - ); - } -} - -type EventProps = $ReadOnly<{||}>; -type EventState = {| - eventCheckBoxIsOn: boolean, - eventCheckBoxRegressionIsOn: boolean, -|}; - -class EventCheckBoxExample extends React.Component { - state = { - eventCheckBoxIsOn: false, - eventCheckBoxRegressionIsOn: true, - }; - - render() { - return ( - - - this.setState({eventCheckBoxIsOn: value})} - style={styles.checkbox} - value={this.state.eventCheckBoxIsOn} - /> - this.setState({eventCheckBoxIsOn: value})} - style={styles.checkbox} - value={this.state.eventCheckBoxIsOn} - /> - {this.state.eventCheckBoxIsOn ? 'On' : 'Off'} - - - - this.setState({eventCheckBoxRegressionIsOn: value}) - } - style={styles.checkbox} - value={this.state.eventCheckBoxRegressionIsOn} - /> - - this.setState({eventCheckBoxRegressionIsOn: value}) - } - style={styles.checkbox} - value={this.state.eventCheckBoxRegressionIsOn} - /> - {this.state.eventCheckBoxRegressionIsOn ? 'On' : 'Off'} - - - ); - } -} - -const styles = StyleSheet.create({ - container: { - flexDirection: 'row', - justifyContent: 'space-around', - }, - checkbox: { - marginBottom: 10, - }, -}); - -exports.title = ''; -exports.displayName = 'CheckBoxExample'; -exports.description = 'Native boolean input'; -exports.examples = [ - { - title: - 'CheckBoxes can be set to true or false, and the color of both states can be specified.', - render(): React.Element { - return ; - }, - }, - { - title: 'CheckBoxes can be disabled', - render(): React.Element { - return ; - }, - }, - { - title: 'Change events can be detected', - render(): React.Element { - return ; - }, - }, - { - title: 'CheckBoxes are controlled components', - render(): React.Element { - return ; - }, - }, -]; diff --git a/RNTester/js/utils/RNTesterList.android.js b/RNTester/js/utils/RNTesterList.android.js index 1de9d42a00c7b6..66962af515439d 100644 --- a/RNTester/js/utils/RNTesterList.android.js +++ b/RNTester/js/utils/RNTesterList.android.js @@ -21,10 +21,6 @@ const ComponentExamples: Array = [ key: 'ButtonExample', module: require('../examples/Button/ButtonExample'), }, - { - key: 'CheckBoxExample', - module: require('../examples/CheckBox/CheckBoxExample'), - }, { key: 'FlatListExample', module: require('../examples/FlatList/FlatListExample'), diff --git a/index.js b/index.js index c8f7ae4656f156..944964c171fb37 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,6 @@ import typeof AccessibilityInfo from './Libraries/Components/AccessibilityInfo/AccessibilityInfo'; import typeof ActivityIndicator from './Libraries/Components/ActivityIndicator/ActivityIndicator'; import typeof Button from './Libraries/Components/Button'; -import typeof CheckBox from './Libraries/Components/CheckBox/CheckBox'; import typeof DatePickerIOS from './Libraries/Components/DatePicker/DatePickerIOS'; import typeof DrawerLayoutAndroid from './Libraries/Components/DrawerAndroid/DrawerLayoutAndroid'; import typeof FlatList from './Libraries/Lists/FlatList'; @@ -121,15 +120,6 @@ module.exports = { get Button(): Button { return require('./Libraries/Components/Button'); }, - get CheckBox(): CheckBox { - warnOnce( - 'checkBox-moved', - 'CheckBox has been extracted from react-native core and will be removed in a future release. ' + - "It can now be installed and imported from '@react-native-community/checkbox' instead of 'react-native'. " + - 'See https://github.com/react-native-community/react-native-checkbox', - ); - return require('./Libraries/Components/CheckBox/CheckBox'); - }, get DatePickerIOS(): DatePickerIOS { warnOnce( 'DatePickerIOS-merged', @@ -650,4 +640,17 @@ if (__DEV__) { ); }, }); + + // $FlowFixMe This is intentional: Flow will error when attempting to access CheckBox. + Object.defineProperty(module.exports, 'CheckBox', { + configurable: true, + get() { + invariant( + false, + 'CheckBox has been removed from React Native. ' + + "It can now be installed and imported from '@react-native-community/checkbox' instead of 'react-native'. " + + 'See https://github.com/react-native-community/react-native-checkbox', + ); + }, + }); } From 1ed16c7bc6951dcf2365cd0338d283a03889fd0d Mon Sep 17 00:00:00 2001 From: Adam Gleitman Date: Wed, 7 Jul 2021 16:06:57 -0700 Subject: [PATCH 6/6] Remove CheckBox from docsList.js --- website/server/docsList.js | 1 - 1 file changed, 1 deletion(-) diff --git a/website/server/docsList.js b/website/server/docsList.js index 8b5828f4e60245..98f05266b51aa8 100644 --- a/website/server/docsList.js +++ b/website/server/docsList.js @@ -10,7 +10,6 @@ const components = [ '../Libraries/Components/ActivityIndicator/ActivityIndicator.js', '../Libraries/Components/Button.js', - '../Libraries/Components/CheckBox/CheckBox.android.js', '../Libraries/Components/DatePicker/DatePickerIOS.ios.js', '../Libraries/Components/DatePickerMacOS/DatePickerMacOS.macos.js', '../Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js',