/** * Copyright (c) 2015-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. * * @flow */ 'use strict'; var React = require('react-native'); var { AppRegistry, ListView, PixelRatio, StyleSheet, Text, TextInput, TouchableHighlight, View, } = React; var NavigatorExample = require('./Navigator/NavigatorExample'); var { TestModule } = React.addons; var createExamplePage = require('./createExamplePage'); var COMPONENTS = [ require('./ActivityIndicatorExample'), require('./DatePickerExample'), require('./ImageExample'), require('./ListViewPagingExample'), require('./ListViewSimpleExample'), require('./MapViewExample'), require('./NavigatorIOSExample'), NavigatorExample, require('./PickerExample'), require('./ScrollViewExample'), require('./SliderIOSExample'), require('./SwitchExample'), require('./TabBarExample'), require('./TextExample.ios'), require('./TextInputExample'), require('./TouchableExample'), require('./ViewExample'), require('./WebViewExample'), ]; var APIS = [ require('./ActionSheetIOSExample'), require('./AdSupportIOSExample'), require('./AlertIOSExample'), require('./AppStateIOSExample'), require('./AsyncStorageExample'), require('./BorderExample'), require('./CameraRollExample.ios'), require('./GeolocationExample'), require('./LayoutExample'), require('./NetInfoExample'), require('./PointerEventsExample'), require('./PushNotificationIOSExample'), require('./StatusBarIOSExample'), require('./ResponderExample'), require('./TimerExample'), require('./VibrationIOSExample'), ]; var ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2, sectionHeaderHasChanged: (h1, h2) => h1 !== h2, }); function makeRenderable(example: any): ReactClass { return example.examples ? createExamplePage(null, example) : example; } // Register suitable examples for snapshot tests COMPONENTS.concat(APIS).forEach((Example) => { if (Example.displayName) { var Snapshotter = React.createClass({ componentDidMount: function() { // View is still blank after first RAF :\ global.requestAnimationFrame(() => global.requestAnimationFrame(() => TestModule.verifySnapshot( TestModule.markTestCompleted ) )); }, render: function() { var Renderable = makeRenderable(Example); return ; }, }); AppRegistry.registerComponent(Example.displayName, () => Snapshotter); } }); class UIExplorerList extends React.Component { constructor(props) { super(props); this.state = { dataSource: ds.cloneWithRowsAndSections({ components: COMPONENTS, apis: APIS, }), }; } render() { return ( ); } _renderSectionHeader(data, section) { return ( {section.toUpperCase()} ); } _renderRow(example, i) { return ( this._onPressRow(example)}> {example.title} {example.description} ); } _search(text) { var regex = new RegExp(text, 'i'); var filter = (component) => regex.test(component.title); this.setState({ dataSource: ds.cloneWithRowsAndSections({ components: COMPONENTS.filter(filter), apis: APIS.filter(filter), }) }); } _onPressRow(example) { if (example === NavigatorExample) { this.props.onExternalExampleRequested( NavigatorExample ); return; } var Component = makeRenderable(example); this.props.navigator.push({ title: Component.title, component: Component, }); } } 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, height: 30, paddingLeft: 8, }, }); module.exports = UIExplorerList;