post.js 5.62 KB
/**
 * Created by Cassie on 2018/03/06
 */
import React, { Component } from 'react';
import {
    StyleSheet,
    View,
    Text,
    TouchableOpacity,
    Image,
    TextInput,
    StatusBar
} from 'react-native';

import {zoomW,zoomH} from '../../utils/getSize';
import {xnBorderWidth} from "../../utils/utils";
const back = require('../../img/back.png');
const close = require('../../img/close.png');
const cross = require('../../img/cross.png');
const plate = require('../../img/plate.png');
const arrow = require('../../img/arrow.png');

export default class Post extends Component {
    static navigationOptions = ({ navigation, screenProps })=>({
        title: '发帖',
        headerLeft:(<View style={{display:'flex',flexDirection:'row'}}>
            <TouchableOpacity style={styles.leftIcon} onPress={navigation.state.params?navigation.state.params.back:null}>
                <Image source={back} style={styles.backIcon} resizeMode="contain" />
            </TouchableOpacity>
            <TouchableOpacity style={styles.leftIcon} onPress={navigation.state.params?navigation.state.params.close:null}>
                <Image source={close} style={styles.closeIcon} resizeMode="contain" />
            </TouchableOpacity>
        </View>),
        headerRight:(<View style={styles.rightTop}>
            <TouchableOpacity style={styles.rightIcon}>
                <Text style={{fontSize:16,color:'#fff'}}>提交</Text>
            </TouchableOpacity>
        </View>)
    });

    constructor(props) {
        super(props);
        this.state = {};
    };

    componentDidMount(){
        //设置头部
        this.props.navigation.setParams({
            back:()=>{
                this.props.navigation.goBack();
            },
            close:()=>{
                NativeModules.system.navTo("BACK");
            }
        });
    };

    render() {
        return (
            <View style={styles.background}>
                <StatusBar barStyle="light-content" />
                <View style={styles.postTitle}>
                    <TextInput autoFocus={true} style={styles.titleText} placeholder='标题(必填),4-40字'  />
                </View>
                <View style={styles.content}>
                    <TextInput multiline={true} style={styles.contentText} placeholder='正文,来吧,尽情发挥吧...'  />
                    <View style={styles.addImg}>
                        <TouchableOpacity activeOpacity={0.6} style={styles.contentImg}>
                            <Image style={{width:(20/zoomW),height:(20/zoomW)}} source={cross} resizeMode="contain" />
                        </TouchableOpacity>
                    </View>
                    <TouchableOpacity activeOpacity={0.6} style={styles.selectItem}>
                        <Image source={plate} style={styles.plateTip} resizeMode="contain" />
                        <View style={{flex:1,display:'flex',flexDirection:'row',justifyContent:'space-between',alignItems:'center'}}>
                            <Text style={{fontSize:16,color:'#333'}}>发表到板块</Text>
                            <View style={{display:'flex',flexDirection:'row',alignItems:'center'}}>
                                <Text style={{fontSize:16,color:'#333'}}>灌水区</Text>
                                <Image source={arrow} style={styles.rightArrow} resizeMode="contain" />
                            </View>
                        </View>
                    </TouchableOpacity>
                </View>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    leftIcon:{
        width:(50/zoomW),
        height:'100%',
        display:'flex',
        flexDirection:'row',
        alignItems:'center'
    },
    backIcon:{
        width:(10/zoomW),
        height:(18/zoomH),
        marginLeft:(10/zoomW)
    },
    closeIcon:{
        width:(18/zoomW),
        height:(18/zoomH)
    },
    rightTop:{
        display:'flex',
        flexDirection:'row',
        alignItems:'center',
    },
    rightIcon:{
        height:'100%',
        width:(34/zoomW),
        display:'flex',
        justifyContent:'center',
        marginRight:(16/zoomW)
    },
    background:{
        width:'100%',
        height:'100%',
        backgroundColor:'#f3f3f3'
    },
    postTitle:{
        width:'100%',
        height:(44/zoomH),
        borderBottomWidth:xnBorderWidth(),
        borderBottomColor:'#eee',
        borderStyle:'solid',
        paddingLeft:(17/zoomW),
        paddingRight:(17/zoomW),
        backgroundColor:'#fff'
    },
    titleText:{
        height:'100%',
        color:'#333',
        fontSize:18
    },
    content:{
        width:'100%',
        backgroundColor:'#fff',
        paddingLeft:(17/zoomW),
        paddingRight:(17/zoomW),
    },
    selectItem:{
        width:'100%',
        height:(44/zoomH),
        borderTopWidth:1,
        borderTopColor:'#eee',
        borderStyle:'solid',
        display:'flex',
        flexDirection:'row',
        alignItems:'center'
    },
    contentText:{
        width:'100%',
        height:(180/zoomH),
        fontSize:16,
        color:'#333',
        textAlignVertical:'top',
        paddingTop:(10/zoomH),
        paddingBottom:(10/zoomH)
    },
    addImg:{
        marginBottom:(10/zoomH)
    },
    contentImg:{
        width:(80/zoomW),
        height:(80/zoomW),
        borderWidth:1,
        borderColor:'#ddd',
        borderStyle:'solid',
        display:'flex',
        justifyContent:'center',
        alignItems:'center'
    },
    plateTip:{
        width:(20/zoomW),
        height:(20/zoomW),
        marginRight:(10/zoomW)
    },
    rightArrow:{
        width:(10/zoomW),
        height:(10/zoomW),
        marginLeft:(10/zoomW)
    }
});