Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, {useState, useEffect} from 'react';
  2. import { View, StyleSheet, TextInput, ImageBackground, Text, TouchableOpacity } from "react-native";
  3. import Modal from 'react-native-modal';
  4. import BottomDrawer from 'rn-bottom-sheet';
  5. import {Ionicons} from '@expo/vector-icons';
  6.  
  7. export default AuthScreen = props => {
  8.   const [modalUp, setModalUp] = useState(false); // -300
  9.   const [phoneValidation, setPhoneValidation] = useState(false);
  10.   const [phoneNumber, setPhoneNumber] = useState('');
  11.  
  12.   const handleShowKeyboard = () => {
  13.     setModalUp(!modalUp)
  14.   }
  15.  
  16.   const handleKeyboardPress = key => {
  17.     if (key == 'backspace') {
  18.       setPhoneNumber(phoneNumber.slice(0, -1));
  19.     } else {
  20.       if (phoneNumber.length == 0 && key == 0) null;
  21.       else if (phoneNumber.length == 16) null;
  22.       else setPhoneNumber(phoneNumber+key);
  23.     }
  24.   }
  25.  
  26.   useEffect(()=>{
  27.     if (phoneNumber.length >= 9) setPhoneValidation(true);
  28.     else setPhoneValidation(false);
  29.   }, [phoneNumber])
  30.  
  31.   const styles = StyleSheet.create({
  32.     container: {
  33.       flex: 1,
  34.       backgroundColor: 'pink',
  35.     },
  36.     backgoundImage: {
  37.       flex: 1,
  38.       resizeMode: 'cover'
  39.     },
  40.     modal: {
  41.       justifyContent: 'flex-end',
  42.       margin: 0,
  43.     },
  44.     modalBotom: {
  45.       backgroundColor: 'white',
  46.       borderTopLeftRadius: 25,
  47.       borderTopRightRadius: 25,
  48.       paddingHorizontal: 25,
  49.       paddingTop: 30,
  50.       height: modalUp ? 500 : 200,
  51.       // marginBottom: modalMargin,
  52.     },
  53.     inputSection: {
  54.       borderBottomWidth: 2,
  55.       borderColor: '#E7E7E7',
  56.       flexDirection: 'row',
  57.       alignItems: 'center',
  58.       paddingBottom: 10,
  59.     },
  60.     phoneCodeText: {
  61.       fontSize: 18,
  62.     },
  63.     phoneInput: {
  64.       fontSize: 18,
  65.       paddingHorizontal: 25,
  66.     },
  67.     phoneClearIcon: {
  68.       fontSize: 20,
  69.       color: '#9CA4AC',
  70.     },
  71.     startButton: {
  72.       marginVertical: 20,
  73.       backgroundColor: phoneValidation ? '#FF0000' : '#9CA4AC',
  74.       height: 50,
  75.       alignItems: 'center',
  76.       justifyContent: 'center',
  77.       borderRadius: 25,
  78.     },
  79.     startButtonText: {
  80.       color: '#F2F3F4',
  81.       fontWeight: 'bold',
  82.     },
  83.     textSection: {
  84.       fontSize: 12,
  85.       textAlign: "center",
  86.       marginBottom: 30,
  87.     },
  88.     textRed: {
  89.       color: '#FF0000',
  90.     },
  91.     keyboardSection: {
  92.       flex: 1,
  93.       flexDirection: 'row',
  94.     },
  95.     keyboardButton: {
  96.       flex: 1,
  97.       alignItems: 'center',
  98.       justifyContent: 'center',
  99.     },
  100.     keyboardButtonText: {
  101.       fontSize: 20,
  102.       fontWeight: 'bold',
  103.     },
  104.     keyboardButtonIcon: {
  105.       fontSize: 25,
  106.       fontWeight: 'bold',
  107.     }
  108.   })
  109.  
  110.   return (
  111.     <ImageBackground source={require('../../../assets/bg-auth.jpg')} style={styles.container}>
  112.       <Modal
  113.         isVisible={true}
  114.         style={styles.modal}
  115.         swipeDirection={modalUp ? ['down'] : ['up']}
  116.         swipeThreshold={150}
  117.         onSwipeComplete={()=>{
  118.           setModalUp(!modalUp)
  119.         }}
  120.       >
  121.         <View style={styles.modalBotom}>
  122.             <View style={styles.inputSection}>
  123.               <Text style={styles.phoneCodeText}>+62</Text>
  124.               <TouchableOpacity onPress={()=>handleShowKeyboard()}>
  125.                 <TextInput style={styles.phoneInput} placeholder='Masukan Nomor Telpon...' editable={false} value={phoneNumber}/>
  126.               </TouchableOpacity>
  127.               <Ionicons name='md-close-circle' style={styles.phoneClearIonicons} onPress={()=>setPhoneNumber('')}></Ionicons>
  128.             </View>
  129.           <TouchableOpacity style={styles.startButton}>
  130.             <Text style={styles.startButtonText}>Start</Text>
  131.           </TouchableOpacity>
  132.           <Text style={styles.textSection}>Dengan masuk atau mendaftar berarti kamu menyetujui <Text style={styles.textRed}>Syarat dan Ketentuan</Text> dan <Text style={styles.textRed}>Kebijakan Privasi</Text></Text>
  133.          
  134.           <View style={styles.keyboardSection}>
  135.             <TouchableOpacity style={styles.keyboardButton} onPress={()=>handleKeyboardPress(1)}>
  136.               <Text style={styles.keyboardButtonText}>1</Text>
  137.             </TouchableOpacity>
  138.             <TouchableOpacity style={styles.keyboardButton} onPress={()=>handleKeyboardPress(2)}>
  139.               <Text style={styles.keyboardButtonText}>2</Text>
  140.             </TouchableOpacity>
  141.             <TouchableOpacity style={styles.keyboardButton} onPress={()=>handleKeyboardPress(3)}>
  142.               <Text style={styles.keyboardButtonText}>3</Text>
  143.             </TouchableOpacity>
  144.           </View>
  145.           <View style={styles.keyboardSection}>
  146.             <TouchableOpacity style={styles.keyboardButton} onPress={()=>handleKeyboardPress(4)}>
  147.               <Text style={styles.keyboardButtonText}>4</Text>
  148.             </TouchableOpacity>
  149.             <TouchableOpacity style={styles.keyboardButton} onPress={()=>handleKeyboardPress(5)}>
  150.               <Text style={styles.keyboardButtonText}>5</Text>
  151.             </TouchableOpacity>
  152.             <TouchableOpacity style={styles.keyboardButton} onPress={()=>handleKeyboardPress(6)}>
  153.               <Text style={styles.keyboardButtonText}>6</Text>
  154.             </TouchableOpacity>
  155.           </View>
  156.           <View style={styles.keyboardSection}>
  157.             <TouchableOpacity style={styles.keyboardButton} onPress={()=>handleKeyboardPress(7)}>
  158.               <Text style={styles.keyboardButtonText}>7</Text>
  159.             </TouchableOpacity>
  160.             <TouchableOpacity style={styles.keyboardButton} onPress={()=>handleKeyboardPress(8)}>
  161.               <Text style={styles.keyboardButtonText}>8</Text>
  162.             </TouchableOpacity>
  163.             <TouchableOpacity style={styles.keyboardButton} onPress={()=>handleKeyboardPress(9)}>
  164.               <Text style={styles.keyboardButtonText}>9</Text>
  165.             </TouchableOpacity>
  166.           </View>
  167.           <View style={styles.keyboardSection}>
  168.             <TouchableOpacity style={styles.keyboardButton}>
  169.               <Text style={styles.keyboardButtonText}>
  170.               </Text>
  171.             </TouchableOpacity>
  172.             <TouchableOpacity style={styles.keyboardButton} onPress={()=>handleKeyboardPress(0)}>
  173.               <Text style={styles.keyboardButtonText}>0</Text>
  174.             </TouchableOpacity>
  175.             <TouchableOpacity style={styles.keyboardButton} onPress={()=>handleKeyboardPress('backspace')}>
  176.               <Ionicons name='md-backspace' style={styles.keyboardButtonIonicons}></Ionicons>
  177.             </TouchableOpacity>
  178.           </View>
  179.         </View>
  180.       </Modal>
  181.     </ImageBackground>
  182.   )
  183. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement