about.js 5.36 KB

import React, { Component } from 'react';
import {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    Image,
    Dimensions,
    Platform,
    TouchableOpacity,
    ActivityIndicator,
    Alert,
    StatusBar
} from 'react-native';

import xnService from './util/service'
import {getConfig} from "./index";

function isIPhoneX () {
    let dimen = Dimensions.get('window');
    return (
        Platform.OS === 'ios' &&
        !Platform.isPad &&
        !Platform.isTVOS &&
        (dimen.height >= 812 || dimen.width >= 812)
    );
}

export default class About extends Component {
    static navigationOptions = ({navigation, screenProps}) => ({
        header:null
    });
    constructor(props) {
        super(props);
        let config = getConfig();
        this.state = {
            loading: true,
            iconUrl:config.imgUrl,
            name:'',
            description:'',
            iconId:''
        };

    }

    componentDidMount(){
        this.props.navigation.setParams({
            backgroundColor:this.props.navigation.state.params.stateColor
        });
        let _this = this;
        xnService.getDetail({code:this.props.navigation.state.params.code}).then((data)=>{
            _this.setState({
                loading: false
            });
            if (data.message) {
                Alert.alert(
                    '提示',
                    data.message,
                    [
                        {text:"确定", onPress:() => {_this.props.navigation.goBack()}}
                    ]

                )
                return;
            }
            if (data.errors.length > 0) {
                Alert.alert(
                    '提示',
                    data.errors[0].message,
                    [
                        {text:"确定", onPress:() => {_this.props.navigation.goBack()}}
                    ]

                );
                return;
            } else {
                console.log(data);

                let url = '';
                if (data.application.iconUrl != '') {

                    if (data.application.iconUrl.indexOf('.png') != -1 || data.application.iconUrl.indexOf('.jpg') != -1 || data.application.iconUrl.indexOf('.jpeg') != -1) {
                        url = data.application.iconUrl;
                    }else{
                        url = this.state.iconUrl+String(data.application.id)+'.png';
                    }

                }else{
                    url = this.state.iconUrl+String(data.application.id)+'.png';
                }

                _this.setState({
                    name:data.application.name,
                    description:data.application.description?data.application.description:'',
                    iconId:data.application.id,
                    iconUrl:url

                })
            }
        }).catch((error)=>{
            this.setState({
                loading: false
            });
            Alert.alert(
                '提示',
                "未获取到关于信息",
                [
                    {text:"确定", onPress:() => {_this.props.navigation.goBack()}}
                ]

            );
            return;
        })
    }

    componentWillUnmount(){
        this.setState({
            loading:false
        });
    }

    render() {
        return (
            <View style={styles.container}>
                <StatusBar
                    backgroundColor={'#fff'}
                    networkActivityIndicatorVisible
                    barStyle={"dark-content"}
                />
                <View style={{height:isIPhoneX()?44:20}}></View>
                <View style={{width:30,height:30,marginLeft:15}}>
                    <TouchableOpacity style={{flex:1,justifyContent:'center',alignItems:'center'}} onPress={()=>{this.props.navigation.goBack()}}>
                        <Image style={{width:9,height:16}} source={require('./img/backB.png')}/>
                    </TouchableOpacity>
                </View>
                {!this.state.loading && <View style={{flex:1,alignItems:'center',paddingTop:40,paddingLeft:15,paddingRight:15}}>
                    <Image source={{uri:this.state.iconUrl}}  resizeMode='contain' style={{backgroundColor:'#ececf1',width:80,height:80}}/>
                    <Text style={{textAlign:'center',fontSize:20,marginTop:20,fontWeight:'500'}}>{this.state.name}</Text>
                    <Text style={{textAlign:'center',fontSize:14,marginTop:20,color:'#888',letterSpacing:2}}>{this.state.description}</Text>
                </View>}
                {this.state.loading && <View style={styles.loadingBg}>
                    <View style={styles.loadingBox}>
                        <ActivityIndicator size='large' color='#fff' />
                        <Text style={{fontSize:16,color:'#fff',marginTop:(6)}}>加载中...</Text>
                    </View>
                </View>}

            </View>
        );
    }
}

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

});