123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- const React = require('react');
- const { Component } = require('react');
-
- const {
- StyleSheet,
- FlatList,
- View,
- Button,
- Text,
- TouchableOpacity,
- Platform
- } = require('react-native');
-
- const { Navigation } = require('react-native-navigation');
- const testIDs = require('../testIDs');
-
- const ITEMS = [...Array(200).keys()].map(key => ({ key: `Item ${key}` }));
-
- class SearchControllerScreen extends Component {
- static get options() {
- return {
- topBar: {
- title: {
- text: 'Search'
- },
- largeTitle: {
- visible: true
- },
- searchBar: true,
- background: {
- translucent: true
- },
- searchBarPlaceholder: 'Start Typing'
- }
- };
- }
-
- constructor(props) {
- super(props);
- this.state = {
- query: ''
- };
- Navigation.events().bindComponent(this);
- }
-
- filteredData() {
- return ITEMS.filter(
- item =>
- this.state.query.length === 0 || item.key.indexOf(this.state.query) > -1
- );
- }
-
- highlight(text, query) {
- if (query.length > 0 && text.indexOf(query) > -1) {
- const before = text.split(query)[0];
- const after = text.split(query)[1];
- return (
- <Text>
- <Text>{before}</Text>
- <Text style={{ backgroundColor: 'yellow' }}>{query}</Text>
- <Text>{after}</Text>
- </Text>
- );
- }
- return text;
- }
-
- onItemPressed = () => {
- Navigation.push(this.props.componentId, {
- component: {
- name: 'navigation.playground.PushedScreen',
- options: {
- topBar: {
- title: {
- text: 'PushedScreen'
- },
- largeTitle: {
- visible: true
- },
- background: {
- translucent: true
- }
- }
- }
- },
- });
- }
-
- render() {
- return (
- <FlatList
- testID={testIDs.SCROLLVIEW_ELEMENT}
- data={this.filteredData()}
- contentContainerStyle={styles.contentContainer}
- renderItem={({ item }) => (
- <TouchableOpacity style={styles.row} onPress={this.onItemPressed}>
- <Text style={styles.rowText} testID={testIDs.SEARCH_RESULT_ITEM}>
- {this.highlight(item.key, this.state.query)}
- </Text>
- </TouchableOpacity>
- )}
- />
- );
- }
-
- searchBarUpdated({text, isFocused}) {
- this.setState({ query: text, isFocused });
- }
- }
-
- module.exports = SearchControllerScreen;
-
- const styles = StyleSheet.create({
- contentContainer: {},
- row: {
- height: 50,
- padding: 20,
- justifyContent: 'center'
- },
- rowText: {
- fontSize: 18
- }
- });
|