-
Notifications
You must be signed in to change notification settings - Fork 7
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
Feature/deeplink api #338
base: master
Are you sure you want to change the base?
Feature/deeplink api #338
Conversation
// MARK: - Open methods | ||
|
||
open func findHandler(for deeplink: DeeplinkType) -> DeeplinkHandler? { | ||
guard let rootController = UIApplication.shared.keyWindow?.rootViewController else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
давай лучше протоколом закроем, который будет предоставлять rootDeeplinkHandlerController (UIViewController)
func canHandle(deeplink: DeeplinkType) -> Bool | ||
func handle(deeplink: DeeplinkType) -> Operation? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
я думаю, что нам хватит второго метода т.к. он возвращает optional
либо handler к которому мы обратились не может обработать deeplink (возвращает nil)
либо он сам найдёт внутри себя обработчика
TIDeepLink/Sources/DeeplinkHandler/Helpers/UIViewController+DeeplinkHandler.swift
Show resolved
Hide resolved
public protocol DeeplinkType { | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а можем обойтись associatedType или generic вместо пустого протокола?
import Foundation | ||
import TIFoundationUtils | ||
|
||
public final class TIDeeplinksService { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
сервис надо создавать самостоятельно с generic аргументом deeplink type
|
||
// MARK: - Private properties | ||
|
||
private let operationQueue = OperationQueue.main |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
параметром в init
private var pendingDeeplink: DeeplinkType? | ||
|
||
private(set) var isProcessingDeeplink = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
уже есть реализация актуальней
# Conflicts: # LeadKit.podspec # TIAppleMapUtils/TIAppleMapUtils.podspec # TIAuth/TIAuth.podspec # TIEcommerce/TIEcommerce.podspec # TIFoundationUtils/TIFoundationUtils.podspec # TIGoogleMapUtils/TIGoogleMapUtils.podspec # TIKeychainUtils/TIKeychainUtils.podspec # TILogging/TILogging.podspec # TIMapUtils/TIMapUtils.podspec # TIMoyaNetworking/TIMoyaNetworking.podspec # TINetworking/TINetworking.podspec # TINetworkingCache/TINetworkingCache.podspec # TIPagination/TIPagination.podspec # TISwiftUICore/TISwiftUICore.podspec # TISwiftUtils/TISwiftUtils.podspec # TITableKitUtils/TITableKitUtils.podspec # TITransitions/TITransitions.podspec # TIUIElements/TIUIElements.podspec # TIUIKitCore/TIUIKitCore.podspec # TIYandexMapUtils/TIYandexMapUtils.podspec
open func tryHandle() { | ||
guard !deeplinkQueue.isEmpty else { | ||
return | ||
} | ||
|
||
handle() | ||
} | ||
|
||
open func handle() { | ||
guard let deeplink = deeplinkQueue.first else { | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
один метод тут лишний
handle() | ||
} | ||
|
||
open func handle() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handlePendingDeeplinks
public init(operationQueue: OperationQueue = .main) { | ||
self.operationQueue = operationQueue | ||
} | ||
|
||
// MARK: - Open methods | ||
|
||
open func configure(mapper: Mapper, handler: Handler) { | ||
deeplinkMapper = mapper | ||
deeplinkHandler = handler | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
давай лучше и Mapper и Handler в init
} | ||
|
||
open func handle() { | ||
guard let deeplink = deeplinkQueue.first else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
также можно сразу проверить let handler
} | ||
|
||
@discardableResult | ||
open func deferredHandle(url: URL) -> Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тут можно подписать в комменте к методу, что значит возвращаемый bool
Deeplink api
Как начать использовать
Для корректной работы необходимо:
DeeplinkType
;DeeplinkMapper
;DeeplinkHandler
;TIDeeplinkService
.1. DeeplinkType
Сам по себе является пустым протоколом
2. DeeplinkMapper
Объект, соответствующий данному протоколу, должен отвечать за преобразование
URL
'а в объектDeeplinkType
3. DeeplinkHandler
Объект, отвечающий за управление диплинком. Если объект может обработать диплинк, то он выдает необходимый набор инструкций
4. TIDeeplinkService
Синглтон класс для работы с диплинками. Для его работы необходимо произвести конфигурацию созданными объектами:
DeeplinkMapper
,DeeplinkHandler
Теперь все готово к использованию сервиса