Blame view

js/groupPurchase/components/ListSnapshootShare.android.js 11 KB
aozhe.zhu authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
'use strict';

import React from 'react';
import ReactNative , {Platform}from 'react-native';
import YH_Image from '../../common/components/YH_Image';
import {getSlicedUrl} from '../../classify/utils/Utils';
import { captureRef } from "react-native-view-shot";

const {
    AppRegistry,
    StyleSheet,
    Image,
    View,
    Dimensions,
    TouchableOpacity,
    Modal,
    Text,
    CameraRoll,
    Alert,
    ScrollView,
} = ReactNative;


export default class SnapshootShare extends React.Component {
    constructor(props) {
        super(props);
        this.saveImage = this.saveImage.bind(this);
        this.shareImage = this.shareImage.bind(this);
    }

    shareImage(shareType){
        if (Platform.OS === 'ios') {
            ReactNative.takeSnapshot(this.refs.container, {format: 'png', quality: 10}).then(
                (uri) => {
                    this.props.shareSnapshootAction && this.props.shareSnapshootAction(shareType,uri);
                }).catch(
                (error) => {
                    Alert.alert('图片生成失败!')
                });

        } else {
            captureRef(this.refs.container, {format: 'png', quality: 10}).then(
                (uri) => {
                    this.props.shareSnapshootAction && this.props.shareSnapshootAction(shareType,uri);
                }).catch(
                (error) => {
                    Alert.alert('图片生成失败!')
                });
        }
    }

    saveImage(){
        if (Platform.OS === 'ios'){
            ReactNative.takeSnapshot(this.refs.container, {format: 'png', quality: 10}).then(
                (uri) => {
                    var promise = CameraRoll.saveToCameraRoll(uri);
                    promise.then(function(result) {
                        Alert.alert('保存成功!')
                    }).catch(function(error) {
                        Alert.alert('保存失败!')
                    });
                }).catch(
                (error) => {
                    Alert.alert('保存失败!')
                });
        } else {
            captureRef(this.refs.container, {format: 'png', quality: 10}).then(
                (uri) => {
                    var promise = CameraRoll.saveToCameraRoll(uri);
                    promise.then(function(result) {
                        Alert.alert('保存成功!')
                    }).catch(function(error) {
                        Alert.alert('保存失败!')
                    });
                }).catch(
                (error) => {
                    Alert.alert('保存失败!')
                });
        }
    }

