本文将介绍Reactnativelogin,signupandnavigation风格一的详细情况,特别是关于reactnativenavigation官网的相关信息。我们将通过案例分析、数据研究等多
本文将介绍React native login, signup and navigation 风格一的详细情况,特别是关于react native navigation官网的相关信息。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些关于@ react-navigation / native和@ react-navigation / stack读取整个堆栈、@react-navigation/native 和 @react-navigation/stack 应该是我模块的 peerDependencies 或依赖项吗?、javascript – undefined不是函数(评估’_reactNavigation.NavigationActions.reset’)、React Native 'TypeError: undefined is not an object (evaluating 'navigation.navigate')'的知识。
本文目录一览:- React native login, signup and navigation 风格一(react native navigation官网)
- @ react-navigation / native和@ react-navigation / stack读取整个堆栈
- @react-navigation/native 和 @react-navigation/stack 应该是我模块的 peerDependencies 或依赖项吗?
- javascript – undefined不是函数(评估’_reactNavigation.NavigationActions.reset’)
- React Native 'TypeError: undefined is not an object (evaluating 'navigation.navigate')'
React native login, signup and navigation 风格一(react native navigation官网)
点击打开链接 favicon.png
src/components/Form.js
import React,{ Component } from 'react'; import { StyleSheet,Text,View,TextInput,TouchableOpacity } from 'react-native'; export default class Form extends Component<{}> { render() { return ( <View style={styles.container}> <TextInput style={styles.inputBox} underlineColorAndroid='rgba(0,0)' placeholder='Email' placeholderTextColor='#ffffff' selectionColor="#fff" keyboardType="email-address" onSubmitEditing={()=> this.password.focus()} /> <TextInput style={styles.inputBox} underlineColorAndroid='rgba(0,0)' placeholder='Password' secureTextEntry={true} placeholderTextColor='#ffffff' ref={(input) => this.password = input} /> <TouchableOpacity style={styles.button}> <Text style={styles.buttonText}> {this.props.type}</Text> </TouchableOpacity> </View> ); } } const styles = StyleSheet.create({ container: { flexGrow: 1,alignItems: 'center',justifyContent: 'center' },inputBox: { width:300,backgroundColor:'rgba(255,255,0.2)',borderRadius:25,paddingHorizontal:16,fontSize:16,color:'#ffffff',marginVertical:10 },button: { width:300,backgroundColor:'#1c313a',marginVertical:10,paddingVertical:12 },buttonText: { fontSize:16,fontWeight:'500',color: '#ffffff',textAlign:'center' } });
src/components/logo.js
import React,Image } from 'react-native'; export default class logo extends Component<{}> { render() { return ( <View style={styles.container}> <Image style={{width: 50,height: 50}} source={require('../assets/favicon.png')} /> <Text style={styles.logoText}>Wecome to my app</Text> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1,justifyContent: 'flex-end',alignItems: 'center' },logoText: { marginVertical:15,fontSize:18,color:'rgba(255,0.7)' } });
src/pages/Login.js
import React,StatusBar,TouchableOpacity } from 'react-native'; import logo from '../components/logo'; import Form from '../components/Form'; import {Actions} from 'react-native-router-flux'; export default class Login extends Component<{}> { signup(){ Actions.signup(); } render() { return ( <View style={styles.container}> <logo/> <Form type="Login"/> <View style={styles.signupTextCont}> <Text style={styles.signupText}>Don't have an account yet?</Text> <TouchableOpacity onPress={this.signup}> <Text style={styles.signupButton}>Signup</Text> </TouchableOpacity> </View> </View> ); } } const styles = StyleSheet.create({ container: { backgroundColor: '#455a64',flex: 1,signupTextCont: { flexGrow: 1,alignItems: 'flex-end',justifyContent: 'center',paddingVertical:16,flexDirection:'row' },signupText: { color:'rgba(255,0.6)',fontSize:16 },signupButton: { fontSize:16,fontWeight:'500' } });
src/pages/Signup.js
import React,TouchableOpacity } from 'react-native'; import logo from '../components/logo'; import Form from '../components/Form'; import {Actions} from 'react-native-router-flux'; export default class Signup extends Component<{}> { goBack() { Actions.pop(); } render() { return ( <View style={styles.container}> <logo/> <Form type="Signup"/> <View style={styles.signupTextCont}> <Text style={styles.signupText}>Already have an account </Text> <TouchableOpacity onPress={this.goBack}> <Text style={styles.signupButton}>Sign in</Text> </TouchableOpacity> </View> </View> ); } } const styles = StyleSheet.create({ container: { backgroundColor: '#455a64',fontWeight:'500' } });
src/Routes.js
import React,{ Component } from 'react'; import {Router,Stack,Scene} from 'react-native-router-flux'; import Login from './pages/Login'; import Signup from './pages/Signup'; export default class Routes extends Component<{}> { render() { return ( <Router> <Stack key="root" hideNavBar={true}> <Scene key="login" component={Login} title="Login" initial={true}/> <Scene key="signup" component={Signup} title="Register"/> </Stack> </Router> ) } }
App.js
import React,StatusBar } from 'react-native'; import Routes from './src/Routes'; export default class App extends Component<{}> { render() { return ( <View style={styles.container}> <StatusBar backgroundColor="#1c313a" bar/> <Routes/> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1,} });
需要安装路由组件
myths-Mac:zigoo myth$ cd $HOME/zigoo && npm i react-native-router-flux --save> react-native-router-flux@4.0.0-beta.28 postinstall /Users/myth/zigoo/node_modules/react-native-router-flux> opencollective postinstall Thanks for installing react-native-router-flux Please consider donating to our open collective to help us maintain this package. Number of contributors: 214 Number of backers: 6 Annual budget: $460 Current balance: $460 Donate: https://opencollective.com/react-native-router-flux/donate+ react-native-router-flux@4.0.0-beta.28updated 1 package in 14.931smyths-Mac:zigoo myth$
@ react-navigation / native和@ react-navigation / stack读取整个堆栈
您可以使用如下所示的useNavigationState钩子来获取当前状态
https://reactnavigation.org/docs/use-navigation-state/
import {useNavigationState} from '@react-navigation/native';
const state = useNavigationState((state) => state);
alert(JSON.stringify(state.routes));
这将在路线中显示屏幕
@react-navigation/native 和 @react-navigation/stack 应该是我模块的 peerDependencies 或依赖项吗?
如何解决@react-navigation/native 和 @react-navigation/stack 应该是我模块的 peerDependencies 或依赖项吗??
我正在编写一个使用以下依赖项的模块:
{
"@react-native-community/masked-view": "^0.1.10","@react-navigation/native": "^5.9.4","@react-navigation/stack": "^5.14.4","@react-native-community/masked-view": "^0.1.10","env-cmd": "^10.1.0","firebase": "^8.4.1","react-native-gesture-handler": "^1.10.3","react-native-reanimated": "^2.1.0","react-native-safe-area-context": "^3.2.0","react-native-screens": "^3.1.1"
}
我知道存储单例状态的依赖项不应该在 dependencies
中,而应该在 devDependencies
和 peerDependencies
中。
我不认为 react-navigation 是一个单独的依赖项,我们可以创建导航的 ref。
可以在我的分布式模块 dependencies
中将这些依赖项用作 package.json
吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
javascript – undefined不是函数(评估’_reactNavigation.NavigationActions.reset’)
splashscreen代码如下:
import React from "react"; import { Animated,Easing } from "react-native"; import LottieView from "lottie-react-native"; import { NavigationActions } from "react-navigation"; export default class SplashScreen extends React.Component { static navigationoptions = { header: null }; constructor() { super(); this.state = { progress: new Animated.Value(0),} } componentDidMount() { setTimeout(() => { this.navigatetoWalkthrough() },3500); Animated.timing(this.state.progress,{ tovalue: 1,duration: 3000,easing: Easing.linear,}).start(); } navigatetoWalkthrough = () => { const navigateAction = NavigationActions.reset({ index: 0,actions: [NavigationActions.navigate({ routeName: "Walkthrough" })],}); this.props.navigation.dispatch(navigateAction); } render() { return( <LottieView source={require("../assets/splash/SplashScreenAnimation.json")} progress={this.state.progress} /> ); } }
我运行应用程序后出现错误:
undefined is not a function (evaluating'_reactNavigation.NavigationActions.reset')
Main.js文件如下所示:
import React from "react"; import { View,Text } from "react-native"; import { createStackNavigator } from "react-navigation"; import SplashScreen from "./screens/SplashScreen"; import Walkthrough from "./screens/Walkthrough"; const Routes = createStackNavigator({ Home: { screen: SplashScreen },Walkthrough: { screen: Walkthrough } }); export default class Main extends React.Component { render() { return <Routes />; } }
任何帮助/反馈?
解决方法
StackActions
.
StackActions
is an object containing methods for generating actions
specific to stack-based navigators. Its methods expand upon the
actions available in NavigationActions.The following actions are supported:
Reset – Replace current state with a new state
Replace – Replace a route at a given key with another route
Push – Add a route on the top of the stack,and navigate forward to it
Pop – Navigate back to prevIoUs routes
PopToTop – Navigate to the top route of the stack,dismissing all other routes
React Native 'TypeError: undefined is not an object (evaluating 'navigation.navigate')'
如何解决React Native ''TypeError: undefined is not an object (evaluating ''navigation.navigate'')''?
这是我的第一个 React Native 项目,我被卡住了,需要帮助。以下是我的代码。我想做的是跟随。
- 登陆屏幕将显示所有项目的列表和底部标签菜单。
- 一旦有人点击项目,就会打开项目详情页面。
App.Js
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React from ''react'';
import App from ''./src'';
import { Provider as PaperProvider } from ''react-native-paper'';
export default App;
src/navigations/index.js
import * as React from ''react'';
import { Text,View,StyleSheet,FlatList,SafeAreaView } from ''react-native'';
import { List,Button,TextInput,FAB,Avatar,Card,Title,Paragraph } from ''react-native-paper'';
import { NavigationContainer } from ''@react-navigation/native'';
import { createBottomTabNavigator } from ''@react-navigation/bottom-tabs'';
import { createStackNavigator} from ''@react-navigation/stack'';
import ProjectList from ''_scenes/projects'';
import NewProject from ''_scenes/projects/addproject'';
import ProjectDetail from ''_scenes/projects/projectdetails'';
import Settings from ''_scenes/settings'';
const Tab = createBottomTabNavigator();
const Projects = ({ navigation }) => (
<ProjectList navigation={navigation} />
);
function SettingsScreen( { navigation} ) {
return (
<Settings />
);
}
export default function App() {
return (
<NavigationContainer>
<Tab.Navigator initialRouteName="HomeScreen">
<Tab.Screen name="Home" component={Projects} options={{ tabBarBadge: 3 }}/>
<Tab.Screen name="Settings" component={SettingsScreen} options={{ tabBarBadge: 2 }}/>
</Tab.Navigator>
</NavigationContainer>
);
}