import React, { Component } from "react"; import { Platform, StyleSheet, View, TextInput, TouchableOpacity, SafeAreaView, Keyboard, TouchableWithoutFeedback } from "react-native"; import { observable } from "mobx"; import { observer, inject } from "mobx-react/native"; import Text from "react-native-text"; import theme from "../../config/colors"; import firebase from "react-native-firebase"; import Header from "../../components/Public/signInUpHeader"; import { scale, verticalScale, moderateScale } from "react-native-size-matters"; import Size from "../../config/size"; import { width, height } from "../../config/screen"; import { Button } from "react-native-elements"; import CodeInput from "react-native-confirmation-code-input"; const size = new Size(); import Toast, { DURATION } from "react-native-easy-toast"; import Countdown, { CountdownStatus } from "rn-countdown"; import { Fonts } from "../../config/fonts"; @inject(["userStore"]) @observer export default class SignUpVerify extends Component { @observable resend = false; @observable signInData = { email: "", countryCode: "852", mobile: "", pwd: "", name: "", verificationCode:"" }; constructor(props) { super(props); this.store = this.props.userStore; } componentDidMount() { // this.startToCount(); } componentWillUnmount = () => { // clearInterval(this.interval); }; state = { checked: false }; navigatieAction(page) { this.props.navigation.navigate(page); } startToCount() { this.interval = setInterval(() => { this.count(); }, 1000); } count() { this.store.countdown -= 1; if (this.store.countdown == 0) { this.resend = true; clearInterval(this.interval); } } signupAction() { if(this.store.signUpData.verificationCode == "" || this.store.signUpData.verificationCode == null){ this.refs.toast.show('Please enter the verification no.') }else{ this.store.signupPost( this); } } resendAction() { this.store.countdown = 10; this.resend = false; this.startToCount(); } handleClickCountdown = () => { var bodyFormData = new FormData(); bodyFormData.append("country_code", "852"); bodyFormData.append("phone_number",this.store.signUpData.mobile.toString() ); this.store.sendsmsVerify(bodyFormData, this); }; startToCountDown = () => { this.countdown && this.countdown.startCountdown(); }; handleNetworkFailed = () => alert("network failed"); handleStopCountdown = () => this.countdown && this.countdown.stopCountdown(); countDownButton() { return ( (this.countdown = r)} time={60} onPress={this.handleClickCountdown} onNetworkFailed={this.handleNetworkFailed} onDidFinishCountdown={this.handleCountdownOver} > {({ status, time }) => { let title, containerStyle, titleStyle; switch (status) { case CountdownStatus.Idle: title = "send"; containerStyle = styles.countdown; titleStyle = styles.countdownTitle; break; case CountdownStatus.Counting: title = `sent(${time})`; containerStyle = styles.countdown; titleStyle = styles.countdownTitle; break; case CountdownStatus.Over: title = "resend"; containerStyle = styles.countdown; titleStyle = styles.countdownTitle; break; } return ( {title} ); }} ); } render() { return (
{this.store.signUpData.mobile} {this.countDownButton()} this.store.signUpData.verificationCode = text} keyboardType = {'numeric'} underlineColorAndroid="rgba(0,0,0,0)" placeholder="verification no." placeholderStyle={{ fontWeight: "bold", fontFamily: Fonts.century, fontSize: size.getSize(10) }} placeholderTextColor={theme.foodNameColor} /> { this.signupAction(); }} > Register No More Hangry ); } } const styles = StyleSheet.create({ container: { flex: 1, alignItems: "center", backgroundColor: "white" }, mainContainer: { width: width, flex: 1 }, loginButton: { width: scale(200), height: verticalScale(50), marginTop: moderateScale(30) }, signupButton: { width: width, height: verticalScale(50) }, phoneCell: { flexDirection: "row", alignItems: "center", justifyContent: "space-between", paddingHorizontal: 15, height: 40, borderBottomWidth: 1, borderColor: "#ebebeb", width: width, backgroundColor: "#fff" }, phoneInfo: { flexDirection: "row", alignItems: "center" }, input: { height: 30, width: width * 0.4, marginLeft: 10, padding: 0, fontSize: 14 }, countdown: { borderRadius: 5, borderWidth: 2, borderColor: theme.coolGrey, height: verticalScale(40), justifyContent: "center", alignItems: "center" }, countdownTitle: { color: theme.coolGrey, fontSize: 12 }, signupButton: { backgroundColor: theme.mainColor, width: width, height: verticalScale(60), justifyContent: "center", alignItems: "center" } });