javascript - React-Navigation:按图像导航
问题描述
我正在尝试通过按SearchScreen.js
. 每个图像都指向不同的屏幕。我目前正在尝试从第一张图像导航到屏幕meo_sw.js
。但是,我不能这样做,我不明白为什么。这是代码SearchScreen.js
:
import React from 'react';
import { ScrollView, StyleSheet, TextInput, Text, View, Image, TouchableOpacity} from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
function SearchScreen() {
return (
<View style={styles.screen}>
<View style={styles.container}>
<TextInput style={styles.inputBox}
underlineColorAndroid='rgba(0,0,0,0)'
placeholder="Procura aqui"
placeholderTextColor = "black"
selectionColor="black"
keyboardType="default"/>
</View>
<View style={styles.teste}>
<Text style={styles.festivais}>Recomendados</Text>
<ScrollView horizontal={true} showsHorizontalScrollIndicator={false} style={styles.festivais_lista}>
<TouchableOpacity>
<Image source={require('../assets/images/meo_sudoeste.png')} style={styles.image} onPress={() => navigation.navigate('meo_sw')}/>
</TouchableOpacity>
<TouchableOpacity>
<Image source={require('../assets/images/vodafone_coura.png')} style={styles.image} onPress={() => {}}/>
</TouchableOpacity>
<TouchableOpacity>
<Image source={require('../assets/images/superbock_superrock.png')} style={styles.image} onPress={() => {}}/>
</TouchableOpacity>
<TouchableOpacity>
<Image source={require('../assets/images/nos_primavera.png')} style={styles.image} onPress={() => {}}/>
</TouchableOpacity>
<TouchableOpacity>
<Image source={require('../assets/images/rock_in_rio.png')} style={styles.image} onPress={() => {}}/>
</TouchableOpacity>
<TouchableOpacity>
<Image source={require('../assets/images/edp_cooljazz.png')} style={styles.image} onPress={() => {}}/>
</TouchableOpacity>
</ScrollView>
</View>
</View>
);
}
SearchScreen.navigationOptions = {
title: 'Procurar',
};
const styles = StyleSheet.create({
//I took this part off because it is useless for this especific question
});
export default SearchScreen;
这是屏幕“meo_sw.js”:
import React from 'react';
import {View, Text, TouchableOpacity, StyleSheet} from 'react-native';
const meo_sw = props => {
return(
<View style={styles.header}>
<Text style={styles.texto}>Meo Sudoeste</Text>
</View>
)
};
const styles=StyleSheet.create({
header:{
width:'100%',
height:90,
paddingTop:36,
backgroundColor: 'blue',
alignItems: 'center',
justifyContent: 'center'
},
texto:{
color:'white',
fontSize: 18
}
})
export default meo_sw;
请帮我
解决方案
我觉得可能有这些问题
首先通过
navigation
.function searchScreen({navigation})
然后组件中没有
onPress
可用的道具,<Image>
因此请使用onPress
on<TouchableOpacity>
。
推荐阅读
- c++ - 完美实现按位 NOT (~) 运算符(翻转位)
- vim - 如何通过vimscript获取第一个非空白字符列号
- php - 为什么下面的代码输出 2 而不是 1?
- angular - Angular8:formGroup中的内存泄漏
- woocommerce - 出问题了。我们将带您返回结帐,以便您再次尝试错误错误 paypal express checkout?
- visual-studio - 授予非域用户对本地 TFS-2018 的访问权限
- javascript - 在 onClick() 上显示新按钮;反应JS
- azure-active-directory - 使用 Microsoft Graph 通信 API 时出现未知错误
- php - 更新约会状态时表格不起作用
- css - PURE CSS 旋转立方体在面部暂停然后播放