home.js 6.07 KB
/**
 * Created by Cassie on 2018/05/14
 */
import React, { Component } from 'react';
import {
    StyleSheet,
    View,
    Image,
    ScrollView,
    Text,
    TextInput,
    TouchableOpacity,
    InteractionManager,
    DeviceEventEmitter,
    ActivityIndicator,
    FlatList,
    NativeModules,
    WebView
} from 'react-native';
import {StackNavigator} from 'react-navigation';
import moment from 'moment';
import {width,height,zoomW,zoomH} from '../utils/getSize';
import {xnToast} from '../utils/utils';
import AppService from '../service/AppService'
import config from "../config"

let myjs = ('$(\'#qrcode\').css("left", ($(window).width() - $(\'#qrcode\').width())/ 2);$(\'#qrcode\').css("top", ($(window).height() - $(\'#qrcode\').height())/ 2);$(\'#qrcode\').show();qrcode.makeCode(\'%1\');');
const back = require('../img/returnB.png');

export default class Home extends Component {
    static navigationOptions = ({ navigation, screenProps }) => ({
        title: "我的通行码",
        headerLeft:(<View style={{display:'flex',flexDirection:'row'}}>
            <TouchableOpacity style={styles.topIcon}  onPress = {navigation.state.params?navigation.state.params.close:null}>
                <Image source={back} style={{width:(16/zoomH),height:(16/zoomH)}} resizeMode="contain" />
            </TouchableOpacity>
        </View>),
        headerRight:(
            <View style={{display:'flex',flexDirection:'row',paddingRight:(5/zoomW)}}>
                <TouchableOpacity style={styles.topIcon} onPress = {navigation.state.params?navigation.state.params.addNotice:null} >
                    {/*<Image source={addTarget} style={{width:(26/zoomH),height:(26/zoomH)}} resizeMode="contain" />*/}
                </TouchableOpacity>
            </View>)
    });

    constructor(props) {
        super(props);
        this.state = {
            AnnounceList:[],
            ownCount:0,
            loading:true,
            loadMore:false,
            key:'',
            type:'',
            imageAvatar:{},
            random:0,
        };
        myjs = myjs.replace("%1", global.code);
    }

    componentWillMount()
    {


    }
    componentDidMount(){
        this.props.navigation.setParams({
            close:()=>{
                InteractionManager.runAfterInteractions(() => {NativeModules.system.navTo("BACK");})
            },
            addNotice:() => {
                InteractionManager.runAfterInteractions(() => {this.props.navigation.navigate('AddNotice');})
            },
        });


        let _this = this;


        if (global.initParam && global.initParam != null)
        {

        }


    };

    componentWillUnmount(){
        this.setState = (state,callback)=>{
            return;
        };

    }

    back(){
        // this.props.navigation.goBack();
    };

    getRandomNum(){
        var Range = 10000;
        var Rand = Math.random();
        this.setState({
            random:Math.round(Rand * Range),
        })
    }

    render(){
        return(
            <View style={styles.background}>
                <View style={{flex:1,width:'100%', height:'100%',backgroundColor:'#ffffff'}}>
                    <WebView
                        ref={el => this.webView = el}
                        style={{height:'100%', width:'100%'}}  urlPrefixesForDefaultIntent={['https://', 'http://']}
                              source={require('../html/qrcode.html')}

                        onLoadEnd={e => {
                            this.webView.injectJavaScript(myjs)
                        }}
                    />
                </View>
            </View>
        );
    }
    webviewLoadEnd()
    {

    }


}

const styles = StyleSheet.create({
   topIcon:{
     paddingLeft:(10/zoomW),
                paddingRight:(10/zoomW),
                height:'100%',
                display:'flex',
                alignItems:'center'
    },

    background:{
        flex:1,
        backgroundColor:'#ececf1',
        display:'flex',
        alignItems:'center'
    },
    itemBackground:{
        flex:1,
        backgroundColor:'#ffffff',
        display:'flex',
        alignItems:'center'
    },

    targetItem:{
        flex:1,
        display:'flex',
        flexDirection:'row',
        alignItems:'center',
        borderStyle:'solid',
        borderBottomColor:'#eee',
        paddingLeft:(15/zoomW),
        paddingRight:(15/zoomW),
        paddingTop:(10/zoomH),
        paddingBottom:(10/zoomH),
        backgroundColor:'#fff'
    },
    searchBox:{
        width:(345/zoomW),
        height:(34/zoomH),
        backgroundColor:'#eeeff3',
        borderRadius:3,
        display:'flex',
        flexDirection:'row',
        alignItems:'center',
        paddingLeft:(12.5/zoomW),
        paddingRight:(12.5/zoomW),
        marginBottom:(12.5/zoomW)
    },
    searchText:{
        flex:1,
        fontSize:14,
        color:'#000',
        padding:0,
        paddingLeft:(8/zoomW)
    },
    myPublish:{
        backgroundColor:'#ffffff',
        paddingLeft:(15/zoomW),
        paddingRight:(15/zoomW),
        paddingTop:(6.5/zoomW),
        paddingBottom:(19/zoomW),
        justifyContent:'space-between',
        display:'flex',
        flexDirection: 'row'
    },

    listItem:{
       flex:1,
       display:'flex',
       borderStyle:'solid',
       backgroundColor:'#ffffff',
       borderBottomColor:'#eee',
       borderBottomWidth:StyleSheet.hairlineWidth,
       paddingTop:(10/zoomH),
       paddingLeft:(15/zoomW),
       paddingRight:(15/zoomW),
       paddingBottom:(10/zoomH)
    },
    loadingBg:{
        width:'100%',
        height:'100%',
        position:'absolute',
        display:'flex',
        alignItems:'center',
        justifyContent:'center'
    },
    loadingBox:{
        width:(100/zoomW),
        height:(120/zoomH),
        backgroundColor:'rgba(0,0,0,.5)',
        borderRadius:8,
        display:'flex',
        alignItems:'center',
        justifyContent:'center'
    },
    inputBox:{
        width:(310/zoomW),
        height:(28/zoomH),
        backgroundColor:'#eeeff3',
        borderRadius:3,
        padding:0,
        paddingLeft:(5/zoomW),
        paddingRight:(5/zoomW)
    },
})