QRTab.js 5.19 KB
import React, { Component } from 'react';
import { View, Text, StyleSheet, TouchableOpacity, Image,Linking, AppRegistry } from 'react-native';
 
import QRCodeScanner from 'react-native-qrcode-scanner';
import { RNCamera } from 'react-native-camera';
import Heart from '../../assets/heart_.svg'
import Chat from '../../assets/chat_.svg'
import Home from '../../assets/home.svg'
import QR from '../../assets/qr.svg'
import Alarm from '../../assets/alarm.svg'

import {post} from 'axios'

export default class QRTab extends Component {
    static navigationOptions = {
        
        headerShown: false
        
    }
    state= {
        marginTop:0
    }
    onSuccess = e => {
    
    post(JSON.parse(e.data).url,JSON.parse(e.data)).then(res => {
        if(res.data.success) {
            alert("스탬프 사용에 성공하였습니다.")
        }
    })
      //Linking.openURL(e.data).catch(err =>
      //  console.error('An error occured', err)
      //);
    };
    
    render() {
        return (
            <View style={{width:"100%",height:"100%",backgroundColor:"#979292"}}>
                <View onLayout={e => {
                    if(e.nativeEvent.layout.height >0) {
                        this.setState({marginTop:e.nativeEvent.layout.height})}
                    }} style={{width:"100%",zIndex:1000,flexDirection:"row",paddingTop:16,paddingBottom:16,paddingLeft:16,position:"absolute",backgroundColor:"#615F5F"}}>
                    <TouchableOpacity onPress={() => this.props.navigation.goBack(null)}>
                        <Image source={require('../../assets/back.png')}/>
                    </TouchableOpacity>
                    <Text style={{color:"white",fontSize:16,marginLeft:16}}>
                        스캔
                    </Text>
                </View>
                <View style={{position:"relative",alignSelf:"center"}}>
                    <QRCodeScanner
                        cameraStyle={{borderBottomColor:"red"}}
                        containerStyle={{}}
                        onRead={this.onSuccess}
                        cameraProps={{ratio:"1:1"}}
                        showMarker={true}
                        customMarker={
                            <View style={{width:"50%",height:"50%",}}>
                                <View style={{flexDirection:"row",height:"30%"}}>
                                    <View style={{borderBottomColor:"transparent",borderRightColor:"transparent",width:"30%",height:"100%",borderTopLeftRadius:10,borderWidth:3,borderLeftColor:"#FFD63A",borderTopColor:"#FFD63A"}}>
                                    </View>
                                    <View style={{marginLeft:"auto",borderBottomColor:"transparent",borderLeftColor:"transparent",width:"30%",height:"100%",borderTopRightRadius:10,borderWidth:3,borderRightColor:"#FFD63A",borderTopColor:"#FFD63A"}}>
                                    </View>
                                </View>
                                <View style={{justifyContent:"center"}}>
                                    <Text style={{textAlign:"center",color:"#FFD63A",fontSize:67,lineHeight:67}}>
                                        +
                                    </Text>
                                </View>
                                <View style={{flexDirection:"row",height:"30%",marginTop:"auto"}}>
                                    <View style={{borderTopColor:"transparent",borderRightColor:"transparent",width:"30%",height:"100%",borderBottomLeftRadius:10,borderWidth:3,borderLeftColor:"#FFD63A",borderBottomColor:"#FFD63A"}}>
                                    </View>
                                    <View style={{marginLeft:"auto",borderTopColor:"transparent",borderLeftColor:"transparent",width:"30%",height:"100%",borderBottomRightRadius:10,borderWidth:3,borderRightColor:"#FFD63A",borderBottomColor:"#FFD63A"}}>
                                    </View>
                                </View>
                            </View>
                        }
                    />
                </View>
                <View style={{
                    shadowColor: "#000",
                    shadowOffset: {
                        width: 0,
                        height: 6,
                    },
                    shadowOpacity: 0.39,
                    shadowRadius: 8.30,
                    
                    elevation: 13,
                    flexDirection:"row",justifyContent:"space-between",paddingLeft:24,paddingRight:24,paddingTop:19,paddingBottom:19,width:"100%",position:"absolute",backgroundColor:"white",bottom:0}}>
                    <Home onPress={() => this.props.navigation.replace("Main_")}/>
                    <Chat onPress={() => this.props.navigation.replace("ChatTab")}/>
                    <QR onPress={() => this.props.navigation.replace("QRTab")}/>
                    <Heart onPress={() => this.props.navigation.replace("LikeTab")}/>
                    <Alarm onPress={() => this.props.navigation.replace("AlarmTab")}/>
                </View>
            </View>
        );
    }
}
 
const style = StyleSheet.create({
    container: {
        flex: 1,
        alignItems: 'center',
        justifyContent: 'center',
    }
});
AppRegistry.registerComponent('default', () => QRTab);