【发布时间】:2019-01-05 12:16:40
【问题描述】:
在 React Native 中,我需要从一个屏幕导航到另一个屏幕。但我不明白这个概念。所以,我做了以下,
在 App.js 中
import React, {Component} from 'react';
import LinearGradient from 'react-native-linear-gradient';
import {StyleSheet, Text, Alert, View} from 'react-native';
import { Container, Header, Content, Button} from 'native-base';
import { createStackNavigator, createAppContainer } from 'react-navigation';
type Props = {};
export default class App extends Component<Props> {
ShowAlertDialog = () =>{
Alert.alert(
// This is Alert Dialog Title
'Lopels',
// This is Alert Dialog Message.
'Welcome to Lopels',
[
// First Text Button in Alert Dialog.
{text: 'Ask me later', onPress: () => console.log('Ask me later Button Clicked')},
// Second Cancel Button in Alert Dialog.
{text: 'Cancel', onPress: () => console.log('Cancel Button Pressed'), style: 'cancel'},
// Third OK Button in Alert Dialog
{text: 'OK', onPress: () => console.log('OK ButtonPressed')},
]
)
}
render() {
return (
<Container>
<LinearGradient colors={['#007991', '#78ffd6']} style={styles.linearGradient}>
<Text style={styles.logoText}>
Lopels
</Text>
<Text style={styles.tagText}>
The Complete Loyalty Platform
</Text>
<Button style={styles.button} onPress={this.ShowAlertDialog}>
<Text style={styles.buttonText}>Get Started</Text>
</Button>
</LinearGradient>
</Container>
);
}
}
const styles = StyleSheet.create({
linearGradient: {
flex: 1,
paddingLeft: 5,
paddingRight: 5,
},
logoText: {
fontSize: 50,
fontFamily: 'Graceland',
textAlign: 'center',
marginTop: 170,
color: '#ffffff',
backgroundColor: 'transparent',
},
tagText:{
fontSize:15,
letterSpacing: 3,
fontFamily:'Actor',
textAlign: 'center',
color: 'black',
backgroundColor: 'transparent',
},
button:{
marginLeft: '15%',
marginTop: '8%',
width:250,
borderRadius: 10,
backgroundColor:'#ffffff',
borderColor: "transparent",
},
buttonText:{
marginTop: '8%',
marginLeft: '35%',
fontFamily: 'Actor',
color: '#282828',
fontSize: 18,
}
});
其他屏幕的文件夹在文件夹./src/Login Screen/index.js中
单击 App.js 中的“开始”按钮后,我需要导航到登录屏幕
【问题讨论】:
标签: reactjs react-native navigation react-navigation