Skip to content

Commit 7d962ca

Browse files
AurelGitrmaniyar@ownsourcing.comJeremyDolleaum-tcm
authored
Implement deep-linking (#112)
* Minor POC to showcase deep-linking abilities through the boilerplate * deep linking ios and refactor Co-authored-by: [email protected] <[email protected]> Co-authored-by: DOLLE <[email protected]> Co-authored-by: Aurélien Mutin <[email protected]>
1 parent 6bedcbe commit 7d962ca

File tree

7 files changed

+60
-5
lines changed

7 files changed

+60
-5
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react'
2+
import { Text, View } from 'react-native'
3+
import { Helpers, Metrics } from 'App/Theme'
4+
5+
/**
6+
* This is an example of a container component with a deep link.
7+
*/
8+
const DeepLinkingScreen = () => (
9+
<View style={[Helpers.fillCenter, Helpers.rowMain, Metrics.mediumHorizontalMargin]}>
10+
<Text>
11+
This is deep linking example screen which can be accessed using boilerplate://deeplink scheme!
12+
</Text>
13+
</View>
14+
)
15+
16+
export default DeepLinkingScreen

App/Containers/Root/RootScreen.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import { Helpers } from 'App/Theme'
77
import { useDispatch } from 'react-redux'
88

99
const RootScreen = () => {
10+
// Deep linking prefix
11+
const prefix = 'boilerplate://';
12+
1013
const dispatch = useDispatch()
1114

1215
useEffect(() => {
@@ -20,6 +23,7 @@ const RootScreen = () => {
2023
ref={(navigatorRef) => {
2124
NavigationService.setTopLevelNavigator(navigatorRef)
2225
}}
26+
uriPrefix={prefix}
2327
/>
2428
</View>
2529
)

App/Navigators/AppNavigator.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createAppContainer, createStackNavigator } from 'react-navigation'
22

33
import ExampleScreen from 'App/Containers/Example/ExampleScreen'
4+
import DeepLinkingScreen from 'App/Containers/DeepLinking/DeepLinkingScreen'
45
import SplashScreen from 'App/Containers/SplashScreen/SplashScreen'
56

67
/**
@@ -15,7 +16,13 @@ const StackNavigator = createStackNavigator(
1516
SplashScreen: SplashScreen,
1617
// The main application screen is our "ExampleScreen". Feel free to replace it with your
1718
// own screen and remove the example.
18-
MainScreen: ExampleScreen,
19+
MainScreen: {
20+
screen: ExampleScreen,
21+
},
22+
DeepLinkingScreen: {
23+
screen: DeepLinkingScreen,
24+
path: 'deeplink',
25+
},
1926
},
2027
{
2128
// By default the application will show the splash screen

android/app/src/main/AndroidManifest.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,18 @@
1414
android:name=".MainActivity"
1515
android:label="@string/app_name"
1616
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
17-
android:windowSoftInputMode="adjustResize">
17+
android:windowSoftInputMode="adjustResize"
18+
android:launchMode="singleTask">
1819
<intent-filter>
1920
<action android:name="android.intent.action.MAIN" />
2021
<category android:name="android.intent.category.LAUNCHER" />
2122
</intent-filter>
23+
<intent-filter>
24+
<action android:name="android.intent.action.VIEW" />
25+
<category android:name="android.intent.category.DEFAULT" />
26+
<category android:name="android.intent.category.BROWSABLE" />
27+
<data android:scheme="boilerplate" />
28+
</intent-filter>
2229
</activity>
2330
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
2431
</application>

ios/Boilerplate/AppDelegate.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
#import <React/RCTLinkingManager.h>
9+
810
#import "AppDelegate.h"
911

1012
#import <React/RCTBridge.h>
@@ -39,4 +41,10 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
3941
#endif
4042
}
4143

44+
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url
45+
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
46+
{
47+
return [RCTLinkingManager application:app openURL:url options:options];
48+
}
49+
4250
@end

ios/Boilerplate/Info.plist

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,24 @@
2020
<string>1.0</string>
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
23+
<key>CFBundleURLTypes</key>
24+
<array>
25+
<dict>
26+
<key>CFBundleTypeRole</key>
27+
<string>Editor</string>
28+
<key>CFBundleURLName</key>
29+
<string>boilerplate</string>
30+
<key>CFBundleURLSchemes</key>
31+
<array>
32+
<string>boilerplate</string>
33+
</array>
34+
</dict>
35+
</array>
2336
<key>CFBundleVersion</key>
2437
<string>1</string>
2538
<key>LSRequiresIPhoneOS</key>
2639
<true/>
27-
<key>NSAppTransportSecurity</key>
40+
<key>NSAppTransportSecurity</key>
2841
<dict>
2942
<key>NSAllowsArbitraryLoads</key>
3043
<true/>

ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,6 @@ SPEC CHECKSUMS:
345345
RNScreens: cf198f915f8a2bf163de94ca9f5bfc8d326c3706
346346
Yoga: f2a7cd4280bfe2cca5a7aed98ba0eb3d1310f18b
347347

348-
PODFILE CHECKSUM: 1aeb3204d81fb1938d1f1a04d0a3797595914ef3
348+
PODFILE CHECKSUM: 3d811d26fadf74812df3c538c7abf505a9be9900
349349

350-
COCOAPODS: 1.9.0
350+
COCOAPODS: 1.9.3

0 commit comments

Comments
 (0)