import React, {Component} from 'react'; import { StyleSheet, Text, View, TouchableOpacity, ImageBackground, Animated, Modal, TouchableWithoutFeedback, InteractionManager } from 'react-native'; import {Navigation} from 'react-native-navigation'; import {Button} from 'react-native-elements'; import ActionSheet from 'react-native-actionsheet-api'; import Color from '../style/color' import Api from '../util/api'; import Update from '../util/update'; import DiaryList from '../component/diary/diaryList' import HomeDiaryData from '../dataLoader/homeDiaryData'; export default class HomePage extends Component { constructor(props) { super(props); this.dataSource = new HomeDiaryData(); let splash = props.splash; this.state = { hasSplash: splash ? true : false, showSplash: true, fadeInOpacity: new Animated.Value(0), splashTime : 3, splashImage: splash ? splash.image_url : null, splashLink: splash ? splash.link : null, topic: null } } componentDidMount() { if(this.state.hasSplash) { this.openSplash(); } else { this.closeSplash(); } this.bottomTabEventListener = Navigation.events().registerBottomTabSelectedListener( ({ selectedTabIndex, unselectedTabIndex }) => { if(selectedTabIndex == unselectedTabIndex && selectedTabIndex == 0) { this.diaryList.scrollToTop(); } } ); if(Api.IS_ANDROID) { setTimeout(() => { Update.updateAndroid(); }, 2000); } } componentWillUnmount() { this.bottomTabEventListener.remove(); } startTimer() { this.timer = setInterval(() => { let newTime = this.state.splashTime - 1; this.setState({ splashTime: newTime }); if(newTime == 0) { this.closeSplash(); } }, 1000); } openSplash() { Animated.timing( this.state.fadeInOpacity, { toValue: 1, duration: 1000, } ).start(() => { this.startTimer(); }); } closeSplash() { if(this.timer) { clearTimeout(this.timer); } Animated.timing( this.state.fadeInOpacity, { toValue: 0, duration: 500, } ).start(() => { Navigation.mergeOptions(this.props.componentId, { topBar: { visible: true, title: { text: '首页' } }, bottomTabs: { visible: true, drawBehind: false, animate: false } }); this.setState({ showSplash: false }) }); } onSplashPress() { if(this.state.splashLink) { if(this.timer) { clearTimeout(this.timer); } Navigation.mergeOptions(this.props.componentId, { topBar: { visible: true, title: { text: '首页' } }, bottomTabs: { visible: true } }); Navigation.push(this.props.componentId, { component: { name: 'WebView', options: { bottomTabs: { visible: false, // hide bottom tab for android drawBehind: true, animate: true } }, passProps: this.state.splashLink.passProps } }).then(() => { this.setState({ showSplash: false, fadeInOpacity: new Animated.Value(0) }); }); } } refreshTopic() { Api.getTodayTopic() .then(topic => { if(topic) { this.setState({topic}); } }) .done(); } openTopicPage() { Navigation.push(this.props.componentId, { component: { name: 'Topic', options: { bottomTabs: { visible: false, // hide bottom tab for android drawBehind: true, animate: true } }, passProps: { topic: this.state.topic, title: '话题:' + this.state.topic.title } } }); } render() { return ( { this.state.showSplash ? this.renderModal() : ( this.diaryList = r} dataSource={this.dataSource} listHeader={this.renderHeader.bind(this)} refreshHeader={this.refreshTopic.bind(this)} {...this.props} > ) } ); } renderHeader() { return this.state.topic ? ( # {this.state.topic.title} {this.state.topic.intro} ) : null; } renderModal() { return ( {}} onRequestClose={() => {}} >