0 react-native react-native-ios react-navigation
我发现各种类似的问题都有不同的问题和解决方案。在大多数情况下,似乎项目架构是罪魁祸首。我无法弄清楚我的。我想导航到Signup screen点击获取 OTP 按钮PhoneSignup screen。
电话注册表格.js
export default class PhoneSignupForm extends Component {
render() {
return (
<View >
<TouchableOpacity
onPress={ () => this.props.navigation.navigate('Signup') }
>
<Text>
Get OTP
</Text>
</ TouchableOpacity>
</View>
);
}
}
Run Code Online (Sandbox Code Playgroud)
电话注册.js
import PhoneSignupForm from './PhoneSignupForm';
export default class PhoneSignup extends Component {
render() {
return (
<View style = {styles.container}>
<View style = {styles.logoContainer}>
<Image
style = {styles.logo}
source = {require('../../icons/hp.png') }
/>
<Text style = {styles.title}>Hewlett-Packard</Text>
</View>
<View style = {styles.formContainer} >
// Using PhoneSignupForm component here
<PhoneSignupForm />
</View>
</View>
);
}
}
Run Code Online (Sandbox Code Playgroud)
主文件
import PhoneSignup from '../scenes/phoneSignup';
import Signup from '../scenes/signup';
import { StackNavigator } from 'react-navigation';
const AppNavigation = StackNavigator(
{
PhoneSignup: {screen: PhoneSignup},
Signup: {screen: Signup}
}
);
export default AppNavigation;
Run Code Online (Sandbox Code Playgroud)
应用程序.js
import React, { Component } from 'react';
import {KeyboardAvoidingView} from 'react-native';
import PhoneSignup from './src/scenes/phoneSignup';
import Signup from './src/scenes/signup';
import AppNavigation from './src/routes/main';
const App = () => ( {
render() {
return (
<KeyboardAvoidingView behavior = 'padding' >
<AppNavigation />
</KeyboardAvoidingView>
);
}
})
export default App;
Run Code Online (Sandbox Code Playgroud)
最后index.js
import { AppRegistry } from 'react-native';
import App from './App';
AppRegistry.registerComponent('DamReact', () => App);
Run Code Online (Sandbox Code Playgroud)
@bennygenel 正确地指出了这一点。您需要将导航道具从 Signup 组件传递给 FormSignup 组件。干得好。
export default class PhoneSignup extends Component {
render() {
const { navigation } = this.props;
return (
<View style = {styles.container}>
<View style = {styles.logoContainer}>
<Image
style = {styles.logo}
source = {require('../../icons/hp.png') }
/>
<Text style = {styles.title}>Hewlett-Packard</Text>
</View>
<View style = {styles.formContainer} >
<PhoneSignupForm navigation={navigation} />
</View>
</View>
);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9639 次 |
| 最近记录: |