thirdStep.js 7.43 KB
/**
 * Created by xiniu on 2018/11/6.
 */
import React, {Component} from 'react';
import {Dimensions, Image, Platform, StatusBar, StyleSheet, Text, TouchableOpacity, View} from 'react-native';
import Slider from 'react-native-slider';
import {observer} from 'mobx-react';
import {getFooterBottom, getHomeColor} from '../../utils/utils';
import uploadVideoThirdLogic from './logic/uploadVideoThirdLogic';
import {zoomH} from "../../utils/getSize";

const zoomW = 750 / parseInt(Dimensions.get('window').width);

@observer
export default class UploadVideoThirdStep extends Component {


    static navigationOptions = ({ navigation, screenProps }) => ({
        headerStyle: {
            height: 40,
            elevation: 0, // 去掉阴影
            borderBottomWidth: 0,
            backgroundColor: "#000"
        },
        headerTitleStyle: {
            flex: 1,
            textAlign: "center",
            alignSelf: "center",
            alignItems: "center",
            justifyContent: "center",
            flexDirection: "column",
            color: "#fff",
            fontSize: 18,
        },
        title: '编辑封面',
        headerLeft: (
            <TouchableOpacity activeOpacity={0.8} style={styles.backWrap} onPress={() => { navigation.goBack(); navigation.state.params.callBack(true); }}>
                <Image source={require('../../img/closeWhite.png')} style={{ width: 31 / zoomW, height: 16.5 }} resizeMode="contain" />
            </TouchableOpacity>
        ),
        headerRight: (
            <TouchableOpacity activeOpacity={0.8} style={styles.rightWrap} onPress={() => navigation.state.params.saveCover()}>
                <Text style={{ fontSize: 16, color: '#fff' }}>完成</Text>
            </TouchableOpacity>
        ),
    });

    logic = new uploadVideoThirdLogic();

    constructor(props) {
        super(props);
        this.state = {
            videoUrl: this.props.navigation.state.params.videoUrl || '',
            videoDuration: this.props.navigation.state.params.videoDuration || 0,
            currentTime: this.props.navigation.state.params.videoCoverTime || 0,
            threadVideoDirection: this.props.navigation.state.params.threadVideoDirection || 0,
        };
    }

    componentWillMount() {
        this.logic.moveSlider(this.state.currentTime, this.state.videoDuration);
    }

    componentDidMount() {
        this.props.navigation.setParams({
            saveCover: () => this.saveCover(),
        });
    }

    // 进度条值改变
    onSliderValueChanged(currentTime) {
        this.logic.moveSlider(currentTime, this.state.videoDuration);
    }

    // 保存视频封面图
    saveCover() {
        const url = this.state.videoUrl + '?x-oss-process=video/snapshot,t_' + parseInt(this.logic.currentTime * 1000) + ',f_png,w_375,h_0';
        this.props.navigation.goBack();
        this.props.navigation.state.params.callBack(true);
        this.props.navigation.state.params.setCover(url, this.logic.currentTime);
    }

    render() {
        return (
            <View style={styles.container}>
                <StatusBar
                    backgroundColor={'#000'}
                    barStyle={'light-content'}
                    networkActivityIndicatorVisible
                />
                <View style={styles.imageWrap}>
                    <Image source={{ uri: this.state.videoUrl + '?x-oss-process=video/snapshot,t_' + parseInt(this.logic.currentTime * 1000) + ',f_png,w_375,h_0'}} style={{ width: '100%', height: '100%', transform:[{rotate:this.state.threadVideoDirection + 'deg'}]}} resizeMode="contain" />
                </View>
                <View style={styles.controlWrap}>
                    <View style={{ height: 37.5, justifyContent: 'center' }}>
                        <Text style={{ fontSize: 14, color: 'rgba(255,255,255,.45)' }}>滑动选择封面图</Text>
                    </View>
                    <View style={{ width: 630 / zoomW, height: 63, flexDirection: 'row' }}>
                        <Image source={{ uri: this.state.videoUrl + '?x-oss-process=video/snapshot,t_0,f_png,w_375,h_0'}} style={{ width: 126 / zoomW, height: '100%' , transform:[{rotate:this.state.threadVideoDirection + 'deg'}]}} resizeMode="cover" />
                        <Image source={{ uri: this.state.videoUrl + '?x-oss-process=video/snapshot,t_' + parseInt(this.state.videoDuration / 4 * 1000) + ',f_png,w_375,h_0'}} style={{ width: 126 / zoomW, height: '100%' , transform:[{rotate:this.state.threadVideoDirection + 'deg'}]}} resizeMode="cover" />
                        <Image source={{ uri: this.state.videoUrl + '?x-oss-process=video/snapshot,t_' + parseInt(this.state.videoDuration / 2 * 1000) + ',f_png,w_375,h_0'}} style={{ width: 126 / zoomW, height: '100%' , transform:[{rotate:this.state.threadVideoDirection + 'deg'}]}} resizeMode="cover" />
                        <Image source={{ uri: this.state.videoUrl + '?x-oss-process=video/snapshot,t_' + parseInt(this.state.videoDuration / 4 * 3000) + ',f_png,w_375,h_0'}} style={{ width: 126 / zoomW, height: '100%' , transform:[{rotate:this.state.threadVideoDirection + 'deg'}]}} resizeMode="cover" />
                        <Image source={{ uri: this.state.videoUrl + '?x-oss-process=video/snapshot,t_' + parseInt(this.state.videoDuration * 1000) + ',f_png,w_375,h_0'}} style={{ width: 126 / zoomW, height: '100%' , transform:[{rotate:this.state.threadVideoDirection + 'deg'}]}} resizeMode="cover" />
                        <View style={[styles.borderView, { left: this.logic.left,borderColor: global.homeColor, }]}></View>
                    </View>
                    <View style={{ width: 557 / zoomW, height: 56.5, justifyContent: 'center' }}>
                        <Slider
                            style={{ width: '100%', height: 35.5 }}
                            minimumTrackTintColor={'transparent'}
                            maximumTrackTintColor={'transparent'}
                            thumbStyle={{
                                width: 55 / zoomW,
                                height: 35.5,
                                backgroundColor: 'transparent',
                                justifyContent: 'center'
                            }}
                            thumbImage={require('../../img/sliderButton.png')}
                            value={this.logic.currentTime}
                            minimumValue={0}
                            maximumValue={this.state.videoDuration}
                            onValueChange={(currentTime) => { this.onSliderValueChanged(currentTime) }}
                        />
                    </View>
                </View>
            </View>
        )
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#000'
    },
    backWrap: {
        height: '100%',
        justifyContent: 'center',
        paddingLeft: 30 / zoomW,
        paddingRight: 30 / zoomW,
    },
    rightWrap: {
        height: '100%',
        justifyContent: 'center',
        paddingLeft: 40 / zoomW,
        paddingRight: 40 / zoomW,
    },
    imageWrap: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center'
    },
    controlWrap: {
        width: '100%',
        height: 157,
        borderTopWidth: StyleSheet.hairlineWidth,
        borderTopColor: 'rgba(255,255,255,.2)',
        alignItems: 'center',
        marginBottom:getFooterBottom(),
    },
    borderView: {
        width: 126 / zoomW,
        height: 70,
        borderWidth: 2,
        position: 'absolute',
        top: -3
    },
});