formik ve yup için
1 |
npm i formik |
1 |
npm i yum |
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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
import React from 'react'; import {View, StyleSheet,Text,Image,TextInput} from "react-native"; import { SafeAreaView } from "react-navigation"; import { ScrollView, TouchableOpacity } from "react-native-gesture-handler"; import Icon from "react-native-vector-icons/FontAwesome5"; import { Formik} from "formik"; import * as Yup from 'yup'; export default class Login extends React.Component{ constructor() { super(); this.state = { hidePassword:true } } _handleSubmit = () => { alert("Form Submit Edildi"); } render() { return ( <SafeAreaView style={style.body}> <ScrollView> <View style={style.header}> <Text style={style.title}>Sign In</Text> </View> <View style={style.logo_area}> <Image source={require('../../../assets/images/home.png')} /> </View> <View style={style.board}> <Formik initialValues={{ username:'', password:'', }} onSubmit={this._handleSubmit} validationSchema={Yup.object().shape({ username:Yup.string().required("Username Gereklidir"), password:Yup.string().required("Şifre gereklidir") })} > {({ values, handleSubmit, errors, handleChange}) => ( <View> <View style={style.item}> <TextInput value={values.username} onChangeText={handleChange('username')} placeholder={"Username"} style={style.input} /> {(errors.username) && <Text style={style.alert}>{errors.username}</Text>} </View> <View style={style.item}> <TextInput value={values.password} onChangeText={handleChange('password')} placeholder={"Password"} secureTextEntry={this.state.hidePassword} style={style.input} /> {(errors.password) && <Text style={style.alert}>{errors.password}</Text>} <TouchableOpacity onPress={()=>this.setState({hidePassword:!this.state.hidePassword })} style={{position:'absolute',right:15,top:-33}}> <Icon name={(this.state.hidePassword) ? "eye-slash" : "eye"} size={20} /> </TouchableOpacity> </View> <View style={[style.item,{flexDirection:'row',justifyContent: 'flex-end'}]}> <Text style={{ color: "#525464",fontSize: 15 }}>Forgot your password?</Text> </View> <View style={style.item}> <TouchableOpacity onPress={handleSubmit} style={style.button}> <Text style={style.button_text}>Login</Text> </TouchableOpacity> </View> </View> )} </Formik> <View style={[style.item,{justifyContent: 'center',alignItems:'center'}]}> <Text style={{ color: "#525464",fontSize: 15 }}>Or</Text> </View> <View style={style.social}> <TouchableOpacity style={style.social_item}> <Icon name={"facebook-f"} color={"#3b5999"} size={20}/> </TouchableOpacity> <TouchableOpacity style={style.social_item}> <Icon name={"twitter"} color={"#55acee"} size={20}/> </TouchableOpacity> <TouchableOpacity style={style.social_item}> <Icon name={"linkedin-in"} color={"#0077B5"} size={20}/> </TouchableOpacity> </View> <View style={[style.item,{justifyContent: 'center',alignItems:'center'}]}> <TouchableOpacity> <Text style={{fontSize:17,fontWeight:'400'}}>Dont have an account? <Text style={{color:'#FFB19D'}}>Sign Up</Text></Text> </TouchableOpacity> </View> </View> </ScrollView> </SafeAreaView> ) } } const style = StyleSheet.create({ body:{backgroundColor:'white',flex:1}, header:{padding:25,justifyContent:'center',alignItems:'center'}, title:{fontWeight:'500',fontSize:20,color:'#525464'}, logo_area:{alignItems: 'center',marginTop:40}, board:{marginTop:10,paddingHorizontal:30,paddingTop:20}, item:{marginBottom:20}, alert:{color:'red',fontSize:15}, social_item:{padding:10,borderWidth: 1,borderColor:'#E2E2E0',width:100,height: 60,justifyContent:'center',alignItems:'center'}, social:{flexDirection:'row',justifyContent:'space-around',marginBottom: 20}, button_text:{color:'white',textAlign:'center',fontSize:17,fontWeight: '700'}, button:{backgroundColor:'#20C3AF',padding:15,borderRadius:5,justifyContent: 'center',alignItems:'center'}, input:{borderWidth:1,borderColor:'#B0B0C3',backgroundColor: '#F7F7F7',paddingVertical: 10,paddingHorizontal:30,height:50} }) |