【问题标题】:React-native splash screen and react-navigationReact-native 闪屏和 react-navigation
【发布时间】:2017-06-01 20:48:35
【问题描述】:

我正在尝试使用上面引用的库之一,react-native-splash-screen 和 react-navigation。我明白了

。

代码如下:

index.android.js

import { AppRegistry } from 'react-native';
import App from './app/index';

AppRegistry.registerComponent('RecallNotes', () => App);

index.js

import React, { Component } from 'react';
import Root from 'config/router';
import { 
  View,
} from 'react-native';
import SplashScreen from 'react-native-smart-splash-screen';


export default class App extends Component {
    componentDidMount () {
     //SplashScreen.close(SplashScreen.animationType.scale, 850, 500)
        SplashScreen.close({
            animationType: SplashScreen.animationType.scale,
            duration: 850,
            delay: 500,
        })
    }

    render() {
        return <Root />;
    }
}

路由器.js

import React from 'react';
import { StackNavigator } from 'react-navigation';

import DeckView from 'screens/deckview';

export const Root = StackNavigator({
    Home: {
        screen: DeckView
    },
},{
    mode: 'modal',
    headerMode: 'none',
});

deckview.js

import React, { Component } from 'react';
import { 
  View, 
  Text
} from 'react-native';

 /*
 *  DeckView class
 *  This is the component of the deck image
 */
export default class DeckView extends Component{

    render(){
      return(
        <View> 
            <Text>Welcome to React Native!</Text>
        </View>
      );
    }
}

我的问题是:我是否必须在我的应用程序的整个导航中使用 StackNavigator,或者我可以在修复此代码后保留上面的代码吗?谢谢。

【问题讨论】:

    标签: javascript android react-native react-navigation


    【解决方案1】:

    在 index.js 中,更改:

    import Root from 'config/router';

    到:

    import { Root } from 'config/router';

    因为您没有从 router.js 导出默认值

    【讨论】:

    • 谢谢。因此,如果我没有从项目中的任何文件中导入默认值,我是否也必须这样做?再次感谢您的帮助。
    • 是的,我记得的方式是,如果它只是一个export,那么它们可能有任意数量,所以你必须使用import { myComponent } 来指定你想要的。如果您使用的是export default,那么导入预计只有一个(尽管仍然可以有多个),那么您只需要import myComponent。至于你需要哪个库等,请查看文档。
    猜你喜欢
    • 2022-10-25
    • 2019-06-25
    • 1970-01-01
    • 1970-01-01
    • 2022-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-28
    相关资源
    最近更新 更多