Open brentvatne opened 6 years ago
The problem with using Linking.openURL
on Android is it'll ask you which app you want to open with. We should be able to navigate to a path without potentially kicking the user into a different app or causing confusion. Take this use case for example:
https://example.page.link
with applicationLinking.openURL('https://example.com/xxx')
https://example.com
with the applicationI think react-navigation should have a public API for navigating to a path
The problem with using
Linking.openURL
on Android is it'll ask you which app you want to open with. We should be able to navigate to a path without potentially kicking the user into a different app or causing confusion. Take this use case for example:
- User installs app
- User clicks dynamic link https://example.page.link
- Android prompts user to open links for
https://example.page.link
with application- User chooses to open link with application
- Application receives link unwraps it and now needs to navigate to the deep link https://example.com/xxx
- Uses
Linking.openURL('https://example.com/xxx')
- Android prompts user to open links for
https://example.com
with the application- User is very confused why they were asked twice to use application to open a single link
I think react-navigation should have a public API for navigating to a path
I think we can use applink
For example yourappname://items/123
So it won't ask user for choosing apps.
Indeed. What's the status here? We are using Branch.io for our links and I just finished upgrading to react-navigation 3.0. I'd like to switch to using the path based navigation for the branch links but this is not well documented. Can I just get a ref to the appContainer and ask it to navigate for me?
import { NavigationActions } from 'react-navigation';
let _navigator;
function setTopLevelNavigator(navigatorRef) {
_navigator = navigatorRef;
}
function navigate(routeName, params) {
try {
_navigator.dispatch(
NavigationActions.navigate({
routeName,
params,
})
);
} catch (error) {
console.log(error);
}
}
function navigateToPath(path, params) {
const action = _navigator
&& _navigator._navigation
&& _navigator._navigation.router
&& _navigator._navigation.router.getActionForPathAndParams(path);
if (action) {
if (action.action) {
if (action.action.action) {
_navigator.dispatch(action.action.action);
} else {
_navigator.dispatch(action.action);
}
} else {
_navigator.dispatch(action);
}
}
}
// add other navigation functions that you need and export them
export default {
navigate,
setTopLevelNavigator,
navigateToPath
};
navigateToPath('/profile') will take to Screen corresponding to path: 'profile'
Is there a public API for jumping to some path, like what happens when the app is opened by a deep link? would it just be
Linking.openURL
? https://github.com/react-navigation/react-navigation/blob/c72b44ce104e5fbeb67624c44b792eca82285119/src/createNavigationContainer.js#L75-L84