From 4488f1402218ff84d052a88c8758b25205781aee Mon Sep 17 00:00:00 2001 From: Josh Justice Date: Sun, 23 Dec 2018 15:32:50 -0600 Subject: [PATCH 01/10] Extract filter --- RNTester/js/RNTesterExampleList.js | 106 ++++++++++++++++++----------- 1 file changed, 66 insertions(+), 40 deletions(-) diff --git a/RNTester/js/RNTesterExampleList.js b/RNTester/js/RNTesterExampleList.js index 48bfab00285269..4c98e98f30abd1 100644 --- a/RNTester/js/RNTesterExampleList.js +++ b/RNTester/js/RNTesterExampleList.js @@ -68,7 +68,18 @@ const renderSectionHeader = ({section}) => ( {section.title} ); -class RNTesterExampleList extends React.Component { +type FilterProps = { + render: Function, + list: { + ComponentExamples: Array, + APIExamples: Array, + }, +}; + +class RNTesterExampleFilter extends React.Component< + FilterProps, + $FlowFixMeState, +> { state = {filter: ''}; render() { @@ -105,22 +116,63 @@ class RNTesterExampleList extends React.Component { key: 'a', }, ]; + return ( + + {this._renderTextInput()} + {this.props.render({sections})} + + ); + } + + _renderTextInput(): ?React.Element { + /* $FlowFixMe(>=0.68.0 site=react_native_fb) This comment suppresses an + * error found when Flow v0.68 was deployed. To see the error delete this + * comment and run Flow. */ + if (this.props.disableSearch) { + return null; + } + return ( + + { + this.setState(() => ({filter: text})); + }} + placeholder="Search..." + underlineColorAndroid="transparent" + style={styles.searchTextInput} + testID="explorer_search" + value={this.state.filter} + /> + + ); + } +} + +class RNTesterExampleList extends React.Component { + render() { return ( {this._renderTitleRow()} - {this._renderTextInput()} - ( + + )} /> ); @@ -162,32 +214,6 @@ class RNTesterExampleList extends React.Component { ); } - _renderTextInput(): ?React.Element { - /* $FlowFixMe(>=0.68.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.68 was deployed. To see the error delete this - * comment and run Flow. */ - if (this.props.disableSearch) { - return null; - } - return ( - - { - this.setState(() => ({filter: text})); - }} - placeholder="Search..." - underlineColorAndroid="transparent" - style={styles.searchTextInput} - testID="explorer_search" - value={this.state.filter} - /> - - ); - } - _handleRowPress(exampleKey: string): void { this.props.onNavigate(RNTesterActions.ExampleAction(exampleKey)); } From cd2a2d17dd260deafcbcfd06f1a4130b1d59ada2 Mon Sep 17 00:00:00 2001 From: Josh Justice Date: Sun, 23 Dec 2018 15:37:19 -0600 Subject: [PATCH 02/10] Extract filter to a separate file --- RNTester/js/RNTesterExampleFilter.js | 115 +++++++++++++++++++++++++++ RNTester/js/RNTesterExampleList.js | 99 +---------------------- 2 files changed, 116 insertions(+), 98 deletions(-) create mode 100644 RNTester/js/RNTesterExampleFilter.js diff --git a/RNTester/js/RNTesterExampleFilter.js b/RNTester/js/RNTesterExampleFilter.js new file mode 100644 index 00000000000000..b7caa956412b6f --- /dev/null +++ b/RNTester/js/RNTesterExampleFilter.js @@ -0,0 +1,115 @@ +/** + * 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. + * + * @format + * @flow + */ + +const Platform = require('Platform'); +const React = require('react'); +const StyleSheet = require('StyleSheet'); +const TextInput = require('TextInput'); +const View = require('View'); + +import type {RNTesterExample} from './RNTesterList.ios'; + +type Props = { + render: Function, + list: { + ComponentExamples: Array, + APIExamples: Array, + }, +}; + +class RNTesterExampleFilter extends React.Component { + state = {filter: ''}; + + render() { + const filterText = this.state.filter; + let filterRegex = /.*/; + + try { + filterRegex = new RegExp(String(filterText), 'i'); + } catch (error) { + console.warn( + 'Failed to create RegExp: %s\n%s', + filterText, + error.message, + ); + } + + const filter = example => + /* $FlowFixMe(>=0.68.0 site=react_native_fb) This comment suppresses an + * error found when Flow v0.68 was deployed. To see the error delete this + * comment and run Flow. */ + this.props.disableSearch || + (filterRegex.test(example.module.title) && + (!Platform.isTV || example.supportsTVOS)); + + const sections = [ + { + data: this.props.list.ComponentExamples.filter(filter), + title: 'COMPONENTS', + key: 'c', + }, + { + data: this.props.list.APIExamples.filter(filter), + title: 'APIS', + key: 'a', + }, + ]; + return ( + + {this._renderTextInput()} + {this.props.render({sections})} + + ); + } + + _renderTextInput(): ?React.Element { + /* $FlowFixMe(>=0.68.0 site=react_native_fb) This comment suppresses an + * error found when Flow v0.68 was deployed. To see the error delete this + * comment and run Flow. */ + if (this.props.disableSearch) { + return null; + } + return ( + + { + this.setState(() => ({filter: text})); + }} + placeholder="Search..." + underlineColorAndroid="transparent" + style={styles.searchTextInput} + testID="explorer_search" + value={this.state.filter} + /> + + ); + } +} + +const styles = StyleSheet.create({ + searchRow: { + backgroundColor: '#eeeeee', + padding: 10, + }, + searchTextInput: { + backgroundColor: 'white', + borderColor: '#cccccc', + borderRadius: 3, + borderWidth: 1, + paddingLeft: 8, + paddingVertical: 0, + height: 35, + }, +}); + +module.exports = RNTesterExampleFilter; diff --git a/RNTester/js/RNTesterExampleList.js b/RNTester/js/RNTesterExampleList.js index 4c98e98f30abd1..3c09d6171a99e0 100644 --- a/RNTester/js/RNTesterExampleList.js +++ b/RNTester/js/RNTesterExampleList.js @@ -10,14 +10,13 @@ 'use strict'; -const Platform = require('Platform'); const React = require('react'); const SectionList = require('SectionList'); const StyleSheet = require('StyleSheet'); const Text = require('Text'); -const TextInput = require('TextInput'); const TouchableHighlight = require('TouchableHighlight'); const RNTesterActions = require('./RNTesterActions'); +const RNTesterExampleFilter = require('./RNTesterExampleFilter'); const View = require('View'); /* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found when @@ -68,89 +67,6 @@ const renderSectionHeader = ({section}) => ( {section.title} ); -type FilterProps = { - render: Function, - list: { - ComponentExamples: Array, - APIExamples: Array, - }, -}; - -class RNTesterExampleFilter extends React.Component< - FilterProps, - $FlowFixMeState, -> { - state = {filter: ''}; - - render() { - const filterText = this.state.filter; - let filterRegex = /.*/; - - try { - filterRegex = new RegExp(String(filterText), 'i'); - } catch (error) { - console.warn( - 'Failed to create RegExp: %s\n%s', - filterText, - error.message, - ); - } - - const filter = example => - /* $FlowFixMe(>=0.68.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.68 was deployed. To see the error delete this - * comment and run Flow. */ - this.props.disableSearch || - (filterRegex.test(example.module.title) && - (!Platform.isTV || example.supportsTVOS)); - - const sections = [ - { - data: this.props.list.ComponentExamples.filter(filter), - title: 'COMPONENTS', - key: 'c', - }, - { - data: this.props.list.APIExamples.filter(filter), - title: 'APIS', - key: 'a', - }, - ]; - return ( - - {this._renderTextInput()} - {this.props.render({sections})} - - ); - } - - _renderTextInput(): ?React.Element { - /* $FlowFixMe(>=0.68.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.68 was deployed. To see the error delete this - * comment and run Flow. */ - if (this.props.disableSearch) { - return null; - } - return ( - - { - this.setState(() => ({filter: text})); - }} - placeholder="Search..." - underlineColorAndroid="transparent" - style={styles.searchTextInput} - testID="explorer_search" - value={this.state.filter} - /> - - ); - } -} - class RNTesterExampleList extends React.Component { render() { return ( @@ -260,19 +176,6 @@ const styles = StyleSheet.create({ color: '#888888', lineHeight: 20, }, - searchRow: { - backgroundColor: '#eeeeee', - padding: 10, - }, - searchTextInput: { - backgroundColor: 'white', - borderColor: '#cccccc', - borderRadius: 3, - borderWidth: 1, - paddingLeft: 8, - paddingVertical: 0, - height: 35, - }, }); module.exports = RNTesterExampleList; From 08732bf42004fc5d3a683589880725f39920743d Mon Sep 17 00:00:00 2001 From: Josh Justice Date: Sun, 23 Dec 2018 15:58:43 -0600 Subject: [PATCH 03/10] Make filter agnostic of sections passed in --- RNTester/js/RNTesterExampleFilter.js | 19 ++++++------------- RNTester/js/RNTesterExampleList.js | 19 ++++++++++++++++--- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/RNTester/js/RNTesterExampleFilter.js b/RNTester/js/RNTesterExampleFilter.js index b7caa956412b6f..9bd0a2e5c11e13 100644 --- a/RNTester/js/RNTesterExampleFilter.js +++ b/RNTester/js/RNTesterExampleFilter.js @@ -49,22 +49,15 @@ class RNTesterExampleFilter extends React.Component { (filterRegex.test(example.module.title) && (!Platform.isTV || example.supportsTVOS)); - const sections = [ - { - data: this.props.list.ComponentExamples.filter(filter), - title: 'COMPONENTS', - key: 'c', - }, - { - data: this.props.list.APIExamples.filter(filter), - title: 'APIS', - key: 'a', - }, - ]; + const filteredSections = this.props.sections.map(section => ({ + ...section, + data: section.data.filter(filter), + })); + return ( {this._renderTextInput()} - {this.props.render({sections})} + {this.props.render({filteredSections})} ); } diff --git a/RNTester/js/RNTesterExampleList.js b/RNTester/js/RNTesterExampleList.js index 3c09d6171a99e0..5ff5cefffb13bc 100644 --- a/RNTester/js/RNTesterExampleList.js +++ b/RNTester/js/RNTesterExampleList.js @@ -69,17 +69,30 @@ const renderSectionHeader = ({section}) => ( class RNTesterExampleList extends React.Component { render() { + const sections = [ + { + data: this.props.list.ComponentExamples, + title: 'COMPONENTS', + key: 'c', + }, + { + data: this.props.list.APIExamples, + title: 'APIS', + key: 'a', + }, + ]; + return ( {this._renderTitleRow()} ( + sections={sections} + render={({filteredSections}) => ( Date: Mon, 24 Dec 2018 07:22:57 -0600 Subject: [PATCH 04/10] Make filter function a prop to filter component --- RNTester/js/RNTesterExampleFilter.js | 13 +++---------- RNTester/js/RNTesterExampleList.js | 9 +++++++++ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/RNTester/js/RNTesterExampleFilter.js b/RNTester/js/RNTesterExampleFilter.js index 9bd0a2e5c11e13..0454fbeb8710da 100644 --- a/RNTester/js/RNTesterExampleFilter.js +++ b/RNTester/js/RNTesterExampleFilter.js @@ -8,20 +8,15 @@ * @flow */ -const Platform = require('Platform'); const React = require('react'); const StyleSheet = require('StyleSheet'); const TextInput = require('TextInput'); const View = require('View'); -import type {RNTesterExample} from './RNTesterList.ios'; - type Props = { + filter: Function, render: Function, - list: { - ComponentExamples: Array, - APIExamples: Array, - }, + sections: Object, }; class RNTesterExampleFilter extends React.Component { @@ -45,9 +40,7 @@ class RNTesterExampleFilter extends React.Component { /* $FlowFixMe(>=0.68.0 site=react_native_fb) This comment suppresses an * error found when Flow v0.68 was deployed. To see the error delete this * comment and run Flow. */ - this.props.disableSearch || - (filterRegex.test(example.module.title) && - (!Platform.isTV || example.supportsTVOS)); + this.props.disableSearch || this.props.filter({example, filterRegex}); const filteredSections = this.props.sections.map(section => ({ ...section, diff --git a/RNTester/js/RNTesterExampleList.js b/RNTester/js/RNTesterExampleList.js index 5ff5cefffb13bc..cc252245a72349 100644 --- a/RNTester/js/RNTesterExampleList.js +++ b/RNTester/js/RNTesterExampleList.js @@ -10,6 +10,7 @@ 'use strict'; +const Platform = require('Platform'); const React = require('react'); const SectionList = require('SectionList'); const StyleSheet = require('StyleSheet'); @@ -69,6 +70,13 @@ const renderSectionHeader = ({section}) => ( class RNTesterExampleList extends React.Component { render() { + const filter = ({example, filterRegex}) => + /* $FlowFixMe(>=0.68.0 site=react_native_fb) This comment suppresses an + * error found when Flow v0.68 was deployed. To see the error delete this + * comment and run Flow. */ + filterRegex.test(example.module.title) && + (!Platform.isTV || example.supportsTVOS); + const sections = [ { data: this.props.list.ComponentExamples, @@ -87,6 +95,7 @@ class RNTesterExampleList extends React.Component { {this._renderTitleRow()} ( Date: Mon, 24 Dec 2018 07:56:50 -0600 Subject: [PATCH 05/10] Add filtering to example container --- RNTester/js/RNTesterExampleContainer.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/RNTester/js/RNTesterExampleContainer.js b/RNTester/js/RNTesterExampleContainer.js index e1c66e3333f1dd..3016e7d1b97b13 100644 --- a/RNTester/js/RNTesterExampleContainer.js +++ b/RNTester/js/RNTesterExampleContainer.js @@ -12,6 +12,7 @@ const React = require('react'); const {Platform} = require('react-native'); const RNTesterBlock = require('./RNTesterBlock'); +const RNTesterExampleFilter = require('./RNTesterExampleFilter'); const RNTesterPage = require('./RNTesterPage'); class RNTesterExampleContainer extends React.Component { @@ -37,9 +38,25 @@ class RNTesterExampleContainer extends React.Component { return ; } + const filter = ({example, filterRegex}) => filterRegex.test(example.title); + + const sections = [ + { + data: this.props.module.examples, + title: 'EXAMPLES', + key: 'e', + }, + ]; + return ( - {this.props.module.examples.map(this.renderExample)} + + filteredSections[0].data.map(this.renderExample) + } + /> ); } From 3bd1890d149fbad18a85fdd20c7fc40f7731be7d Mon Sep 17 00:00:00 2001 From: Josh Justice Date: Mon, 24 Dec 2018 08:10:19 -0600 Subject: [PATCH 06/10] Remove unused type --- RNTester/js/RNTesterExampleList.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RNTester/js/RNTesterExampleList.js b/RNTester/js/RNTesterExampleList.js index cc252245a72349..98a0f07be97e39 100644 --- a/RNTester/js/RNTesterExampleList.js +++ b/RNTester/js/RNTesterExampleList.js @@ -23,7 +23,7 @@ const View = require('View'); /* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found when * making Flow check .android.js files. */ import type {RNTesterExample} from './RNTesterList.ios'; -import type {TextStyleProp, ViewStyleProp} from 'StyleSheet'; +import type {ViewStyleProp} from 'StyleSheet'; type Props = { onNavigate: Function, From 8d3609b52b38b4eceda73eb631da709efbc4f556 Mon Sep 17 00:00:00 2001 From: Josh Justice Date: Mon, 24 Dec 2018 08:29:02 -0600 Subject: [PATCH 07/10] Add use strict to filter file --- RNTester/js/RNTesterExampleFilter.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RNTester/js/RNTesterExampleFilter.js b/RNTester/js/RNTesterExampleFilter.js index 0454fbeb8710da..b86a73f4c32fc9 100644 --- a/RNTester/js/RNTesterExampleFilter.js +++ b/RNTester/js/RNTesterExampleFilter.js @@ -8,6 +8,8 @@ * @flow */ +'use strict'; + const React = require('react'); const StyleSheet = require('StyleSheet'); const TextInput = require('TextInput'); From b6e11342a3f42c219b02a4fc34d440f35ae5b4b8 Mon Sep 17 00:00:00 2001 From: Josh Justice Date: Mon, 24 Dec 2018 08:36:04 -0600 Subject: [PATCH 08/10] Extract inline style --- RNTester/js/RNTesterExampleList.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/RNTester/js/RNTesterExampleList.js b/RNTester/js/RNTesterExampleList.js index 98a0f07be97e39..78fb8ed7ebe4cd 100644 --- a/RNTester/js/RNTesterExampleList.js +++ b/RNTester/js/RNTesterExampleList.js @@ -99,7 +99,7 @@ class RNTesterExampleList extends React.Component { render={({filteredSections}) => ( Date: Sat, 29 Dec 2018 15:05:13 -0600 Subject: [PATCH 09/10] Update RNTester/js/RNTesterExampleContainer.js Co-Authored-By: CodingItWrong --- RNTester/js/RNTesterExampleContainer.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/RNTester/js/RNTesterExampleContainer.js b/RNTester/js/RNTesterExampleContainer.js index 3016e7d1b97b13..0d8d5521141167 100644 --- a/RNTester/js/RNTesterExampleContainer.js +++ b/RNTester/js/RNTesterExampleContainer.js @@ -38,6 +38,11 @@ class RNTesterExampleContainer extends React.Component { return ; } + if (this.props.module.examples.length === 1) { + const Example = this.props.module.examples[0].render; + return ; + } + const filter = ({example, filterRegex}) => filterRegex.test(example.title); const sections = [ From f39e4eae134fc1bce9cc6bfbcd47ad063c5b10c9 Mon Sep 17 00:00:00 2001 From: Rick Hanlon Date: Sat, 29 Dec 2018 21:09:49 +0000 Subject: [PATCH 10/10] Fix lint --- RNTester/js/RNTesterExampleContainer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RNTester/js/RNTesterExampleContainer.js b/RNTester/js/RNTesterExampleContainer.js index 0d8d5521141167..03b2a1cb762713 100644 --- a/RNTester/js/RNTesterExampleContainer.js +++ b/RNTester/js/RNTesterExampleContainer.js @@ -42,7 +42,7 @@ class RNTesterExampleContainer extends React.Component { const Example = this.props.module.examples[0].render; return ; } - + const filter = ({example, filterRegex}) => filterRegex.test(example.title); const sections = [