TopicBoard.js 5.25 KB
import React, {Component} from "react";
import {
    ActivityIndicator,
    DeviceEventEmitter,
    Image,
    ImageBackground,
    StyleSheet,
    Text,
    TouchableOpacity,
    View
} from "react-native";

import {zoomH, zoomW} from '../../utils/getSize';
import TopicInfoUtil from '../component/topicInfo';
import HomeList from "../../pages/home/HomeList";
import {NoDoublePress} from "../../utils/utils";

var InfoBg = ImageBackground;
var deEmitter = DeviceEventEmitter;

//图片资源
const backArrow = require('../../img/backWhite.png');

// 变量定义
{
    let parm_topicId = 0
}

export default class TopicBoard extends Component {

    static navigationOptions = ({ navigation, screenProps }) => ({
        header:null,
    });

    constructor(props){
        super(props);
        parm_topicId = this.props.navigation.state.params.id;
        TopicInfoUtil.parm_topicId = parm_topicId;
        this.state = {
            // 信息区域的背景图
            imgUrl:'',
            infoLoading:true,
            listLoading:true
        };
    };

    componentWillMount(){
    };

    componentDidMount(){
        //设置头部
        this.props.navigation.setParams({
            back:()=>{
                this.props.navigation.goBack();
            },
        });
        let _this = this;
        this.deEmitter = DeviceEventEmitter.addListener('getTopicInfo', (url) => {
            console.log('getTopicInfo' + url);
            _this.setState({
                imgUrl:url,
                infoLoading:false
            })
        });
        this.deEmitter = DeviceEventEmitter.addListener('getTopicList', () => {
            console.log('收到通知getTopicList:');
            _this.setState({
                listLoading:false
            })
        });
    }

    componentWillUnmount(){
        this.deEmitter.remove();
    }

    onBackPress(){
        this.props.navigation.goBack();
    }

    render() {
        return(
            <View style = {styles.background}>
                {/*话题信息区域背景图*/}
                <InfoBg style = {styles.infoBg} source = {{uri:this.state.imgUrl}}>
                    <View style = {{position:'absolute',width:'100%',height:'100%',backgroundColor:'rgba(0,0,0,0.25)'}}></View>
                    {/*假的导航区域*/}
                    <View style = {styles.navi}>
                        {/*导航返回按钮*/}
                        <TouchableOpacity style={styles.backStyle}  onPress={() => {
                          NoDoublePress.onPress(()=>{
                            this.onBackPress();
                          });
                        }}>
                            <Image  style={{width:9/zoomW,height:16/zoomH}} source={backArrow} resizeMode="cover" />
                        </TouchableOpacity>
                    </View>
                    {/*话题信息*/}
                    <View style = {styles.info}>
                        {/*话题信息自定义UI*/}
                        <TopicInfoUtil id={parm_topicId}/>
                    </View>
                </InfoBg>
                {/*/!*使用话题的帖子列表*!/*/}
                <HomeList arr_keyValue = {[{'topicId':parm_topicId}]} navigation={this.props.navigation}/>
                {(this.state.infoLoading || this.state.listLoading) && (
                    <View style={styles.loadingBg}>
                        <View style={styles.loadingBox}>
                            <ActivityIndicator size="large" color="#fff" />
                            <Text
                                style={{ fontSize: 16, color: "#fff", marginTop: 6 / zoomH }}
                            >
                                加载中...
                            </Text>
                        </View>
                    </View>
                )}
            </View>
      );
    }
}

const styles = StyleSheet.create({
    background:{
      flex: 1,
      backgroundColor: 'white',
      display: 'flex',
  },
  loadingBg: {
      position: "absolute",
      top: 0,
      width: "100%",
      height: "100%",
      display: "flex",
      justifyContent: "center",
      alignItems: "center"
  },
  loadingBox: {
      width: 100 / zoomW,
      height: 120 / zoomH,
      backgroundColor: "rgba(0,0,0,.5)",
      borderRadius: 8,
      display: "flex",
      alignItems: "center",
      justifyContent: "center"
  },

    navi:{
        display: 'flex',
        alignItems: 'flex-start',
        justifyContent:'flex-start',
        flexDirection:'row',
        width:'100%',
        height:89/zoomH
    },

    backStyle:{
        display: 'flex',
        alignItems: 'flex-start',
        justifyContent:'flex-start',
        flexDirection:'row',
        width:9/zoomW,
        height:16/zoomH,
        marginTop:34/zoomH,
        marginLeft:15/zoomW
    },

    infoBg:{
        height:195/zoomH,
        width:'100%',
        backgroundColor:'#000',
        display: 'flex',
        flexDirection:'column',
        justifyContent:'flex-start',
        alignItems:'flex-start'
    },

    info:{
        backgroundColor:'rgba(0,0,0,0)',
        display: 'flex',
        flexDirection:'row',
        justifyContent:'flex-start',
        alignItems:'flex-start',
        position:'absolute',
        left:15/zoomW,
        right:23/zoomW,
        bottom:20/zoomH
    },
});