2017-05-06 11 views
1

私の問題は、BountyDetailsS​​creenからLoyaltyScreenへnavigateBack()を呼びたいのですが、navigateBack()関数呼び出しは何の動作も引き起こさないということです。私は機能をログインすると、それは言う:私は気付かReact Native/Shoutem:navigateBack()not working

enter image description here

唯一のことは、navigationStackが空であること、です。私がnavigateTo機能を使って同じことをしているとき、それは動作していますが、それから私はうんざりしたナビゲーションスタックを持っています。

私のLoyaltyScreen.jsではListViewを表示しています。これはRN ListView(shoutemからインポートされていない)です。

LoyaltyScreen.js

renderRow(bounty) { 
    return (
    <ListBountiesView 
     key={bounty.id} 
     bounty={bounty} 
     onDetailPress={this.openDetailsScreen} 
     redeemBounty={this.redeemBounty} 
    /> 
); 
} 

ListBountiesView.js

ListBountiesViewは、各リストビューの行をレンダリングし、行をクリックした際に詳細画面を開きます。 BountyDetailsS​​creenで

render() { 
const { bounty } = this.props; 

return (  
    <TouchableOpacity onPress={this.onDetailPress}>   
    {bounty.type == 0 ? this.renderInShopBounty() : this.renderContestBounty()} 
    <Divider styleName="line" /> 
    </TouchableOpacity> 
); 
} 

BountyDetailsS​​creen.js

私は、詳細情報を表示し、私はボタンを押したときに忠誠画面に)(navigateBackしたいと思います。

<Button styleName="full-width" onPress={() => this.onRedeemClick()}> 
    <Icon name="add-to-cart" /> 
    <Text>Einlösen</Text> 
</Button> 

onRedeemClick() { 
    const { bounty, onRedeemPress } = this.props; 
    onRedeemPress(bounty); 
    navigateBack(); 
} 

答えて

1

navigateBackはアクションクリエイターです。あなたはそれを小道具にマップし、小道具ののredeemClick機能でそれを読む必要があります。インポートされたアクションクリエータを実行するだけで、Reduxに接続されていないので何もしません。ここで

はあなたの例では、小道具にマッピングです:ここでは

export default connect(mapStateToProps, { navigateBack })(SomeScreen)); 

は、あなたがそれを使用する方法は次のとおりです。

const { navigateBack } = this.props; 

navigateBack(); 
+0

ありがとう!私は 'navigateBack()'関数を小道具から読むのを忘れていました –

1

私はそのairmihaの答えは、あなたが探しているものですが、私見ることができますちょうどそれに追加したい。

hasHistoryを使用して、@shoutem/uiNavigationBar(使用している場合)にnavigateBack()を使用する単純な戻るボタンを設定することもできます。

<NavigationBar 
    styleName="no-border" 
    hasHistory 
    title="The Orange Tabbies" 
    share={{ 
    link: 'http://the-orange-tabbies.org', 
    text: 'I was underwhelmed by The Orange Tabbies, but then I looked at that 
      sweet, sweet back button on the Nav Bar. 
      #MakeNavBarsGreatAgain', 
    title: 'Nevermind the cats, check the Nav Bar!', 
    }} 
/> 

あなたはNavigationBarコンポーネントhereでより多くの例を見つけることができます。