    render() {
      let { shareCodeInfo, qrCode, unionType } = this.props;
      shareCodeInfo = shareCodeInfo ? shareCodeInfo.toJS() : {};
      let productIcon = shareCodeInfo.bigImage ? getSlicedUrl(shareCodeInfo.bigImage,218*DEVICE_WIDTH_RATIO, 282*DEVICE_WIDTH_RATIO, 2) : '';

        return (
            <Modal
                visible={this.props.show}
                animationType={'none'}
                transparent={true}
                onRequestClose={() => {
                }}>
                <View style={styles.modalContainer}>
                    <ScrollView
                      style={styles.scrollView}
                      vertical={true}
                      showsVerticalScrollIndicator={false}
                    >
                      <View style={styles.container} ref='container'>

                            <Image source={require('../images/share-logo.png')} resizeMode={'contain'} style={styles.logo} />
                            <View style={styles.product}>
                                <YH_Image style={styles.productimage} url={productIcon}></YH_Image>
                            </View>
                            <View style={styles.bottom}>
                                <Image source={{uri: qrCode}} resizeMode={'contain'} style={styles.qr} />
                                <View style={styles.bottomDetail}>
                                    <View style={styles.titleV}>
110
                                        <Text style={styles.titleText} numberOfLines={1}>有货友拼团,潮人专属福利团</Text>
aozhe.zhu authored
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
                                    </View>
                                    <Text style={styles.tipDetailText}>长按图片识别小程序参团</Text>
                                </View>
                            </View>
                        </View>
                      <View style={styles.spaceV}/>
                      </ScrollView>
                  <View style={styles.shareView}>
                    <View style={styles.buttons}>
                      <TouchableOpacity activeOpacity={0.5} style={styles.button1} onPress={() => {
                        this.shareImage && this.shareImage('WXSceneSession');
                      }}>
                          <Image source={unionType ? require('../images/unionShare_wx_icon.png') : require('../images/weixin.png')} style={styles.icon} />
                          <Text style={styles.text}>微信好友</Text>
                      </TouchableOpacity>
                      <TouchableOpacity activeOpacity={0.5} style={styles.button2} onPress={() => {
                        this.shareImage && this.shareImage('WXSceneTimeline');
                      }}>
                        <Image source={unionType ? require('../images/unionShare_timeline_icon.png') : require('../images/share_timeline_icon.png')} style={styles.icon} />
                        <Text style={styles.text}>微信朋友圈</Text>
                      </TouchableOpacity>
                    </View>
                    <View style={styles.line}/>
                    <TouchableOpacity activeOpacity={0.5} style={styles.save} onPress={() => {
                      this.saveImage && this.saveImage();
                    }}>
                      <Text style={styles.savetext}>保存图片</Text>
                    </TouchableOpacity>
                  </View>

                  <TouchableOpacity activeOpacity={0.5} style={styles.cancelBtn} onPress={() => {
                    this.props.showSnapshootShare && this.props.showSnapshootShare(false);
                  }}>
                    <Image source={require('../images/imageShareClose.png')} style={styles.cancelBtnicon} resizeMode={'contain'}/>
                  </TouchableOpacity>

                </View>
            </Modal>
        );
    }
};

let {width, height} = Dimensions.get('window');
const DEVICE_WIDTH_RATIO = width / 375;

