Skip to content
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

fix issue #71: UIView that conforms StatefulViewController protocol cannot be destroyed #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion StatefulViewController/StatefulViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public enum StatefulViewControllerState: String {
public protocol BackingViewProvider {
/// The backing view, usually a UIViewController's view.
/// All placeholder views will be added to this view instance.
var backingView: UIView { get }
var backingView: UIView! { get }
}

/// StatefulViewController protocol may be adopted by a view controller or a view in order to transition to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import UIKit
// MARK: Default Implementation BackingViewProvider

extension BackingViewProvider where Self: UIViewController {
public var backingView: UIView {
public weak var backingView: UIView! {
return view
}
}

extension BackingViewProvider where Self: UIView {
public var backingView: UIView {
public weak var backingView: UIView! {
return self
}
}
Expand Down
13 changes: 9 additions & 4 deletions StatefulViewController/ViewStateMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public class ViewStateMachine {
}()

/// The view that should act as the superview for any added views
public let view: UIView
public weak var view: UIView?

/// The current display state of views
public fileprivate(set) var currentState: ViewStateMachineState = .none

Expand Down Expand Up @@ -162,9 +162,14 @@ public class ViewStateMachine {
// MARK: Private view updates

fileprivate func showView(forKey state: String, animated: Bool, completion: (() -> ())? = nil) {
guard let superview = self.view else {
completion?()
return
}

// Add the container view
containerView.frame = view.bounds
view.addSubview(containerView)
containerView.frame = superview.bounds
superview.addSubview(containerView)

let store = viewStore

Expand Down