Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { useState } from 'react';
- import { View, Text, TextInput, TouchableOpacity, ImageBackground, StyleSheet } from 'react-native';
- const LoginScreen = () => {
- const [username, setUsername] = useState('');
- const [password, setPassword] = useState('');
- const handleLogin = () => {
- // Perform login logic here (e.g., API request, validation)
- if (username.length >= 8 && /^[A-Z]/.test(username) && password.length >= 8) {
- // Login successful
- console.log('Login successful');
- alert('Login สำเร็จ');
- } else {
- // Invalid credentials
- console.log('Invalid credentials');
- alert('Login ผิดพลาด');
- }
- };
- return (
- <ImageBackground
- source={{ uri: 'https://codingmasterweb.com/wp-content/uploads/2021/12/Copy-of-Copy-of-for-thumbnail-1.jpg' }}
- style={styles.container}
- >
- <View style={styles.overlay} />
- <View style={styles.content}>
- <Text style={styles.title}>Login</Text>
- <View style={styles.inputContainer}>
- <Text style={styles.label}>Username</Text>
- <TextInput
- style={styles.input}
- onChangeText={(text) => setUsername(text)}
- />
- </View>
- <View style={styles.inputContainer}>
- <Text style={styles.label}>Password</Text>
- <TextInput
- style={styles.input}
- secureTextEntry
- onChangeText={(text) => setPassword(text)}
- />
- </View>
- <TouchableOpacity style={styles.button} onPress={handleLogin}>
- <Text style={styles.buttonText}>Login</Text>
- </TouchableOpacity>
- </View>
- </ImageBackground>
- );
- };
- const styles = StyleSheet.create({
- container: {
- flex: 1,
- resizeMode: 'cover',
- },
- overlay: {
- ...StyleSheet.absoluteFillObject,
- backgroundColor: 'rgba(0, 0, 0, 0.6)',
- },
- content: {
- flex: 1,
- justifyContent: 'center',
- alignItems: 'center',
- paddingHorizontal: 30,
- },
- title: {
- fontSize: 24,
- fontWeight: 'bold',
- marginBottom: 20,
- color: '#fff',
- },
- inputContainer: {
- width: '100%',
- marginBottom: 20,
- },
- label: {
- fontSize: 16,
- marginBottom: 8,
- color: '#fff',
- },
- input: {
- height: 40,
- borderColor: '#ccc',
- borderWidth: 1,
- borderRadius: 5,
- paddingHorizontal: 10,
- color: '#fff',
- },
- button: {
- backgroundColor: '#007AFF',
- borderRadius: 5,
- paddingVertical: 12,
- paddingHorizontal: 20,
- },
- buttonText: {
- color: '#fff',
- fontSize: 18,
- fontWeight: 'bold',
- textAlign: 'center',
- },
- });
- export default LoginScreen;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement