react-navigation - navigating back to previous screen after opening app from deep link not working -
i'm trying implement deep linking in react native app i'm having trouble maintaining expected back-button behavior when closing out of view nested in stack navigator. root navigator stacknavigator has tabnavigator path 'customer'. inside tab navigator there 4 tabs, 1 of has path 'order-now' screen being stacknavigator. ordernow stack has 3 child screens this:
const ordernowtab = stacknavigator({ root: { screen: storesscreen, path: 'show-stores' }, menu: { screen: storeitemsscreen, path: 'show-stores/:store_id'}, item: { screen: itemdetailsscreen, path: 'show-stores/:store_id/:item_id'} });
when follow deep linking guides running adb shell start -w -a android.intent.action.view -d "mychat://mychat/customer/order-now/show-stores/some_store_id/some_item_id" com.sampleapp
taken item details screen expected, when press arrow button within navigation header, app appears close screen , land on exact copy of 1 closed (item details). difference new screen doesn't have arrow button within header, giving me impression it's @ root of stack navigator when shouldn't (pressing should have brought me storeitemsscreen
).
why happen , how can storeitemsscreen
show after pressing button (either navigation header or physical android button) instead?
my package.json
file's dependencies section looks this:
"dependencies": { "react": "16.0.0-alpha.12", "react-native": "0.48.1", "react-navigation": "^1.0.0-beta.11" },
and here file's i'm using:
// src/app.js import react 'react'; import { appregistry, platform } 'react-native'; import { stacknavigator } 'react-navigation'; const sampleapp = stacknavigator({ home: { screen: require('./homescreen') }, customertabbar: { screen: require('./customer/customernavigator'), path: 'customer' }, chat: { screen: require('./customer/chatscreen'), path: 'chat/:user' }, }, {mode: "modal", headermode: "none"}); const prefix = platform.os == 'android' ? 'mychat://mychat/' : 'mychat://' const mainapp = () => <sampleapp uriprefix={prefix} /> appregistry.registercomponent('sampleapp', () => mainapp);
src/homescreen.js
:
import react 'react' import {text, button, view} 'react-native' class homescreen extends react.component { static navigationoptions = { title: 'welcome', }; render() { const { navigate } = this.props.navigation; return ( <view> <text>hello, chat app!</text> <button onpress={() => navigate('chat', { user: 'lucy' })} title="chat lucy" /> </view> ); } } module.exports = homescreen
customernavigator.js
:
import { tabnavigator } 'react-navigation'; const customernavigator = tabnavigator({ ordernow: { screen: require('./ordernowtab'), path: 'order-now' }, futureorders: { screen: require('./futureordersscreen'), path: 'future-order' }, bag: { screen: require('./bagscreen'), path: 'bag-tab' }, yourorders: { screen: require('./yourordersscreen'), path: 'your-orders' }, account: { screen: require('./accountscreen'), path: 'your-account' }, },{ tabbaroptions: { activetintcolor: '#000', } }) module.exports = customernavigator
ordernowtab.js
:
import react 'react'; import {text} 'react-native'; import { stacknavigator } 'react-navigation'; class storesscreen extends react.component { static navigationoptions = ({ navigation }) => ({ title: `stores`, }); render() { return ( <text>list of stores</text> ) } } class storeitemsscreen extends react.component { static navigationoptions = ({ navigation }) => ({ title: `store items`, }); render() { const { params } = this.props.navigation.state; return ( <text>store items screen store id {params.store_id}</text> ) } } class itemdetailsscreen extends react.component { static navigationoptions = ({navigation}) => ({ title: 'item details' }) render() { const { params } = this.props.navigation.state return ( <text>item details screen item id {params.item_id} , store id {params.store_id}</text> ) } } const ordernowtab = stacknavigator({ root: { screen: storesscreen, path: 'show-stores' }, menu: { screen: storeitemsscreen, path: 'show-stores/:store_id'}, item: { screen: itemdetailsscreen, path: 'show-stores/:store_id/:item_id'} }); module.exports = ordernowtab
Comments
Post a Comment