[英]How to open a component from a function react native
<View style = {styles.container}>
<TouchableOpacity style={styles.btn}
onPress={() => this.props.navigation.navigate('AddCustomer') }>
<Text style={styles.plus}>+</Text>
</TouchableOpacity>
</View>
</List>
I want to open a component using the on press function, but I am getting no response when I am using this.props.navigation.navigate('AddCustomer') ? 我想使用按一下功能打开一个组件,但是使用this.props.navigation.navigate('AddCustomer')时却没有任何反应?
You can look at my code( https://github.com/dakshbhardwaj/Swipe/blob/master/components/Customers.js ) 你可以看一下我的代码( https://github.com/dakshbhardwaj/Swipe/blob/master/components/Customers.js )
I am new to the react native. 我是React Native的新手。
Can you help me ? 你能帮助我吗 ?
AddCustomer
screen is not part of your navigator. AddCustomer
屏幕不是导航器的一部分。 You created a StackNavigator
and added it to App
Component but you are not using that App component anywhere in you app. 您创建了
StackNavigator
并将其添加到App
Component中,但是您并未在应用程序中的任何位置使用该App组件。
I'm not sure what sort of navigation do you want to create but one option is creating something like below. 我不确定您要创建哪种导航,但是一种选择是创建如下所示的内容。 Add your customer related all screens to the
StackNavigator
and add that navigator as a screen to the TabNavigator
. 将与客户相关的所有屏幕添加到
StackNavigator
,并将该导航器作为屏幕添加到TabNavigator
。
export const CustomerStack = createStackNavigator(
{
Customers:{
screen:Customers,
},
AddCustomer:{
screen:AddCustomers
}
}
);
export default createBottomTabNavigator({
Dashboard:{
// ...
},
Customers:{
screen: CustomerStack,
navigationOptions:{
tabBarLabel:'Customers',
tabBarIcon:({tintColor}) => (
<Icon name ="ios-people-outline" color =
{tintColor} size = {24} />
)
}
},
Invoice:{
// ...
},
TimeTracker:{
// ...
},
More:{
// ...
}
},{
tabBarOptions:{
// ...
}
})
PS: On your next question please create a Minimal, Complete, and Verifiable example and add it to your question. PS:关于下一个问题,请创建一个最小,完整和可验证的示例 ,并将其添加到您的问题中。 Digging through a project and trying to debug it is a time consuming thing and this might result for you to not get an answer.
挖掘项目并尝试对其进行调试是一件很耗时的事情,这可能会导致您无法获得答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.