Open luisfcofv opened 7 years ago
Cmon...... if you're going to provide a 'react-native' library, then make sure the docs are updated for both platforms. Otherwise, mark it as [iOS Only]
@StuffWeDoCo The library works for both platforms, it's not iOS only. The docs are updated for both platforms. However, the example provided only shows iOS.
Feel free to send a pull request if you are feeling useful.
For anyone that lands here after some googeling, this seems to work. Based on the case you want to call test://lost-password
:
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTask"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter android:label="filter_react_native">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="test"
android:host="lost-password"/>
</intent-filter>
</activity>
The basic difference to https://developer.android.com/training/app-links/deep-linking is this line: android:launchMode="singleTask"
.
In my case I wrote a middleware for redux to then decide whether I want to open a route or not:
import _ from 'lodash';
import DeepLinking from 'react-native-deep-linking';
import { Linking } from 'react-native';
import Screens from '../../constants/Screens';
import { NavigationActions } from 'react-navigation';
import { REHYDRATE } from 'redux-persist';
DeepLinking.addScheme('test://');
const handleUrl = ({ url }) => {
Linking.canOpenURL(url).then((supported) => {
if (supported) {
DeepLinking.evaluateUrl(url);
}
});
};
Linking.addEventListener('url', handleUrl);
function deepLinkingMiddleware () {
return ({ dispatch, getState }) => next => action => {
if (action.type === REHYDRATE) {
DeepLinking.addRoute('/lost-password/:token', (response) => {
dispatch(NavigationActions.navigate({
params: {
token: response.token,
},
routeName: Screens.ResetPassword,
}));
});
}
return next(action);
};
}
export {
deepLinkingMiddleware,
};
To test this you can use this command:
adb shell am start -a android.intent.action.VIEW -d "test://lost-password/foo" de.your-package.id
Only iOS is working in the example provided.