2017-11-20 6 views
0

私はStackNavigatorに割り当てられていないコンポーネントがあります。しかし、私はまだnavigateメソッドをreact-navigationから使いたいと思っています。それは可能ですか?例えばどこでもnavigateメソッドを使用する

manage.js

export const mainStack = StackNavigator({ 
    Home: { screen: HomeScreen}, 
    Content: { screen: ContentScreen }, 
}); 

OtherContent.js

class OtherContent extends React.Component { 
    constructor(props) { 
     super(props); 
    } 

    _MoveToScreen =() =>{ 
     //try to open ContentScreen from here 
     const { navigate } = this.props.navigation; 
     navigate('ContentScreen'); 
    } 

} 

私はOtherContentコンポーネントでnavigateを使用したいです。コンポーネントにnavigation小道具を渡すにはどうすればよいですか。

答えて

0

使用の再来と私は

0

あなたが小道具として親からnavigationを渡すか、react-navigation

例1でwithNavigation高次コンポーネントを使用することができると思うその後、uはそこからそれを呼び出すことができ、状態にそれを置く:

<OtherContent navigation={this.props.navigation} /> 

例2:

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

class OtherContent extends React.Component { 
    constructor(props) { 
     super(props); 
    } 

    _MoveToScreen =() =>{ 
     //try to open ContentScreen from here 
     const { navigate } = this.props.navigation; 
     navigate('ContentScreen'); 
    } 
    // ... 
} 

const OtherContentWithNavigation = withNavigation(OtherContent); 

;

関連する問題