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
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-05-03 20:30:24 +00:00
|
|
|
const ListView = require('ListView');
|
2016-04-09 03:36:40 +00:00
|
|
|
const React = require('react');
|
2016-05-03 20:30:24 +00:00
|
|
|
const StyleSheet = require('StyleSheet');
|
|
|
|
const Text = require('Text');
|
|
|
|
const TextInput = require('TextInput');
|
|
|
|
const TouchableHighlight = require('TouchableHighlight');
|
|
|
|
const View = require('View');
|
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-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-02-23 00:15:35 +00:00
|
|
|
|
2016-09-06 21:44:15 +00:00
|
|
|
import type {
|
|
|
|
PassProps,
|
|
|
|
} from './UIExplorerStatePersister';
|
|
|
|
|
|
|
|
import type {
|
|
|
|
StyleObj,
|
|
|
|
} from 'StyleSheetTypes';
|
|
|
|
|
2016-02-23 00:15:35 +00:00
|
|
|
const ds = new ListView.DataSource({
|
|
|
|
rowHasChanged: (r1, r2) => r1 !== r2,
|
|
|
|
sectionHeaderHasChanged: (h1, h2) => h1 !== h2,
|
|
|
|
});
|
|
|
|
|
2016-09-06 21:44:15 +00:00
|
|
|
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
|
|
|
|
2016-09-06 21:44:15 +00:00
|
|
|
class UIExplorerExampleList extends React.Component {
|
|
|
|
props: Props
|
2016-05-05 23:51:34 +00:00
|
|
|
|
2016-10-16 11:11:59 +00:00
|
|
|
render(): ?React.Element<any> {
|
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');
|
|
|
|
const filter = (example) => filterRegex.test(example.module.title);
|
|
|
|
|
|
|
|
const dataSource = ds.cloneWithRowsAndSections({
|
|
|
|
components: this.props.list.ComponentExamples.filter(filter),
|
|
|
|
apis: this.props.list.APIExamples.filter(filter),
|
|
|
|
});
|
|
|
|
return (
|
|
|
|
<View style={[styles.listContainer, this.props.style]}>
|
|
|
|
{this._renderTitleRow()}
|
|
|
|
{this._renderTextInput()}
|
|
|
|
<ListView
|
|
|
|
style={styles.list}
|
|
|
|
dataSource={dataSource}
|
|
|
|
renderRow={this._renderExampleRow.bind(this)}
|
|
|
|
renderSectionHeader={this._renderSectionHeader}
|
2016-06-14 05:15:47 +00:00
|
|
|
enableEmptySections={true}
|
2016-02-23 00:15:35 +00:00
|
|
|
keyboardShouldPersistTaps={true}
|
|
|
|
automaticallyAdjustContentInsets={false}
|
|
|
|
keyboardDismissMode="on-drag"
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
return this._renderRow(
|
|
|
|
'UIExplorer',
|
|
|
|
'React Native Examples',
|
|
|
|
'home_key',
|
|
|
|
() => {
|
|
|
|
this.props.onNavigate(
|
|
|
|
UIExplorerActions.ExampleListWithFilter('')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-10-16 11:11:59 +00:00
|
|
|
_renderSectionHeader(data: any, section: string): ?React.Element<any> {
|
2016-02-23 00:15:35 +00:00
|
|
|
return (
|
|
|
|
<Text style={styles.sectionHeader}>
|
|
|
|
{section.toUpperCase()}
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-10-16 11:11:59 +00:00
|
|
|
_renderExampleRow(example: {key: string, module: Object}): ?React.Element<any> {
|
2016-02-23 00:15:35 +00:00
|
|
|
return this._renderRow(
|
|
|
|
example.module.title,
|
|
|
|
example.module.description,
|
|
|
|
example.key,
|
|
|
|
() => this._handleRowPress(example.key)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-10-16 11:11:59 +00:00
|
|
|
_renderRow(title: string, description: string, key: ?string, handler: ?Function): ?React.Element<any> {
|
2016-02-23 00:15:35 +00:00
|
|
|
return (
|
|
|
|
<View key={key || title}>
|
|
|
|
<TouchableHighlight onPress={handler}>
|
|
|
|
<View style={styles.row}>
|
|
|
|
<Text style={styles.rowTitleText}>
|
|
|
|
{title}
|
|
|
|
</Text>
|
|
|
|
<Text style={styles.rowDetailText}>
|
|
|
|
{description}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
|
|
|
<View style={styles.separator} />
|
|
|
|
</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: {
|
|
|
|
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;
|