如何使用Flow定义用于反应导航的道具

Fin*_*ish 3 javascript reactjs flowtype react-native react-navigation

我正在开发一个简单的React Native App,并决定使用用户react-navigation。我还决定使用Flow进行静态类型检查。我不知道的是如何使用Flow定义与导航相关的道具。

例如,我将App.js定义为使用StackNavigator,如下所示:

import StackNavigator from 'react-navigation';
import Main from './app/containers/Main';

const App = StackNavigator({
  Main: { screen: Main },
});

export default App;
Run Code Online (Sandbox Code Playgroud)

然后我定义了Main类,但是我不知道如何在我的道具中引用react-navigation:

// @flow

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

type Props = {
  navigate: ????
};

type State = {};

class Main extends Component<Props, State> {
   ...
}
Run Code Online (Sandbox Code Playgroud)

use*_*015 7

根据https://github.com/react-navigation/react-navigation/issues/3643

import { NavigationState, NavigationScreenProp } from 'react-navigation';

type Props = {
  navigation: NavigationScreenProp<NavigationState>
};
Run Code Online (Sandbox Code Playgroud)


Muk*_*oni 1

react-navigation有一个流文件。也许您可以从那里导入或只是复制粘贴

https://github.com/react-navigation/react-navigation/blob/master/flow/react-navigation.js#L72