2016-02-23 00:15:35 +00:00
|
|
|
/**
|
2016-05-03 20:30:24 +00:00
|
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
2016-02-23 00:15:35 +00:00
|
|
|
* The examples provided by Facebook are for non-commercial testing and
|
|
|
|
* evaluation purposes only.
|
|
|
|
*
|
|
|
|
* Facebook reserves all rights not expressly granted.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* @flow
|
2017-02-25 11:05:32 +00:00
|
|
|
* @providesModule UIExplorerExampleList
|
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');
|
2016-02-23 00:15:35 +00:00
|
|
|
const UIExplorerActions = require('./UIExplorerActions');
|
2016-09-06 21:44:15 +00:00
|
|
|
const UIExplorerStatePersister = require('./UIExplorerStatePersister');
|
2016-12-19 14:26:07 +00:00
|
|
|
const View = require('View');
|
2016-05-03 20:30:24 +00:00
|
|
|
|
2016-02-23 00:15:35 +00:00
|
|
|
import type {
|
|
|
|
UIExplorerExample,
|
2016-05-03 20:30:24 +00:00
|
|
|
} from './UIExplorerList.ios';
|
2016-09-06 21:44:15 +00:00
|
|
|
import type {
|
|
|
|
PassProps,
|
|
|
|
} from './UIExplorerStatePersister';
|
|
|
|
import type {
|
|
|
|
StyleObj,
|
|
|
|
} from 'StyleSheetTypes';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
onNavigate: Function,
|
|
|
|
list: {
|
|
|
|
ComponentExamples: Array<UIExplorerExample>,
|
|
|
|
APIExamples: Array<UIExplorerExample>,
|
|
|
|
},
|
|
|
|
persister: PassProps<*>,
|
|
|
|
searchTextInputStyle: StyleObj,
|
|
|
|
style?: ?StyleObj,
|
|
|
|
};
|
2016-07-13 21:22:25 +00:00
|
|
|
|
2017-02-28 16:47:51 +00:00
|
|
|
class RowComponent extends React.PureComponent {
|
|
|
|
props: {
|
|
|
|
item: Object,
|
|
|
|
onNavigate: Function,
|
|
|
|
onPress?: Function,
|
|
|
|
};
|
|
|
|
_onPress = () => {
|
|
|
|
if (this.props.onPress) {
|
|
|
|
this.props.onPress();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.props.onNavigate(UIExplorerActions.ExampleAction(this.props.item.key));
|
|
|
|
};
|
|
|
|
render() {
|
|
|
|
const {item} = this.props;
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<TouchableHighlight 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>
|
|
|
|
<View style={styles.separator} />
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const renderSectionHeader = ({section}) =>
|
|
|
|
<Text style={styles.sectionHeader}>
|
|
|
|
{section.title}
|
|
|
|
</Text>;
|
|
|
|
|
2016-09-06 21:44:15 +00:00
|
|
|
class UIExplorerExampleList extends React.Component {
|
|
|
|
props: Props
|
2016-05-05 23:51:34 +00:00
|
|
|
|
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) =>
|
|
|
|
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
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
_renderItem = ({item}) => <RowComponent item={item} onNavigate={this.props.onNavigate} />;
|
|
|
|
|
2016-10-16 11:11:59 +00:00
|
|
|
_renderTitleRow(): ?React.Element<any> {
|
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: {
|
|
|
|
title: 'UIExplorer',
|
|
|
|
description: 'React Native Examples',
|
|
|
|
}}}
|
|
|
|
onNavigate={this.props.onNavigate}
|
|
|
|
onPress={() => {
|
2017-02-28 23:39:24 +00:00
|
|
|
this.props.onNavigate(UIExplorerActions.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> {
|
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 {
|
2016-05-03 20:30:24 +00:00
|
|
|
this.props.onNavigate(UIExplorerActions.ExampleAction(exampleKey));
|
2016-02-23 00:15:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-06 21:44:15 +00:00
|
|
|
UIExplorerExampleList = UIExplorerStatePersister.createContainer(UIExplorerExampleList, {
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = UIExplorerExampleList;
|