当前位置:网站首页>Navagation navigation
Navagation navigation
2022-06-23 09:36:00 【conanma】
1. preparation
To be in React-Native Using navigation in , You need to import the corresponding library in the project in advance , React-Native Several existing navigation components in : React Navigation 、 NavigatorIOS 、Navigator, If you're new to it , So direct choice React Navigation Just fine . If you only aim at iOS Platform development , And want to be consistent with the native appearance of the system , Then you can choose NavigatorIOS . and Navigator This is the earliest component , Has been gradually React Navigation replace , But it has been practiced for a long time , More stable . Now the more widely used cutting general is React Navigation, This article will explain the use of this component in detail .
- Enter the project through the terminal , Then add react-navigation.
- Then introduce... Into the project
React Navigation.
import { createStackNavigator } from 'react-navigation';2. Import the controls used
In this project, because it is navigation , So it involves View、Button、Alert etc. .
import {
StyleSheet,
View,
Text,
Button,
Alert,
} from 'react-native';3. Create two pages to jump to
Here to create Home and Details Two pages , The home page is Home page , Used to Home Page can jump to Details page , stay Details You can return or continue to jump . When creating a page , You can set the navigation of the current page , The corresponding title can be set 、 typeface 、 The font color 、 Background color, etc .
- Home
class HomeNav extends React.Component {
static navigationOptions = {
title: 'Home',
headerStyle: {
backgroundColor: '#f4511e'
},
headerTintColoe: '#fff',
headerTitleStyle: {
fontSize: 30,
color: 'blue',
fontWeight: 'bold'
}
}
render() {
return(
<View style={styles.homeStyle}>
<Text style = {styles.homeTextStyle}>Home Screen</Text>
<Button
style = {styles.homeBtnStyle}
title = "Go to detail"
onPress = {() => this.props.navigation.navigate('Details')}
/>
</View>
)
}
}- Detail
class DetailsScreen extends React.Component {
constructor(props){
super(props)
this.state = {}
}
static navigationOptions = {
title: 'Details',
headerStyle: {
backgroundColor: 'red'
}
}
render() {
return(
<View style = {styles.detailStyle}>
<Text style={styles.detailsTextStyle}>Detail Screen</Text>
<Button
title = "Go to details again"
onPress = { () => this.props.navigation.push('Details')}
/>
<Button
title = "Go to home"
onPress = { () => this.props.navigation.navigate('Home')}
/>
<Button
title = "Go back"
onPress = {
() => {
Alert.alert(
`Title`,
'are you sure go back?',
[
{text: ' determine ', onPress: () => this.props.navigation.goBack()},
{text: ' Cancel ', onPress: () => console.log('Cancel Pressed'), style: 'cancel'}
]
)
}
}
/>
</View>
)
}
}4. Declaration class
To use a jump between classes , You need to declare the corresponding class first
const RootStack = createStackNavigator(
{
Home: HomeNav,
Details: DetailsScreen
}
)5. Call navigation
React Native Need to be in return Return the corresponding component in , Return to the navigation controller .
export default class App extends Component {
render(){
return(<RootStack />)
}
} Come here , be based on React Navigation The navigation controller is complete
边栏推荐
猜你喜欢
随机推荐
Redis learning notes - geographic information location (GEO)
Aiming at the overseas pet market, "grasshand" has developed an intelligent tracking product independent of mobile phones | early project
One of the 12 balls is different from the others. Provide a balance and find it three times
2022 gdevops global agile operation and maintenance summit - essence playback of Guangzhou station (with PPT download)
Go 字符串比较
Playing with nanopi 2 bare metal tutorial programming-01 lighting user led difficulty analysis
Difference between global shutter and roller shutter
披萨订购设计----简单工厂模式
AI: the Elephant in Room
Redis学习笔记—Redis与Lua
Pizza ordering design - simple factory model
S5P4418裸机编程的实现(替换2ndboot)
[GXYCTF2019]BabyUpload
[plugin:vite:import-analysis]Failed to resolve import “@/“ from ““.Does the file exist
[网鼎杯 2020 青龙组]AreUSerialz
Qiming Xingchen Huadian big data quantum security innovation laboratory was unveiled and two black technology products were released
Chain representation and implementation of linklist ---- linear structure
[wangdingbei 2020 Qinglong formation]areuserialz
swagger UI :%E2%80%8B
三层架构与SSM之间的对应关系
![[SUCTF 2019]CheckIn](/img/0e/75bb14e7a3e55ddc5126581a663bfb.png)





