2016-02-23 00:15:35 +00:00
|
|
|
/**
|
2017-05-06 03:50:47 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
2016-05-03 20:30:24 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-05-03 20:30:24 +00:00
|
|
|
*
|
2016-02-23 00:15:35 +00:00
|
|
|
* @flow
|
2017-05-06 03:50:47 +00:00
|
|
|
* @providesModule RNTesterExampleList
|
2016-02-23 00:15:35 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-12-19 14:26:07 +00:00
|
|
|
const Platform = require('Platform');
|
2016-04-09 03:36:40 +00:00
|
|
|
const React = require('react');
|
2017-02-28 16:47:51 +00:00
|
|
|
const SectionList = require('SectionList');
|
2016-05-03 20:30:24 +00:00
|
|
|
const StyleSheet = require('StyleSheet');
|
|
|
|
const Text = require('Text');
|
|
|
|
const TextInput = require('TextInput');
|
|
|
|
const TouchableHighlight = require('TouchableHighlight');
|
2017-05-06 03:50:47 +00:00
|
|
|
const RNTesterActions = require('./RNTesterActions');
|
|
|
|
const RNTesterStatePersister = require('./RNTesterStatePersister');
|
2016-12-19 14:26:07 +00:00
|
|
|
const View = require('View');
|
2016-05-03 20:30:24 +00:00
|
|
|
|
2018-03-07 20:03:26 +00:00
|
|
|
import type {RNTesterExample} from './RNTesterList.ios';
|
|
|
|
import type {PassProps} from './RNTesterStatePersister';
|
2018-03-07 21:12:51 +00:00
|
|
|
import type {DangerouslyImpreciseStyleProp} from 'StyleSheet';
|
2016-09-06 21:44:15 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
onNavigate: Function,
|
|
|
|
list: {
|
2017-05-06 03:50:47 +00:00
|
|
|
ComponentExamples: Array<RNTesterExample>,
|
|
|
|
APIExamples: Array<RNTesterExample>,
|
2016-09-06 21:44:15 +00:00
|
|
|
},
|
|
|
|
persister: PassProps<*>,
|
2018-03-07 21:12:51 +00:00
|
|
|
searchTextInputStyle: DangerouslyImpreciseStyleProp,
|
|
|
|
style?: ?DangerouslyImpreciseStyleProp,
|
2016-09-06 21:44:15 +00:00
|
|
|
};
|
2016-07-13 21:22:25 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class RowComponent extends React.PureComponent<{
|
|
|
|
item: Object,
|
|
|
|
onNavigate: Function,
|
|
|
|
onPress?: Function,
|
|
|
|
onShowUnderlay?: Function,
|
|
|
|
onHideUnderlay?: Function,
|
|
|
|
}> {
|
2017-02-28 16:47:51 +00:00
|
|
|
_onPress = () => {
|
|
|
|
if (this.props.onPress) {
|
|
|
|
this.props.onPress();
|
|
|
|
return;
|
|
|
|
}
|
2017-05-06 03:50:47 +00:00
|
|
|
this.props.onNavigate(RNTesterActions.ExampleAction(this.props.item.key));
|
2017-02-28 16:47:51 +00:00
|
|
|
};
|
|
|
|
render() {
|
|
|
|
const {item} = this.props;
|
|
|
|
return (
|
2017-04-12 23:57:12 +00:00
|
|
|
<TouchableHighlight {...this.props} onPress={this._onPress}>
|
|
|
|
<View style={styles.row}>
|
|
|
|
<Text style={styles.rowTitleText}>
|
|
|
|
{item.module.title}
|
|
|
|
</Text>
|
|
|
|
<Text style={styles.rowDetailText}>
|
|
|
|
{item.module.description}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
2017-02-28 16:47:51 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const renderSectionHeader = ({section}) =>
|
|
|
|
<Text style={styles.sectionHeader}>
|
|
|
|
{section.title}
|
|
|
|
</Text>;
|
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class RNTesterExampleList extends React.Component<Props, $FlowFixMeState> {
|
2017-02-28 16:47:51 +00:00
|
|
|
render() {
|
2016-09-06 21:44:15 +00:00
|
|
|
const filterText = this.props.persister.state.filter;
|
2016-02-23 00:15:35 +00:00
|
|
|
const filterRegex = new RegExp(String(filterText), 'i');
|
2017-02-28 16:47:51 +00:00
|
|
|
const filter = (example) =>
|
2018-03-20 01:24:11 +00:00
|
|
|
/* $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. */
|
2017-02-28 16:47:51 +00:00
|
|
|
this.props.disableSearch ||
|
|
|
|
filterRegex.test(example.module.title) &&
|
|
|
|
(!Platform.isTVOS || example.supportsTVOS);
|
2016-02-23 00:15:35 +00:00
|
|
|
|
2017-02-28 16:47:51 +00:00
|
|
|
const sections = [
|
|
|
|
{
|
|
|
|
data: this.props.list.ComponentExamples.filter(filter),
|
|
|
|
title: 'COMPONENTS',
|
|
|
|
key: 'c',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
data: this.props.list.APIExamples.filter(filter),
|
|
|
|
title: 'APIS',
|
|
|
|
key: 'a',
|
|
|
|
},
|
|
|
|
];
|
2016-02-23 00:15:35 +00:00
|
|
|
return (
|
|
|
|
<View style={[styles.listContainer, this.props.style]}>
|
|
|
|
{this._renderTitleRow()}
|
|
|
|
{this._renderTextInput()}
|
2017-02-28 16:47:51 +00:00
|
|
|
<SectionList
|
2017-04-12 23:57:12 +00:00
|
|
|
ItemSeparatorComponent={ItemSeparator}
|
|
|
|
contentContainerStyle={{backgroundColor: 'white'}}
|
2016-02-23 00:15:35 +00:00
|
|
|
style={styles.list}
|
2017-02-28 16:47:51 +00:00
|
|
|
sections={sections}
|
|
|
|
renderItem={this._renderItem}
|
2016-06-14 05:15:47 +00:00
|
|
|
enableEmptySections={true}
|
2017-02-28 16:47:51 +00:00
|
|
|
itemShouldUpdate={this._itemShouldUpdate}
|
2016-12-08 05:39:54 +00:00
|
|
|
keyboardShouldPersistTaps="handled"
|
2016-02-23 00:15:35 +00:00
|
|
|
automaticallyAdjustContentInsets={false}
|
|
|
|
keyboardDismissMode="on-drag"
|
2017-02-28 16:47:51 +00:00
|
|
|
legacyImplementation={false}
|
|
|
|
renderSectionHeader={renderSectionHeader}
|
2016-02-23 00:15:35 +00:00
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-02-28 16:47:51 +00:00
|
|
|
_itemShouldUpdate(curr, prev) {
|
|
|
|
return curr.item !== prev.item;
|
|
|
|
}
|
|
|
|
|
2017-04-12 23:57:12 +00:00
|
|
|
_renderItem = ({item, separators}) => (
|
|
|
|
<RowComponent
|
|
|
|
item={item}
|
|
|
|
onNavigate={this.props.onNavigate}
|
|
|
|
onShowUnderlay={separators.highlight}
|
|
|
|
onHideUnderlay={separators.unhighlight}
|
|
|
|
/>
|
|
|
|
);
|
2017-02-28 16:47:51 +00:00
|
|
|
|
2016-10-16 11:11:59 +00:00
|
|
|
_renderTitleRow(): ?React.Element<any> {
|
2018-03-20 01:24:11 +00:00
|
|
|
/* $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. */
|
2016-02-23 00:15:35 +00:00
|
|
|
if (!this.props.displayTitleRow) {
|
|
|
|
return null;
|
|
|
|
}
|
2017-02-28 16:47:51 +00:00
|
|
|
return (
|
|
|
|
<RowComponent
|
|
|
|
item={{module: {
|
2017-05-06 03:50:47 +00:00
|
|
|
title: 'RNTester',
|
2017-02-28 16:47:51 +00:00
|
|
|
description: 'React Native Examples',
|
|
|
|
}}}
|
|
|
|
onNavigate={this.props.onNavigate}
|
|
|
|
onPress={() => {
|
2017-05-06 03:50:47 +00:00
|
|
|
this.props.onNavigate(RNTesterActions.ExampleList());
|
2017-02-28 16:47:51 +00:00
|
|
|
}}
|
|
|
|
/>
|
2016-02-23 00:15:35 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-10-16 11:11:59 +00:00
|
|
|
_renderTextInput(): ?React.Element<any> {
|
2018-03-20 01:24:11 +00:00
|
|
|
/* $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. */
|
2016-02-23 00:15:35 +00:00
|
|
|
if (this.props.disableSearch) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<View style={styles.searchRow}>
|
|
|
|
<TextInput
|
|
|
|
autoCapitalize="none"
|
|
|
|
autoCorrect={false}
|
|
|
|
clearButtonMode="always"
|
|
|
|
onChangeText={text => {
|
2016-09-06 21:44:15 +00:00
|
|
|
this.props.persister.setState(() => ({filter: text}));
|
2016-02-23 00:15:35 +00:00
|
|
|
}}
|
|
|
|
placeholder="Search..."
|
2016-09-14 00:15:10 +00:00
|
|
|
underlineColorAndroid="transparent"
|
2016-02-23 00:15:35 +00:00
|
|
|
style={[styles.searchTextInput, this.props.searchTextInputStyle]}
|
|
|
|
testID="explorer_search"
|
2016-09-06 21:44:15 +00:00
|
|
|
value={this.props.persister.state.filter}
|
2016-02-23 00:15:35 +00:00
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_handleRowPress(exampleKey: string): void {
|
2017-05-06 03:50:47 +00:00
|
|
|
this.props.onNavigate(RNTesterActions.ExampleAction(exampleKey));
|
2016-02-23 00:15:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-12 23:57:12 +00:00
|
|
|
const ItemSeparator = ({highlighted}) => (
|
|
|
|
<View style={highlighted ? styles.separatorHighlighted : styles.separator} />
|
|
|
|
);
|
|
|
|
|
2017-05-06 03:50:47 +00:00
|
|
|
RNTesterExampleList = RNTesterStatePersister.createContainer(RNTesterExampleList, {
|
2016-09-06 21:44:15 +00:00
|
|
|
cacheKeySuffix: () => 'mainList',
|
|
|
|
getInitialState: () => ({filter: ''}),
|
|
|
|
});
|
|
|
|
|
2016-05-03 20:30:24 +00:00
|
|
|
const styles = StyleSheet.create({
|
2016-02-23 00:15:35 +00:00
|
|
|
listContainer: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
list: {
|
|
|
|
backgroundColor: '#eeeeee',
|
|
|
|
},
|
|
|
|
sectionHeader: {
|
2017-03-02 23:09:39 +00:00
|
|
|
backgroundColor: '#eeeeee',
|
2016-02-23 00:15:35 +00:00
|
|
|
padding: 5,
|
|
|
|
fontWeight: '500',
|
|
|
|
fontSize: 11,
|
|
|
|
},
|
|
|
|
row: {
|
|
|
|
backgroundColor: 'white',
|
|
|
|
justifyContent: 'center',
|
|
|
|
paddingHorizontal: 15,
|
|
|
|
paddingVertical: 8,
|
|
|
|
},
|
|
|
|
separator: {
|
|
|
|
height: StyleSheet.hairlineWidth,
|
|
|
|
backgroundColor: '#bbbbbb',
|
|
|
|
marginLeft: 15,
|
|
|
|
},
|
2017-04-12 23:57:12 +00:00
|
|
|
separatorHighlighted: {
|
|
|
|
height: StyleSheet.hairlineWidth,
|
|
|
|
backgroundColor: 'rgb(217, 217, 217)',
|
|
|
|
},
|
2016-02-23 00:15:35 +00:00
|
|
|
rowTitleText: {
|
|
|
|
fontSize: 17,
|
|
|
|
fontWeight: '500',
|
|
|
|
},
|
|
|
|
rowDetailText: {
|
|
|
|
fontSize: 15,
|
|
|
|
color: '#888888',
|
|
|
|
lineHeight: 20,
|
|
|
|
},
|
|
|
|
searchRow: {
|
|
|
|
backgroundColor: '#eeeeee',
|
|
|
|
padding: 10,
|
|
|
|
},
|
|
|
|
searchTextInput: {
|
|
|
|
backgroundColor: 'white',
|
|
|
|
borderColor: '#cccccc',
|
|
|
|
borderRadius: 3,
|
|
|
|
borderWidth: 1,
|
|
|
|
paddingLeft: 8,
|
2016-09-14 00:15:10 +00:00
|
|
|
paddingVertical: 0,
|
2016-02-23 00:15:35 +00:00
|
|
|
height: 35,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2017-05-06 03:50:47 +00:00
|
|
|
module.exports = RNTesterExampleList;
|