let styles = StyleSheet.create({
    modalContainer: {
        flex: 1,
        width: width,
        height: height,
    },
    backContainer: {
        flex: 1,
        width: width,
        height: height,
        alignItems: 'center',
        backgroundColor: 'white',
    },

    container: {
        width,
        height,
        backgroundColor: 'white',
        alignItems: 'center',
    },

    scrollView: {
        backgroundColor: 'white',
    },
    spaceV: {
        backgroundColor: 'white',
        height: 150*DEVICE_WIDTH_RATIO,
        width,
    },

    logo: {
        height: 22*DEVICE_WIDTH_RATIO,
        width: 112*DEVICE_WIDTH_RATIO,
        marginTop: 37*DEVICE_WIDTH_RATIO,
    },

    productimage: {
193
        height: 433*DEVICE_WIDTH_RATIO,
aozhe.zhu authored
194 195 196 197
        width: 325*DEVICE_WIDTH_RATIO,
    },

    product: {
198
        height: 433*DEVICE_WIDTH_RATIO,
aozhe.zhu authored
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
        width: 325*DEVICE_WIDTH_RATIO,
        marginTop: 24*DEVICE_WIDTH_RATIO,
    },
    productDetail: {
        height: 80*DEVICE_WIDTH_RATIO,
        width: 325*DEVICE_WIDTH_RATIO,
        backgroundColor: 'rgba(0,0,0,0.4)',
        position: 'absolute',
        bottom: 0,
    },
    productDetailTop: {
        height: 20*DEVICE_WIDTH_RATIO,
        width: 325*DEVICE_WIDTH_RATIO,
        marginTop: 14*DEVICE_WIDTH_RATIO,
        justifyContent: 'center',
        alignItems: 'center',
    },
    productDetailTopText: {
        fontSize: 14,
        color: '#FFFFFF',
    },
    productDetailBottom: {
        height: 30*DEVICE_WIDTH_RATIO,
        width: 325*DEVICE_WIDTH_RATIO,
        marginTop: 7*DEVICE_WIDTH_RATIO,
        flexDirection: 'row',
        justifyContent: 'center',
        alignItems: 'center',
    },
    priceIcon: {
        height: 17,
        width: 50,
    },
    price: {
        fontSize: 24,
        color: '#FFFFFF',
        marginLeft: 15*DEVICE_WIDTH_RATIO,
        fontWeight: 'bold',
    },
    price2: {
        fontSize: 14,
        lineHeight: 14,
        color: '#B0B0B0',
        alignItems: 'center',
        marginLeft: 13*DEVICE_WIDTH_RATIO,
        height: 14,
        marginTop: 2,
    },

    mianyouIcon: {
        position: 'absolute',
        top: 262*DEVICE_WIDTH_RATIO,
        right: 28*DEVICE_WIDTH_RATIO,
        height: 63*DEVICE_WIDTH_RATIO,
        width: 63*DEVICE_WIDTH_RATIO,
    },

    bottom: {
        height: 141*DEVICE_WIDTH_RATIO,
        width: 325*DEVICE_WIDTH_RATIO,
        alignItems: 'center',
        flexDirection: 'row',
    },
    qr: {
        height: 80*DEVICE_WIDTH_RATIO,
        width: 80*DEVICE_WIDTH_RATIO,
    },

    bottomDetail: {
        height: 80*DEVICE_WIDTH_RATIO,
        width: 245*DEVICE_WIDTH_RATIO,
    },
    titleV: {
        width: 218*DEVICE_WIDTH_RATIO,
        height: 20*DEVICE_WIDTH_RATIO,
        flexDirection: 'row',
        alignItems: 'center',
        marginTop: 16*DEVICE_WIDTH_RATIO,
        marginLeft: 27*DEVICE_WIDTH_RATIO,
    },
    titleText: {
280
        fontSize: 13,
aozhe.zhu authored
281 282 283
        color: '#444444',
    },
    tipDetailText: {
284
        fontSize: 11,
aozhe.zhu authored
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
        color: '#B0B0B0',
        marginTop: 12*DEVICE_WIDTH_RATIO,
        marginLeft: 27*DEVICE_WIDTH_RATIO,
    },

    shareView: {
        position: 'absolute',
        width,
        height: 171*DEVICE_WIDTH_RATIO,
        backgroundColor: 'rgb(241,241,241)',
        alignItems: 'center',
        bottom : 0,
    },
    image :{
        width: 305*DEVICE_WIDTH_RATIO,
        height: 88*DEVICE_WIDTH_RATIO,
        marginTop: 25*DEVICE_WIDTH_RATIO,
        backgroundColor: 'red',
    },
    buttons: {
        width,
        height: 115*DEVICE_WIDTH_RATIO,
        alignItems: 'center',
        flexDirection: 'row',
    },
    button1: {
        alignItems: 'center',
        marginLeft: (width - 180*DEVICE_WIDTH_RATIO)/3,
    },

    button2: {
        marginLeft: (width - 180*DEVICE_WIDTH_RATIO)/3,
        alignItems: 'center',
    },
    icon: {
        width: 45*DEVICE_WIDTH_RATIO,
        height: 45*DEVICE_WIDTH_RATIO,
    },
    text: {
        marginTop: 8*DEVICE_WIDTH_RATIO,
        fontSize: 12,
        width: 90*DEVICE_WIDTH_RATIO,
        textAlign: 'center',
        color: '#444444',
    },
    line: {
        width: width - 52,
        height: 1,
        backgroundColor: '#CCCCCC',
    },
    save: {
        width,
        height: 54*DEVICE_WIDTH_RATIO,
        justifyContent: 'center',
        alignItems: 'center',
    },
    savetext: {
        fontSize: 17,
        color: '#444444',
    },

    cancelBtn: {
        position: 'absolute',
        width: 54*DEVICE_WIDTH_RATIO,
        height: 54*DEVICE_WIDTH_RATIO,
        top: 44,
        right: 34,
        alignItems: 'flex-end',
    },
    cancelBtnicon: {
        width: 30*DEVICE_WIDTH_RATIO,
        height: 30*DEVICE_WIDTH_RATIO,
    },
});