import React, { Component } from 'react'; import { View, Text, Image, StyleSheet, FlatList, ScrollView, Dimensions, TouchableOpacity } from 'react-native'; import SegmentedBar from './SegmentedBar' import Carousel from './Carousel' import DashSecondLine from './DashSecondLine' import Header from './Header' import CodeDetail from './CodeDetail' var { height, width } = Dimensions.get('window'); export default class Home extends Component { // static navigationOptions = ({navigation,screenProps})=>({ // tabBarLabel: '首页', // tabBarIcon: ({ focused, tintColor }) => , // }); constructor(props) { super(props); // var barItems = [ // { // title:'浏览记录', // type: 0, // content:[ // { // timeText:'今天', // title:'3号免手洗', // time:'查看于1小时前', // }, // { // timeText:'今天', // title:'3号免手洗', // time:'查看于1小时前', // }, // { // timeText:'今天', // title:'3号免手洗', // time:'查看于1小时前', // }, // { // timeText:'今天', // title:'3号免手洗', // time:'查看于1小时前', // }, // { // timeText:'今天', // title:'3号免手洗', // time:'查看于1小时前', // }, // { // timeText:'昨天', // title:'3号免手洗', // time:'查看于1小时前', // }, // { // timeText:'昨天', // title:'3号免手洗', // time:'查看于1小时前', // }, // { // timeText:'昨天', // title:'3号免手洗', // time:'查看于1小时前', // } // ] // },{ // title:'收藏列表', // type: 1, // content:[ // { // title:'3号免手洗', // time:'收藏于1小时前', // } // ] // } // ]; var history = { title: '浏览记录', type: 0, content: [ { timeText: '今天', title: '3号免手洗', time: '查看于1小时前', }, { timeText: '今天', title: '3号免手洗', time: '查看于1小时前', }, { timeText: '今天', title: '3号免手洗', time: '查看于1小时前', }, { timeText: '今天', title: '3号免手洗', time: '查看于1小时前', }, { timeText: '今天', title: '3号免手洗', time: '查看于1小时前', }, { timeText: '昨天', title: '3号免手洗', time: '查看于1小时前', }, { timeText: '昨天', title: '3号免手洗', time: '查看于1小时前', }, { timeText: '昨天', title: '3号免手洗', time: '查看于1小时前', } ] } var collect = { title: '收藏列表', type: 1, content: [ { title: '3号免手洗', time: '收藏于1小时前', } ] } this.justifyItemItems = ['fixed', 'scrollable']; this.indicatorTypeItems = ['none', 'boxWidth', 'itemWidth', 'customWidth']; this.indicatorPositionItems = ['top', 'bottom']; if (!this.state) { this.state = {} } Object.assign(this.state, { justifyItem: 'fixed', indicatorType: 'itemWidth', indicatorPosition: 'bottom', animated: true, autoScroll: true, activeIndex: 0, custom: false, history: history, collect: collect }); } onSegmentedBarChange(index) { if (index != this.state.activeIndex) { this.setState({ activeIndex: index }); if (this.refs.carousel) { this.refs.carousel.scrollToPage(index, false); } } } onCarouselChange(index) { index != this.state.activeIndex && this.setState({ activeIndex: index }); } getContent(item, _this) { if (item.type == 0) { return ( {item.content.length == 0 ? 这里空空如也,快去扫描看看 : item.content.map((itemChild, index) => ( {itemChild.timeText} {itemChild.title} {itemChild.time} { this.refs.dialog._setModalVisible(true); }}> { item.content.splice(index, 1); _this.setState({ history: item }) }}> { _this.props.navigation.navigate('Details') }}>查看详情 ))} ) } else { return ( {item.content.length == 0 ? 这里空空如也,快去收藏看看 : item.content.map((itemChild, index) => ( {itemChild.title} {itemChild.time} { this.refs.dialog._setModalVisible(true); }}> { item.content.splice(index, 1); _this.setState({ collect: item }) }}> 取消收藏 { _this.props.navigation.navigate('Details') }}>查看详情 ))} ) } } render() { let { justifyItem, indicatorType, indicatorPosition, animated, autoScroll, custom, activeIndex } = this.state; var barItems = []; barItems.push(this.state.history); barItems.push(this.state.collect); console.log(barItems) return (
this.onSegmentedBarChange(index)} > {barItems.map((item, index) => { return () })} this.onCarouselChange(index)} > {barItems.map((item, index) => ( {this.getContent(item, this)} ))}
) } } const styles = StyleSheet.create({ tabImg: { width: 30, height: 30, }, noResult: { width: 100, height: 100, }, headImg: { width: 40, height: 50, }, listContainer: { flexDirection: 'row', alignItems: 'center', height: 60, paddingLeft: 20, paddingRight: 20, borderBottomWidth: 1, borderBottomColor: "#ddd" }, textContainer: { flexDirection: 'column', alignItems: 'flex-start', height: 60, marginLeft: 20, }, item: { marginLeft: 20, marginRight: 20, }, carousel_style: { backgroundColor: '#fff', height: height - 80, borderTopWidth: 1, borderTopColor: '#f8f8f8' } })