import React, {Component} from 'react'; import SearchTitleBar from '../views/SearchTitleBar'; import CommonLoadingView from '../views/CommonLoadingView'; import Global from '../utils/Global'; import {Dimensions, FlatList, Image, PixelRatio, StyleSheet, Text, TouchableOpacity, View} from 'react-native'; const {width} = Dimensions.get('window'); const stateNormal = -1; const stateNoData = -2; export default class SearchScreen extends Component { constructor(props) { super(props); this.state = { loadingState: stateNormal, searchResult: null, listItemIndex: 0 }; } render() { switch (this.state.loadingState) { case stateNormal: return this.renderDefaultView(); case Global.loading: return this.renderLoadingView(); case Global.loadSuccess: if (this.state.searchResult == null || this.state.searchResult.length == 0) { return this.renderEmptyView(); } return this.renderSearchResultView(); } } renderDefaultView() { return ( 搜索指定内容 朋友圈 文章 公众号 小说 音乐 表情 ); } renderSearchResultView() { return ( ); } renderItem = (item) => { var title = item.item.name; var icon = item.item.avatar; var param = { title: title, icon: {uri: icon}, }; return ( { this.props.navigation.navigate('ContactDetail', {title: "详细资料", data: param}) }} style={{flexDirection: 'column', flex: 1}}> {item.item.name} ); } renderEmptyView() { return ( 没有搜索到结果 ); } renderLoadingView() { return ( ); } renderErrorView() { return ( Error! ); } startSearch = (key) => { const URL = "http://app.yubo725.top/search"; var data = {key: key}; let params = new FormData(); params.append("key", key); fetch(URL, { method: 'POST', body: params }).then((res) => res.json()) .then(json => { for (var i = 0; i < json.length; i++) { var item = json[i]; item.key = item.id; } this.setState({ loadingState: Global.loadSuccess, searchResult: json }) }) } handleSearchClick = (str) => { this.setState({loadingState: Global.loading}); this.startSearch(str); } } const listItemStyle = StyleSheet.create({ container: { flex: 1, width: width, flexDirection: 'row', alignItems: 'center', padding: 10, }, listItemAvatar: { width: 45, height: 45, }, listItemText: { color: '#000000', fontSize: 15, marginLeft: 15 }, divider: { width: width, height: 1 / PixelRatio.get(), backgroundColor: Global.dividerColor } }) const styles = StyleSheet.create({ container: { flex: 1, flexDirection: 'column', }, content: { flex: 1, flexDirection: 'column', alignItems: 'center', backgroundColor: '#FFFFFF', }, searchHintText: { marginTop: 50, marginBottom: 50, fontSize: 16, color: '#999999' }, row: { justifyContent: 'center', flexDirection: 'row', paddingTop: 15, paddingBottom: 15, paddingLeft: 20, paddingRight: 20, }, rowItem: { flex: 1, flexDirection: 'row', justifyContent: 'center', }, rowItemText: { color: '#49BC1C', }, rowItemDivider: { width: 1 / PixelRatio.get(), height: 20, backgroundColor: '#000000' } })