在移动设备中运行以下react-native代码后,显示错误。错误是:
“ TypeError:null不是对象(正在评估'_RNGestureHandlerModule.default.Direction')”。
我已经安装了运行该应用程序所需的所有库。 请帮助我解决我的错误。代码是:
App.js
import 'react-native-gesture-handler';
import * as React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import HomeScreen from './modules/HomeScreen';
import SecondScreen from './modules/SecondScreen';
const Stack = createStackNavigator();
function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Second" component={SecondScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
export default App;
HomeScreen.js:
import 'react-native-gesture-handler';
import * as React from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';
function HomeScreen({ navigation }) {
navigateToScreen=()=>{
navigation.navigate('Second');
}
return (
<View style={styles.MainContainer}>
<Text style={styles.text}> Home Screen </Text>
<Button onPress={this.navigateToScreen} title="Navigate To Second Screen" />
</View>
);
}
const styles = StyleSheet.create({
MainContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
text: {
textAlign: 'center',
margin: 18,
fontSize: 24,
fontWeight: "200",
},
});
export default HomeScreen ;
SecondScreen.js
import 'react-native-gesture-handler';
import * as React from 'react';
import { StyleSheet, Text, View } from 'react-native';
function SecondScreen() {
return (
<View style={styles.MainContainer}>
<Text style={styles.text}> Second Screen </Text>
</View>
);
}
const styles = StyleSheet.create({
MainContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
text: {
textAlign: 'center',
fontSize: 24,
fontWeight: "200",
},
});
export default SecondScreen;