-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from formbound/release-1.1.0
Release 1.1.0
- Loading branch information
Showing
3 changed files
with
106 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
public protocol AnyStateViewControllerObserver : AnyObject { | ||
func remove() | ||
} | ||
|
||
public class StateViewControllerObserver<T: Equatable>: AnyStateViewControllerObserver { | ||
|
||
public typealias EventHandler = (StateViewControllerObserver<T>.Event) -> Void | ||
|
||
public enum Event { | ||
case willTransitionTo(nextState: T, animated: Bool) | ||
case didTransitionFrom(previousState: T?, animated: Bool) | ||
|
||
case didChangeHierarhcy | ||
|
||
case contentWillAppear(UIViewController) | ||
case contentDidAppear(UIViewController) | ||
|
||
case contentWillDisappear(UIViewController) | ||
case contentDidDisappear(UIViewController) | ||
} | ||
|
||
private weak var stateViewController: StateViewController<T>? | ||
|
||
private let eventHandler: EventHandler | ||
|
||
internal init(stateViewController: StateViewController<T>, eventHandler: @escaping EventHandler) { | ||
self.eventHandler = eventHandler | ||
self.stateViewController = stateViewController | ||
} | ||
|
||
public func remove() { | ||
stateViewController?.removeStateObserver(self) | ||
} | ||
|
||
internal func invoke(with event: Event) { | ||
eventHandler(event) | ||
} | ||
} | ||
|
||
extension StateViewControllerObserver: Equatable { | ||
|
||
public static func == (lhs: StateViewControllerObserver, rhs: StateViewControllerObserver) -> Bool { | ||
return lhs === rhs | ||
} | ||
} | ||
|
||
|
||
|
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