当前位置:网站首页>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
边栏推荐
- Cesium加载正射影像方案
- Redis learning notes - data type: ordered set (Zset)
- #gStore-weekly | gStore源码解析(四):安全机制之黑白名单配置解析
- [geek challenge 2019] hardsql
- Implementation of s5p4418 bare metal programming (replace 2ndboot)
- [MRCTF2020]Ez_ bypass
- Redis学习笔记—数据类型:哈希(hash)
- Redis学习笔记—遍历键
- Redis学习笔记—数据类型:字符串(string)
- Redis学习笔记—数据类型:有序集合(zset)
猜你喜欢

Web -- Information Disclosure

Implementation of s5p4418 bare metal programming (replace 2ndboot)
![[plugin:vite:import-analysis]Failed to resolve import “@/“ from ““.Does the file exist](/img/1f/dde52dc63de58d67f51161e318a9fb.png)
[plugin:vite:import-analysis]Failed to resolve import “@/“ from ““.Does the file exist

Pizza ordering design - simple factory model

Jog sport mode

Gesture recognition based on mediapipe

xml相关面试题

Qiming Xingchen Huadian big data quantum security innovation laboratory was unveiled and two black technology products were released
Redis学习笔记—发布订阅
【NanoPi2试用体验】裸机第一步
随机推荐
给RepVGG填坑?其实是RepVGG2的RepOptimizer开源
Redis学习笔记—数据类型:集合(set)
Playing with nanopi 2 bare metal tutorial programming-01 lighting user led difficulty analysis
启明星辰华典大数据量子安全创新实验室揭牌,发布两款黑科技产品
Three methods to find the limit of univariate function -- lobida's rule and Taylor's formula
12个球,有一个与其他不一样,提供一个天平,三次找出来
How should junior programmers who enter a small company improve themselves?
Cesium加载正射影像方案
UEFI learning 3.6 - ACPI table on ARM QEMU
ICLR 2022 | 视频中的动态卷积TAdaConv以及高效的卷积视频理解模型TAdaConvNeXt
#gStore-weekly | gStore源码解析(四):安全机制之黑白名单配置解析
RBtree
Ionic5 form input box and radio button
学习SCI论文绘制技巧(F)
UEFI 学习3.6 - ARM QEMU上的ACPI表
Go 字符串比较
map的下标操作符
ARM处理器与51单片机程序编写的区别
全局快门和卷帘快门的区别
Redis学习笔记—Redis与Lua