Advertisement
Guest User

Untitled

a guest
Jul 8th, 2023
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. import React, { useState } from 'react';
  2. import { View, Text, TextInput, TouchableOpacity, ImageBackground, StyleSheet } from 'react-native';
  3.  
  4. const LoginScreen = () => {
  5. const [username, setUsername] = useState('');
  6. const [password, setPassword] = useState('');
  7.  
  8. const handleLogin = () => {
  9. // Perform login logic here (e.g., API request, validation)
  10.  
  11. if (username.length >= 8 && /^[A-Z]/.test(username) && password.length >= 8) {
  12. // Login successful
  13. console.log('Login successful');
  14. alert('Login สำเร็จ');
  15. } else {
  16. // Invalid credentials
  17. console.log('Invalid credentials');
  18. alert('Login ผิดพลาด');
  19. }
  20. };
  21.  
  22. return (
  23. <ImageBackground
  24. source={{ uri: 'https://codingmasterweb.com/wp-content/uploads/2021/12/Copy-of-Copy-of-for-thumbnail-1.jpg' }}
  25. style={styles.container}
  26. >
  27. <View style={styles.overlay} />
  28.  
  29. <View style={styles.content}>
  30. <Text style={styles.title}>Login</Text>
  31.  
  32. <View style={styles.inputContainer}>
  33. <Text style={styles.label}>Username</Text>
  34. <TextInput
  35. style={styles.input}
  36. onChangeText={(text) => setUsername(text)}
  37. />
  38. </View>
  39.  
  40. <View style={styles.inputContainer}>
  41. <Text style={styles.label}>Password</Text>
  42. <TextInput
  43. style={styles.input}
  44. secureTextEntry
  45. onChangeText={(text) => setPassword(text)}
  46. />
  47. </View>
  48.  
  49. <TouchableOpacity style={styles.button} onPress={handleLogin}>
  50. <Text style={styles.buttonText}>Login</Text>
  51. </TouchableOpacity>
  52. </View>
  53. </ImageBackground>
  54. );
  55. };
  56.  
  57. const styles = StyleSheet.create({
  58. container: {
  59. flex: 1,
  60. resizeMode: 'cover',
  61. },
  62. overlay: {
  63. ...StyleSheet.absoluteFillObject,
  64. backgroundColor: 'rgba(0, 0, 0, 0.6)',
  65. },
  66. content: {
  67. flex: 1,
  68. justifyContent: 'center',
  69. alignItems: 'center',
  70. paddingHorizontal: 30,
  71. },
  72. title: {
  73. fontSize: 24,
  74. fontWeight: 'bold',
  75. marginBottom: 20,
  76. color: '#fff',
  77. },
  78. inputContainer: {
  79. width: '100%',
  80. marginBottom: 20,
  81. },
  82. label: {
  83. fontSize: 16,
  84. marginBottom: 8,
  85. color: '#fff',
  86. },
  87. input: {
  88. height: 40,
  89. borderColor: '#ccc',
  90. borderWidth: 1,
  91. borderRadius: 5,
  92. paddingHorizontal: 10,
  93. color: '#fff',
  94. },
  95. button: {
  96. backgroundColor: '#007AFF',
  97. borderRadius: 5,
  98. paddingVertical: 12,
  99. paddingHorizontal: 20,
  100. },
  101. buttonText: {
  102. color: '#fff',
  103. fontSize: 18,
  104. fontWeight: 'bold',
  105. textAlign: 'center',
  106. },
  107. });
  108.  
  109. export default LoginScreen;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement