-
Notifications
You must be signed in to change notification settings - Fork 8
Feature/deeplink api #338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
castlele
wants to merge
8
commits into
master
Choose a base branch
from
feature/deeplink_api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature/deeplink api #338
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a7e44a3
feat: initial deep link settings
castlele aff5485
feat: complete deeplink api
castlele f885183
fix: updated push to podspecs script
castlele 3d5aa7a
fix: remove default implementation of deeplink handler in service object
castlele caeded9
fix: searching deeplink handler in navigation stack
castlele 63777fe
fix: update an approach to handling operation in TIDeeplinkService
castlele 407995d
Merge branch 'master' into feature/deeplink_api
castlele 7765c01
fix: code review notes
castlele File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
TIDeepLink/Sources/DeeplinkHandler/BaseNavigationStackDeeplinkHandler.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // | ||
| // Copyright (c) 2023 Touch Instinct | ||
| // | ||
| // Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| // of this software and associated documentation files (the Software), to deal | ||
| // in the Software without restriction, including without limitation the rights | ||
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| // copies of the Software, and to permit persons to whom the Software is | ||
| // furnished to do so, subject to the following conditions: | ||
| // | ||
| // The above copyright notice and this permission notice shall be included in | ||
| // all copies or substantial portions of the Software. | ||
| // | ||
| // THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| // THE SOFTWARE. | ||
| // | ||
|
|
||
| import Foundation | ||
| import UIKit | ||
|
|
||
| open class BaseNavigationStackDeeplinkHandler<ControllerKeeper: RootViewControllerKeeper>: DeeplinkHandler { | ||
|
|
||
| public typealias DeeplinkType = ControllerKeeper.DeeplinkHandler.DeeplinkType | ||
| public typealias Handler = ControllerKeeper.DeeplinkHandler | ||
|
|
||
| public var rootViewControllerKeeper: ControllerKeeper? | ||
|
|
||
| // MARK: - DeeplinkHandler | ||
|
|
||
| open func handle(deeplink: DeeplinkType) -> Operation? { | ||
| let handler = findHandler(for: deeplink) | ||
| return handler?.handle(deeplink: deeplink) | ||
| } | ||
|
|
||
| // MARK: - Open methods | ||
|
|
||
| open func findHandler(for deeplink: DeeplinkType) -> Handler? { | ||
|
|
||
| guard let rootController = rootViewControllerKeeper?.rootDeeplinkHandlerController else { | ||
| return nil | ||
| } | ||
|
|
||
| return rootController.findHandler(for: deeplink) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // | ||
| // Copyright (c) 2023 Touch Instinct | ||
| // | ||
| // Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| // of this software and associated documentation files (the Software), to deal | ||
| // in the Software without restriction, including without limitation the rights | ||
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| // copies of the Software, and to permit persons to whom the Software is | ||
| // furnished to do so, subject to the following conditions: | ||
| // | ||
| // The above copyright notice and this permission notice shall be included in | ||
| // all copies or substantial portions of the Software. | ||
| // | ||
| // THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| // THE SOFTWARE. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| public protocol DeeplinkHandler { | ||
| associatedtype DeeplinkType: Hashable | ||
|
|
||
| func handle(deeplink: DeeplinkType) -> Operation? | ||
| } |
87 changes: 87 additions & 0 deletions
87
TIDeepLink/Sources/DeeplinkHandler/Helpers/UIViewController+DeeplinkHandler.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| // | ||
| // Copyright (c) 2023 Touch Instinct | ||
| // | ||
| // Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| // of this software and associated documentation files (the Software), to deal | ||
| // in the Software without restriction, including without limitation the rights | ||
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| // copies of the Software, and to permit persons to whom the Software is | ||
| // furnished to do so, subject to the following conditions: | ||
| // | ||
| // The above copyright notice and this permission notice shall be included in | ||
| // all copies or substantial portions of the Software. | ||
| // | ||
| // THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| // THE SOFTWARE. | ||
| // | ||
|
|
||
| import UIKit | ||
|
|
||
| public typealias DeeplinkHandlerViewController = DeeplinkHandler & UIViewController | ||
|
|
||
| public extension UIViewController { | ||
|
|
||
| func findHandler<DeeplinkHandler: DeeplinkHandlerViewController>( | ||
| for deeplink: DeeplinkHandler.DeeplinkType | ||
| ) -> DeeplinkHandler? { | ||
|
|
||
| if let deeplinksHandler = self as? DeeplinkHandler, | ||
| let _ = deeplinksHandler.handle(deeplink: deeplink) { | ||
| return deeplinksHandler | ||
| } | ||
|
|
||
| if let deeplinksHandler: DeeplinkHandler = presentedViewController?.findHandler(for: deeplink) { | ||
| return deeplinksHandler | ||
| } | ||
|
|
||
| return findHandlerInViewHierarchy(for: deeplink) | ||
| } | ||
|
|
||
| private func findHandlerInViewHierarchy<DeeplinkHandler: DeeplinkHandlerViewController>( | ||
| for deeplink: DeeplinkHandler.DeeplinkType | ||
| ) -> DeeplinkHandler? { | ||
|
|
||
| switch self { | ||
| case let navController as UINavigationController: | ||
| let deeplinksHandler: DeeplinkHandler? = navController.viewControllers.reversed().findHandler(for: deeplink) | ||
| return deeplinksHandler | ||
|
|
||
| case let tabController as UITabBarController: | ||
| if let deeplinksHandler: DeeplinkHandler = tabController.selectedViewController?.findHandler(for: deeplink) { | ||
| return deeplinksHandler | ||
| } else if var tabControllers = tabController.viewControllers { | ||
| if tabController.selectedIndex != NSNotFound { | ||
| tabControllers.remove(at: tabController.selectedIndex) | ||
| } | ||
|
|
||
| if let deeplinksHandler: DeeplinkHandler = tabControllers.findHandler(for: deeplink) { | ||
| return deeplinksHandler | ||
| } | ||
| } | ||
|
|
||
| default: | ||
| return nil | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
| } | ||
|
|
||
| private extension Sequence where Element: UIViewController { | ||
| func findHandler<DeeplinkHandler: DeeplinkHandlerViewController>( | ||
| for deeplink: DeeplinkHandler.DeeplinkType | ||
| ) -> DeeplinkHandler? { | ||
|
|
||
| for controller in self { | ||
| if let deeplinksHandler: DeeplinkHandler = controller.findHandler(for: deeplink) { | ||
| return deeplinksHandler | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
TIDeepLink/Sources/DeeplinkHandler/RootViewControllerKeeper.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // | ||
| // Copyright (c) 2023 Touch Instinct | ||
| // | ||
| // Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| // of this software and associated documentation files (the Software), to deal | ||
| // in the Software without restriction, including without limitation the rights | ||
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| // copies of the Software, and to permit persons to whom the Software is | ||
| // furnished to do so, subject to the following conditions: | ||
| // | ||
| // The above copyright notice and this permission notice shall be included in | ||
| // all copies or substantial portions of the Software. | ||
| // | ||
| // THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| // THE SOFTWARE. | ||
| // | ||
|
|
||
| import UIKit | ||
|
|
||
| public protocol RootViewControllerKeeper { | ||
| associatedtype DeeplinkHandler: DeeplinkHandlerViewController | ||
|
|
||
| var rootDeeplinkHandlerController: DeeplinkHandler { get } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // | ||
| // Copyright (c) 2023 Touch Instinct | ||
| // | ||
| // Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| // of this software and associated documentation files (the Software), to deal | ||
| // in the Software without restriction, including without limitation the rights | ||
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| // copies of the Software, and to permit persons to whom the Software is | ||
| // furnished to do so, subject to the following conditions: | ||
| // | ||
| // The above copyright notice and this permission notice shall be included in | ||
| // all copies or substantial portions of the Software. | ||
| // | ||
| // THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| // THE SOFTWARE. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| public protocol DeeplinkMapper { | ||
| associatedtype DeeplinkType | ||
|
|
||
| func map(url: URL) -> DeeplinkType? | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| // | ||
| // Copyright (c) 2023 Touch Instinct | ||
| // | ||
| // Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| // of this software and associated documentation files (the Software), to deal | ||
| // in the Software without restriction, including without limitation the rights | ||
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| // copies of the Software, and to permit persons to whom the Software is | ||
| // furnished to do so, subject to the following conditions: | ||
| // | ||
| // The above copyright notice and this permission notice shall be included in | ||
| // all copies or substantial portions of the Software. | ||
| // | ||
| // THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| // THE SOFTWARE. | ||
| // | ||
|
|
||
| import Foundation | ||
| import TIFoundationUtils | ||
|
|
||
| open class TIDeeplinksService<DeeplinkType: Hashable, | ||
| Mapper: DeeplinkMapper, | ||
| Handler: DeeplinkHandler> where Mapper.DeeplinkType == Handler.DeeplinkType, | ||
| Mapper.DeeplinkType == DeeplinkType { | ||
|
|
||
| // MARK: - Private properties | ||
|
|
||
| private var operationQueue: OperationQueue | ||
|
|
||
| private var deeplinkQueue: [DeeplinkType] = [] | ||
| private var inProcessingSet: Set<DeeplinkType> = [] | ||
|
|
||
| // MARK: - Public properties | ||
|
|
||
| public var deeplinkMapper: Mapper? | ||
| public var deeplinkHandler: Handler? | ||
|
|
||
| // MARK: - Init | ||
|
|
||
| public init(mapper: Mapper, handler: Handler, operationQueue: OperationQueue = .main) { | ||
| self.deeplinkMapper = mapper | ||
| self.deeplinkHandler = handler | ||
| self.operationQueue = operationQueue | ||
| } | ||
|
|
||
| // MARK: - Open methods | ||
|
|
||
| /// Mapping the given url to deeplink model and appending it to the queue. | ||
| /// - Parameter url: URL to map into deeplink model | ||
| /// - Returns: true if a mapper mapped url to deeplink model successfully. Also returns false if `deeplinkMapper` is nil | ||
| @discardableResult | ||
| open func deferredHandle(url: URL) -> Bool { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. тут можно подписать в комменте к методу, что значит возвращаемый bool |
||
| let deeplink = deeplinkMapper?.map(url: url) | ||
|
|
||
| guard let deeplink = deeplink else { | ||
| return false | ||
| } | ||
|
|
||
| deeplinkQueue.append(deeplink) | ||
|
|
||
| return true | ||
| } | ||
|
|
||
| open func reset() { | ||
| operationQueue.cancelAllOperations() | ||
| deeplinkQueue.removeAll() | ||
| inProcessingSet.removeAll() | ||
| } | ||
|
|
||
| open func handlePendingDeeplinks() { | ||
| guard let deeplink = deeplinkQueue.first, | ||
| let handler = deeplinkHandler else { | ||
| return | ||
| } | ||
|
|
||
| deeplinkQueue.remove(at: .zero) | ||
|
|
||
| guard !inProcessingSet.contains(deeplink), | ||
| let operation = handler.handle(deeplink: deeplink) else { | ||
| return | ||
| } | ||
|
|
||
| inProcessingSet.formUnion([deeplink]) | ||
|
|
||
| let competionOperation = BlockOperation { [weak self] in | ||
| self?.inProcessingSet.subtract([deeplink]) | ||
| } | ||
|
|
||
| competionOperation.addDependency(operation) | ||
|
|
||
| competionOperation.add(to: operationQueue) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.