/** * 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'; var React = require('react-native'); var { ListView, PixelRatio, StyleSheet, Text, TextInput, TouchableHighlight, View, } = React; var createExamplePage = require('./createExamplePage'); var ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2, sectionHeaderHasChanged: (h1, h2) => h1 !== h2, }); class UIExplorerListBase extends React.Component { constructor(props: any) { super(props); this.state = { dataSource: ds.cloneWithRowsAndSections({ components: [], apis: [], }), searchText: this.props.searchText || '', }; } componentDidMount(): void { this.search(this.state.searchText); } render() { var topView = this.props.renderAdditionalView && this.props.renderAdditionalView(this.renderRow.bind(this), this.renderTextInput.bind(this)); return ( {topView} ); } renderTextInput(searchTextInputStyle: any) { return ( ); } _renderSectionHeader(data: any, section: string) { return ( {section.toUpperCase()} ); } renderRow(example: any, i: number) { return ( this.onPressRow(example)}> {example.title} {example.description} ); } search(text: mixed): void { this.props.search && this.props.search(text); var regex = new RegExp(String(text), 'i'); var filter = (component) => regex.test(component.title); this.setState({ dataSource: ds.cloneWithRowsAndSections({ components: this.props.components.filter(filter), apis: this.props.apis.filter(filter), }), searchText: text, }); } onPressRow(example: any): void { this.props.onPressRow && this.props.onPressRow(example); } static makeRenderable(example: any): ReactClass { return example.examples ? createExamplePage(null, example) : example; } } var styles = StyleSheet.create({ listContainer: { flex: 1, }, list: { backgroundColor: '#eeeeee', }, sectionHeader: { padding: 5, }, group: { backgroundColor: 'white', }, sectionHeaderTitle: { fontWeight: '500', fontSize: 11, }, row: { backgroundColor: 'white', justifyContent: 'center', paddingHorizontal: 15, paddingVertical: 8, }, separator: { height: 1 / PixelRatio.get(), backgroundColor: '#bbbbbb', marginLeft: 15, }, rowTitleText: { fontSize: 17, fontWeight: '500', }, rowDetailText: { fontSize: 15, color: '#888888', lineHeight: 20, }, searchRow: { backgroundColor: '#eeeeee', paddingTop: 75, paddingLeft: 10, paddingRight: 10, paddingBottom: 10, }, searchTextInput: { backgroundColor: 'white', borderColor: '#cccccc', borderRadius: 3, borderWidth: 1, paddingLeft: 8, }, }); module.exports = UIExplorerListBase;