-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- introduced PresentableUserAgent - deprecated makePresentableUserAgent from WebViewUserAgentViewController - updated test apps
- Loading branch information
1 parent
60c8c31
commit b4ead3b
Showing
7 changed files
with
94 additions
and
62 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
65 changes: 65 additions & 0 deletions
65
MHIdentityKit/Infrastructure/UserAgent/PresentableUserAgent.swift
This file contains 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,65 @@ | ||
// | ||
// PresentableUserAgent.swift | ||
// MHIdentityKit | ||
// | ||
// Created by Milen Halachev on 6.02.20. | ||
// Copyright © 2020 Milen Halachev. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
///A type that makes a given user agent persentable. | ||
public struct PresentableUserAgent<T: UserAgent>: UserAgent { | ||
|
||
public var userAgent: T | ||
public var presentationHandler: (T) -> Void | ||
public var dismissHandler: (T) -> Void | ||
|
||
/** | ||
Makes a presentable UserAgent of a given user agent. | ||
|
||
- parameter userAgent: The user agent to present. | ||
- parameter presentationHandler: This is the presentation handler. Called when the user agent has to be shown on screen. | ||
- parameter dismissHandler: This is the dimiss handler. Called when the user agent successfully handles a redirect and has to be dismissed. | ||
|
||
- note: If the user agent is UIViewController, It is recommended embed it into UINavigationController with visible toolbar, because it contains web navigation controls. If you present it modally within an UINavigationController - it is your responsibility to setup a cancel/close button, based on your needs. | ||
*/ | ||
|
||
public init(_ userAgent: T, presentationHandler: @escaping (T) -> Void, dismissHandler: @escaping (T) -> Void) { | ||
|
||
self.userAgent = userAgent | ||
self.presentationHandler = presentationHandler | ||
self.dismissHandler = dismissHandler | ||
} | ||
|
||
public func perform(_ request: URLRequest, redirectURI: URL?, redirectionHandler: @escaping (URLRequest) throws -> Bool) { | ||
|
||
DispatchQueue.main.async { | ||
|
||
self.userAgent.perform(request, redirectURI: redirectURI, redirectionHandler: { (request) -> Bool in | ||
|
||
let didHandleRedirect = try redirectionHandler(request) | ||
|
||
if didHandleRedirect { | ||
|
||
self.dismiss() | ||
} | ||
|
||
return didHandleRedirect | ||
}) | ||
|
||
self.present() | ||
} | ||
} | ||
|
||
public func present() { | ||
|
||
self.presentationHandler(self.userAgent) | ||
} | ||
|
||
public func dismiss() { | ||
|
||
self.dismissHandler(self.userAgent) | ||
} | ||
} |
This file contains 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 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