armadiazrino

Untitled

Jun 23rd, 2022
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. import {View, Text, Image, TextInput, TouchableOpacity} from 'react-native';
  2. import React, {useState} from 'react';
  3. import style from './style';
  4. import AsyncStorage from '@react-native-async-storage/async-storage';
  5.  
  6. const Login = props => {
  7. const [email, setEmail] = useState('');
  8. const [password, setPassword] = useState('');
  9.  
  10. const onLogin = () => {
  11. if (email === '[email protected]' && password === '12345678') {
  12. // Login Success
  13. props.navigation.reset({
  14. index: 0,
  15. routes: [{name: 'BottomTab'}],
  16. });
  17. AsyncStorage.setItem('isLoggedIn', 'true');
  18. } else {
  19. // Login Failed
  20. alert('username atau password salah');
  21. }
  22. };
  23.  
  24. return (
  25. <View style={style.container}>
  26. <Image style={style.image} source={require('../../assets/ticket.png')} />
  27. <Text style={style.textWelcome}>{'Selamat Datang'}</Text>
  28. <TextInput
  29. style={style.email}
  30. placeholder="Email"
  31. keyboardType="email-address"
  32. textContentType="emailAddress"
  33. value={email}
  34. onChangeText={value => {
  35. setEmail(value);
  36. }}
  37. />
  38. <TextInput
  39. style={style.password}
  40. placeholder="Password"
  41. textContentType="password"
  42. secureTextEntry={true}
  43. value={password}
  44. onChangeText={value => {
  45. setPassword(value);
  46. }}
  47. />
  48. <TouchableOpacity
  49. style={style.button}
  50. onPress={() => {
  51. onLogin();
  52. }}>
  53. <Text style={style.buttonText}>{'Login'}</Text>
  54. </TouchableOpacity>
  55. </View>
  56. );
  57. };
  58.  
  59. export default Login;
  60.  
Advertisement
Add Comment
Please, Sign In to add comment