TouchableOpacity在安卓模拟器和手机上都能用,但是当我生成APK后,TouchableOpacity就不能用了。
可能发生了什么?
当我点击TouchableOpacity时,什么都没有发生,只是让不透明度动画。
正确的做法是进入主屏幕,但它不
它是否有像z-index这样的东西在上面?
Javascript代码
import React from 'react';
import {View, Image, Text, TouchableOpacity, TextInput} from 'react-native';
import {useNavigation} from '@react-navigation/native';
import {useField} from '@unform/core';
import {Form} from '@unform/mobile';
import {KeyboardAwareScrollView} from 'react-native-keyboard-aware-scroll-view';
import styles from './styles';
import logoImg from '../../assets/logo.png';
import Home from '../Home';
export default function Login() {
const navigation = useNavigation();
function navigateToHome() {
navigation.navigate(Home);
}
return (
<KeyboardAwareScrollView style={styles.scroll}>
<View style={styles.container}>
<Image style={styles.logo} source={logoImg} />
<TextInput style={styles.input} placeholder="Login" />
<TextInput
secureTextEntry={true}
style={styles.inputPassword}
placeholder="Senha"
/>
<TouchableOpacity style={styles.button} onPress={navigateToHome}>
<Text style={styles.buttonText}>Entrar</Text>
</TouchableOpacity>
</View>
</KeyboardAwareScrollView>
);
}
风格代码 Bellow
import {StyleSheet} from 'react-native';
export default StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
backgroundColor: '#fff',
},
scroll: {
backgroundColor: '#fff',
},
logo: {
marginTop: 30,
},
input: {
marginTop: 30,
padding: 10,
width: 300,
height: 56,
backgroundColor: '#f5f5f5',
fontSize: 16,
borderBottomWidth: 1,
borderBottomColor: '#8CC63F',
borderRadius: 4,
},
inputPassword: {
marginTop: 30,
padding: 10,
width: 300,
height: 56,
backgroundColor: '#f5f5f5',
fontSize: 16,
borderBottomWidth: 1,
borderBottomColor: '#8CC63F',
borderRadius: 4,
},
button: {
width: 122,
height: 66,
marginTop: 60,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#20565C',
borderRadius: 4,
},
buttonText: {
fontSize: 16,
color: '#fff',
textTransform: 'uppercase',
fontWeight: 'bold',
},
});
更新下面这样的代码。
<TouchableOpacity style={styles.button} onPress={()=>this.navigateToHome}>
<Text style={styles.buttonText}>Entrar</Text>
</TouchableOpacity>
希望它为你工作。