Skip to content

Commit ad468ab

Browse files
lks574interactord
authored andcommitted
feat: Singnavigator - deeplink init
1 parent 2e07245 commit ad468ab

7 files changed

Lines changed: 87 additions & 2 deletions

File tree

Examples/SingleNavigator/02-SingleEventSubscriber/02-SingleEventSubscriber.xcodeproj/project.pbxproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
29C639072B44FEAB00FCFE0F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 29C639062B44FEAB00FCFE0F /* Assets.xcassets */; };
1212
29C6390B2B44FEAB00FCFE0F /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 29C6390A2B44FEAB00FCFE0F /* Preview Assets.xcassets */; };
1313
932D1E822B46A641000E50C3 /* PathIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 932D1E812B46A641000E50C3 /* PathIndicator.swift */; };
14+
932D1E882B46AC5E000E50C3 /* DeepLinkParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 932D1E872B46AC5E000E50C3 /* DeepLinkParser.swift */; };
15+
932D1E8A2B46B190000E50C3 /* DeepLinkItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 932D1E892B46B190000E50C3 /* DeepLinkItem.swift */; };
1416
933012A22B4563C700893C91 /* LinkNavigator in Frameworks */ = {isa = PBXBuildFile; productRef = 933012A12B4563C700893C91 /* LinkNavigator */; };
1517
933012A52B4563D900893C91 /* PageTemplate in Frameworks */ = {isa = PBXBuildFile; productRef = 933012A42B4563D900893C91 /* PageTemplate */; };
1618
93D683F02B463DA700FD2C24 /* AppDependency.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93D683EF2B463DA700FD2C24 /* AppDependency.swift */; };
@@ -33,6 +35,9 @@
3335
29C639082B44FEAB00FCFE0F /* SingleEventSubscriber.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = SingleEventSubscriber.entitlements; sourceTree = "<group>"; };
3436
29C6390A2B44FEAB00FCFE0F /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
3537
932D1E812B46A641000E50C3 /* PathIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PathIndicator.swift; sourceTree = "<group>"; };
38+
932D1E872B46AC5E000E50C3 /* DeepLinkParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeepLinkParser.swift; sourceTree = "<group>"; };
39+
932D1E892B46B190000E50C3 /* DeepLinkItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeepLinkItem.swift; sourceTree = "<group>"; };
40+
932D1E8B2B46B5E9000E50C3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
3641
93D683EF2B463DA700FD2C24 /* AppDependency.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDependency.swift; sourceTree = "<group>"; };
3742
93D683F12B463DB100FD2C24 /* AppRouterGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppRouterGroup.swift; sourceTree = "<group>"; };
3843
93D683F62B463DE600FD2C24 /* HomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeView.swift; sourceTree = "<group>"; };
@@ -78,6 +83,8 @@
7883
29C639012B44FEAA00FCFE0F /* SingleEventSubscriber */ = {
7984
isa = PBXGroup;
8085
children = (
86+
932D1E8B2B46B5E9000E50C3 /* Info.plist */,
87+
932D1E862B46ABE0000E50C3 /* DeepLink */,
8188
932D1E802B46A634000E50C3 /* Component */,
8289
93D683F42B463DD800FD2C24 /* Page */,
8390
29C639022B44FEAA00FCFE0F /* SingleEventSubscriberApp.swift */,
@@ -106,6 +113,15 @@
106113
path = Component;
107114
sourceTree = "<group>";
108115
};
116+
932D1E862B46ABE0000E50C3 /* DeepLink */ = {
117+
isa = PBXGroup;
118+
children = (
119+
932D1E872B46AC5E000E50C3 /* DeepLinkParser.swift */,
120+
932D1E892B46B190000E50C3 /* DeepLinkItem.swift */,
121+
);
122+
path = DeepLink;
123+
sourceTree = "<group>";
124+
};
109125
93D683F42B463DD800FD2C24 /* Page */ = {
110126
isa = PBXGroup;
111127
children = (
@@ -238,8 +254,10 @@
238254
93D684012B463E5E00FD2C24 /* Page2View.swift in Sources */,
239255
932D1E822B46A641000E50C3 /* PathIndicator.swift in Sources */,
240256
93D683F22B463DB100FD2C24 /* AppRouterGroup.swift in Sources */,
257+
932D1E882B46AC5E000E50C3 /* DeepLinkParser.swift in Sources */,
241258
93D684082B46589300FD2C24 /* Page3View.swift in Sources */,
242259
93D683F72B463DE600FD2C24 /* HomeView.swift in Sources */,
260+
932D1E8A2B46B190000E50C3 /* DeepLinkItem.swift in Sources */,
243261
93D683F92B463DFC00FD2C24 /* HomeRouteBuilder.swift in Sources */,
244262
29C639032B44FEAA00FCFE0F /* SingleEventSubscriberApp.swift in Sources */,
245263
93D683FE2B463E4600FD2C24 /* Page1RouteBuilder.swift in Sources */,
@@ -376,6 +394,7 @@
376394
DEVELOPMENT_ASSET_PATHS = "\"SingleEventSubscriber/Preview Content\"";
377395
ENABLE_PREVIEWS = YES;
378396
GENERATE_INFOPLIST_FILE = YES;
397+
INFOPLIST_FILE = SingleEventSubscriber/Info.plist;
379398
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
380399
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
381400
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
@@ -413,6 +432,7 @@
413432
DEVELOPMENT_ASSET_PATHS = "\"SingleEventSubscriber/Preview Content\"";
414433
ENABLE_PREVIEWS = YES;
415434
GENERATE_INFOPLIST_FILE = YES;
435+
INFOPLIST_FILE = SingleEventSubscriber/Info.plist;
416436
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
417437
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
418438
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Foundation
2+
3+
struct DeepLinkItem: Equatable, Codable {
4+
let message: String
5+
}
6+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Foundation
2+
import LinkNavigator
3+
4+
enum DeepLinkParser {
5+
static func parse(url: URL, completeAction: @escaping (LinkItem?) -> Void) {
6+
guard let component = URLComponents(url: url, resolvingAgainstBaseURL: false) else {
7+
completeAction(.none)
8+
return
9+
}
10+
11+
let pathList = component.path.split(separator: "/").map(String.init)
12+
let item: String = component.query ?? ""
13+
completeAction(.init(pathList: pathList, items: item))
14+
}
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleURLTypes</key>
6+
<array>
7+
<dict>
8+
<key>CFBundleTypeRole</key>
9+
<string>Editor</string>
10+
<key>CFBundleURLName</key>
11+
<string>DeepLink</string>
12+
<key>CFBundleURLSchemes</key>
13+
<array>
14+
<string>single-ex</string>
15+
</array>
16+
</dict>
17+
</array>
18+
</dict>
19+
</plist>

Examples/SingleNavigator/02-SingleEventSubscriber/SingleEventSubscriber/Page/Page1/Page1RouteBuilder.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ struct Page1RouteBuilder<RootNavigator: RootNavigatorType> {
77
var matchPath: String { "page1" }
88
return .init(matchPath: matchPath) { navigator, items, diContainer -> RouteViewController? in
99
let query: HomeToPage1Item? = items.decoded()
10+
let deepLinkItem: DeepLinkItem? = items.decoded()
1011
return WrappingController(matchPath: matchPath) {
1112
Page1View(
1213
navigator: navigator,
13-
item: query)
14+
item: query,
15+
deepLinkItem: deepLinkItem
16+
)
1417
}
1518
}
1619
}

Examples/SingleNavigator/02-SingleEventSubscriber/SingleEventSubscriber/Page/Page1/Page1View.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ struct Page1View: View {
55

66
let navigator: RootNavigatorType
77
let item: HomeToPage1Item?
8+
let deepLinkItem: DeepLinkItem?
89

910
var body: some View {
1011
VStack(spacing: 30) {
@@ -15,7 +16,7 @@ struct Page1View: View {
1516
VStack(spacing: 10) {
1617
HStack {
1718
Image(systemName: "envelope")
18-
Text("Received Message")
19+
Text("HomePage Received Message")
1920
}
2021
.font(.footnote)
2122
.foregroundColor(.secondary)
@@ -24,6 +25,19 @@ struct Page1View: View {
2425
}
2526
}
2627

28+
GroupBox {
29+
VStack(spacing: 10) {
30+
HStack {
31+
Image(systemName: "envelope")
32+
Text("DeepLink Received Message")
33+
}
34+
.font(.footnote)
35+
.foregroundColor(.secondary)
36+
37+
Text(deepLinkItem?.message ?? "-")
38+
}
39+
}
40+
2741
Button(action: {
2842
navigator.backOrNext(linkItem: .init(path: "page2"), isAnimated: true)
2943
}) {

Examples/SingleNavigator/02-SingleEventSubscriber/SingleEventSubscriber/SingleEventSubscriberApp.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ struct SingleEventSubscriberApp: App {
1515
item: .init(path: "home")
1616
)
1717
.ignoresSafeArea()
18+
.onOpenURL { url in
19+
DeepLinkParser.parse(url: url) { linkItem in
20+
guard let linkItem else { return }
21+
singleNavigator.getCurrentPaths().count > 1
22+
? singleNavigator.next(linkItem: linkItem, isAnimated: true)
23+
: singleNavigator.replace(linkItem: linkItem, isAnimated: true)
24+
}
25+
}
1826
}
1927
}
2028
}

0 commit comments

Comments
 (0)