TouchableOpacity可在Android模拟器和手机上使用,但是当我生成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>
);
}
波纹管样式
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',
},
});
答案 0 :(得分:0)
更新以下代码,如下所示:
<TouchableOpacity style={styles.button} onPress={()=>this.navigateToHome}>
<Text style={styles.buttonText}>Entrar</Text>
</TouchableOpacity>
希望它对您有用。