警告: React.jsx: 类型无效 -- 期望是字符串(用于内置组件)或类/函数(用于复合组件),但实际为: undefined。你可能忘记了从定义组件的文件中导出组件,或者可能混淆了默认导入和命名导入。

作者: fahadsolangi创建于 2024年1月16日更新于 2024年1月16日

import React, { Component } from "react"; import { PermissionsAndroid, View, StyleSheet, Animated, Dimensions, AsyncStorage } from "react-native"; import { CommonActions } from '@react-navigation/native'; import { Constants } from '../common'; import utils from "../utils"; import DeviceInfo from 'react-native-device-info'; import { getUniqueId, getManufacturer } from 'react-native-device-info'; const { width } = Dimensions.get('window');

const resetLoginAction = CommonActions.reset({ index: 1, routes: [ { name: 'Home' }, ], }) const resetActionApp = CommonActions.reset({ index: 1, routes: [ { name: 'SignIn' }, ], }) let uniqueId = DeviceInfo.getUniqueId(); export default class Splash extends Component { constructor(props) { super(props); this.state = { ready: false, SlideInLeft: new Animated.Value(0), slideUpValue: new Animated.Value(0), fadeValue: new Animated.Value(0), } }

async componentDidMount() { this._start() setTimeout(() => { this._retrieveData() }, 3000); } _start = async () => { return Animated.parallel([ Animated.timing(this.state.SlideInLeft, { toValue: 1, duration: 500, useNativeDriver: true }), Animated.timing(this.state.fadeValue, { toValue: 1, duration: 500, useNativeDriver: true }), Animated.timing(this.state.slideUpValue, { toValue: 1, duration: 500, useNativeDriver: true }) ]).start(); };

_retrieveData = async () => { try { const value = await AsyncStorage.getItem('LoginDetails'); // console.log(value+"data get") if (value !== null) { if(JSON.parse(value).is_guest) { this.props.navigation.dispatch(resetLoginAction); } else { utils.setUserData(value); this.props.navigation.dispatch(resetLoginAction); } } else { this.props.navigation.dispatch(resetActionApp); } } catch (error) { console.log(error); // Error retrieving data } };

render() { let { slideUpValue, fadeValue, SlideInLeft } = this.state; return ( <Animated.Image source={Constants.Splash_bg} style={{ transform: [ { translateY: slideUpValue.interpolate({ inputRange: [0, 1], outputRange: [-200, 0] }) } ], flex: 1, width: width, resizeMode: 'contain', justifyContent: "center" }} />

);

} }

const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#FFF", alignItems: "center" }, item: {}, btn: { backgroundColor: "#480032", width: 100, height: 40, padding: 3, justifyContent: "center", borderRadius: 6, marginTop: …

内容来源: expo/create-react-native-app