From 7d962ca55177b1ec29f5ab177925a54a93092bec Mon Sep 17 00:00:00 2001 From: Arln Date: Wed, 2 Sep 2020 13:50:28 +0200 Subject: [PATCH] Implement deep-linking (#112) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Minor POC to showcase deep-linking abilities through the boilerplate * deep linking ios and refactor Co-authored-by: rmaniyar@ownsourcing.com Co-authored-by: DOLLE Co-authored-by: Aurélien Mutin --- App/Containers/DeepLinking/DeepLinkingScreen.js | 16 ++++++++++++++++ App/Containers/Root/RootScreen.js | 4 ++++ App/Navigators/AppNavigator.js | 9 ++++++++- android/app/src/main/AndroidManifest.xml | 9 ++++++++- ios/Boilerplate/AppDelegate.m | 8 ++++++++ ios/Boilerplate/Info.plist | 15 ++++++++++++++- ios/Podfile.lock | 4 ++-- 7 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 App/Containers/DeepLinking/DeepLinkingScreen.js diff --git a/App/Containers/DeepLinking/DeepLinkingScreen.js b/App/Containers/DeepLinking/DeepLinkingScreen.js new file mode 100644 index 000000000..aa7ec8c2c --- /dev/null +++ b/App/Containers/DeepLinking/DeepLinkingScreen.js @@ -0,0 +1,16 @@ +import React from 'react' +import { Text, View } from 'react-native' +import { Helpers, Metrics } from 'App/Theme' + +/** + * This is an example of a container component with a deep link. + */ +const DeepLinkingScreen = () => ( + + + This is deep linking example screen which can be accessed using boilerplate://deeplink scheme! + + +) + +export default DeepLinkingScreen diff --git a/App/Containers/Root/RootScreen.js b/App/Containers/Root/RootScreen.js index 4f083e064..253331109 100644 --- a/App/Containers/Root/RootScreen.js +++ b/App/Containers/Root/RootScreen.js @@ -7,6 +7,9 @@ import { Helpers } from 'App/Theme' import { useDispatch } from 'react-redux' const RootScreen = () => { + // Deep linking prefix + const prefix = 'boilerplate://'; + const dispatch = useDispatch() useEffect(() => { @@ -20,6 +23,7 @@ const RootScreen = () => { ref={(navigatorRef) => { NavigationService.setTopLevelNavigator(navigatorRef) }} + uriPrefix={prefix} /> ) diff --git a/App/Navigators/AppNavigator.js b/App/Navigators/AppNavigator.js index 3e98badfd..57c470113 100644 --- a/App/Navigators/AppNavigator.js +++ b/App/Navigators/AppNavigator.js @@ -1,6 +1,7 @@ import { createAppContainer, createStackNavigator } from 'react-navigation' import ExampleScreen from 'App/Containers/Example/ExampleScreen' +import DeepLinkingScreen from 'App/Containers/DeepLinking/DeepLinkingScreen' import SplashScreen from 'App/Containers/SplashScreen/SplashScreen' /** @@ -15,7 +16,13 @@ const StackNavigator = createStackNavigator( SplashScreen: SplashScreen, // The main application screen is our "ExampleScreen". Feel free to replace it with your // own screen and remove the example. - MainScreen: ExampleScreen, + MainScreen: { + screen: ExampleScreen, + }, + DeepLinkingScreen: { + screen: DeepLinkingScreen, + path: 'deeplink', + }, }, { // By default the application will show the splash screen diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index ddbb92dc1..3d80d2214 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -14,11 +14,18 @@ android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize" - android:windowSoftInputMode="adjustResize"> + android:windowSoftInputMode="adjustResize" + android:launchMode="singleTask"> + + + + + + diff --git a/ios/Boilerplate/AppDelegate.m b/ios/Boilerplate/AppDelegate.m index 4bcf02090..bc34109ec 100644 --- a/ios/Boilerplate/AppDelegate.m +++ b/ios/Boilerplate/AppDelegate.m @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +#import + #import "AppDelegate.h" #import @@ -39,4 +41,10 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge #endif } +- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url + options:(NSDictionary *)options +{ + return [RCTLinkingManager application:app openURL:url options:options]; +} + @end diff --git a/ios/Boilerplate/Info.plist b/ios/Boilerplate/Info.plist index 80dd4dbb2..eb62fcb4f 100644 --- a/ios/Boilerplate/Info.plist +++ b/ios/Boilerplate/Info.plist @@ -20,11 +20,24 @@ 1.0 CFBundleSignature ???? + CFBundleURLTypes + + + CFBundleTypeRole + Editor + CFBundleURLName + boilerplate + CFBundleURLSchemes + + boilerplate + + + CFBundleVersion 1 LSRequiresIPhoneOS - NSAppTransportSecurity + NSAppTransportSecurity NSAllowsArbitraryLoads diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 259788ca2..0905cefc1 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -345,6 +345,6 @@ SPEC CHECKSUMS: RNScreens: cf198f915f8a2bf163de94ca9f5bfc8d326c3706 Yoga: f2a7cd4280bfe2cca5a7aed98ba0eb3d1310f18b -PODFILE CHECKSUM: 1aeb3204d81fb1938d1f1a04d0a3797595914ef3 +PODFILE CHECKSUM: 3d811d26fadf74812df3c538c7abf505a9be9900 -COCOAPODS: 1.9.0 +COCOAPODS: 1.9.3