Skip to content

Commit

Permalink
Merge pull request #14 from MetalheadSanya/fix_appearance
Browse files Browse the repository at this point in the history
Fix layout warnings and begin/end appearance transitions
  • Loading branch information
MetalheadSanya authored Aug 22, 2018
2 parents 762914f + 44e3ba1 commit 5666ced
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
<LocationScenarioReference
identifier = "com.apple.dt.IDEFoundation.CurrentLocationScenarioIdentifier"
referenceType = "1">
</LocationScenarioReference>
</LaunchAction>
<ProfileAction
buildConfiguration = "AdHoc"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ extension TextControl {

parent.addSubview(view)
NSLayoutConstraint.activate(constraints)
parent.layoutIfNeeded()
animation?.perform(for: view)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class ModalTemplate: UIViewController {

func setContentView(_ view: UIView) {
view.translatesAutoresizingMaskIntoConstraints = false
view.frame = self.view.bounds
self.view.insertSubview(view, at: 0)

let constraints = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,13 @@ class TokenizationViewController: UIViewController {
actionSheetTemplate.delegate = self

addChildViewController(actionSheetTemplate)

actionSheetTemplate.addChildViewController(vc)

actionSheetTemplate.beginAppearanceTransition(true, animated: false)

view.addSubview(actionSheetTemplate.view)
actionSheetTemplate.dummyView.addSubview(vc.view)

actionSheetTemplate.beginAppearanceTransition(true, animated: false)

actionSheetTemplate.view.translatesAutoresizingMaskIntoConstraints = false
vc.view.translatesAutoresizingMaskIntoConstraints = false

Expand All @@ -267,6 +266,7 @@ class TokenizationViewController: UIViewController {
]
NSLayoutConstraint.activate(constraints)

actionSheetTemplate.didMove(toParentViewController: self)
vc.didMove(toParentViewController: actionSheetTemplate)

actionSheetTemplate.endAppearanceTransition()
Expand All @@ -286,8 +286,8 @@ class TokenizationViewController: UIViewController {
modalTemplate.addChildViewController(vc)
vc.view.translatesAutoresizingMaskIntoConstraints = false
modalTemplate.setContentView(vc.view)

modalTemplate.beginAppearanceTransition(true, animated: true)
vc.beginAppearanceTransition(true, animated: true)

let modalTemplateConstraints = [
view.leading.constraint(equalTo: modalTemplate.view.leading),
Expand All @@ -305,11 +305,11 @@ class TokenizationViewController: UIViewController {
modalTemplate.view.bottom.constraint(equalTo: vc.view.bottom),
]
NSLayoutConstraint.activate(constraints)
modalTemplate.endAppearanceTransition()
vc.endAppearanceTransition()
modalTemplate.didMove(toParentViewController: self)
vc.didMove(toParentViewController: modalTemplate)

modalTemplate.endAppearanceTransition()

modalTemplate.navigationBar.setItems([vc.navigationItem], animated: false)

modules.append(vc)
Expand All @@ -327,8 +327,6 @@ class TokenizationViewController: UIViewController {
pageSheet.addChildViewController(vc)
vc.view.translatesAutoresizingMaskIntoConstraints = false
pageSheet.setContentView(vc.view)
pageSheet.beginAppearanceTransition(true, animated: true)
vc.beginAppearanceTransition(true, animated: true)

let modalTemplateConstraints = [
view.leading.constraint(equalTo: pageSheet.view.leading),
Expand All @@ -342,8 +340,6 @@ class TokenizationViewController: UIViewController {
pageSheet.setNavigationItems(modules.map { $0.navigationItem }, animated: false)
pageSheet.view.layoutIfNeeded()

pageSheet.endAppearanceTransition()
vc.endAppearanceTransition()
pageSheet.didMove(toParentViewController: self)
vc.didMove(toParentViewController: pageSheet)

Expand Down Expand Up @@ -378,17 +374,16 @@ class TokenizationViewController: UIViewController {
containerConstraints = []

vc.view.removeFromSuperview()
vc.endAppearanceTransition()

vc.removeFromParentViewController()

vc.endAppearanceTransition()
}

// MARK: - Hide view controller animated

private func hideAnimated(actionSheet: ActionSheetTemplate, completion: (() -> Void)? = nil) {
actionSheet.willMove(toParentViewController: nil)

actionSheet.beginAppearanceTransition(false, animated: true)
actionSheet.willMove(toParentViewController: nil)

NSLayoutConstraint.deactivate(containerConstraints)

Expand All @@ -414,8 +409,8 @@ class TokenizationViewController: UIViewController {
}

private func hideAnimated(pageSheet: PageSheetTemplate, completion: (() -> Void)? = nil) {
pageSheet.willMove(toParentViewController: nil)
pageSheet.beginAppearanceTransition(false, animated: true)
pageSheet.willMove(toParentViewController: nil)
NSLayoutConstraint.deactivate(containerConstraints)

let dismissConstraint = [
Expand Down Expand Up @@ -448,13 +443,15 @@ class TokenizationViewController: UIViewController {
modules.append(vc)

addChildViewController(modalTemplate)
modalTemplate.beginAppearanceTransition(true, animated: true)
modalTemplate.view.translatesAutoresizingMaskIntoConstraints = false
modalTemplate.view.frame = view.bounds
view.addSubview(modalTemplate.view)

modalTemplate.addChildViewController(vc)
modalTemplate.setContentView(vc.view)

modalTemplate.beginAppearanceTransition(true, animated: true)

let startConstraints = [
modalTemplate.view.leading.constraint(equalTo: view.leading),
modalTemplate.view.top.constraint(equalTo: view.bottom),
Expand Down Expand Up @@ -482,10 +479,11 @@ class TokenizationViewController: UIViewController {
self.view.layoutIfNeeded()
},
completion: { _ in
modalTemplate.endAppearanceTransition()
modalTemplate.didMove(toParentViewController: self)

vc.didMove(toParentViewController: modalTemplate)

modalTemplate.endAppearanceTransition()

self.modalTemplate = modalTemplate
completion?()
})
Expand All @@ -502,8 +500,8 @@ class TokenizationViewController: UIViewController {
pageSheet.addChildViewController(vc)
vc.view.translatesAutoresizingMaskIntoConstraints = false
pageSheet.setContentView(vc.view)

pageSheet.beginAppearanceTransition(true, animated: true)
vc.beginAppearanceTransition(true, animated: true)

let startConstraints = [
pageSheet.view.leading.constraint(equalTo: view.leading),
Expand Down Expand Up @@ -534,27 +532,30 @@ class TokenizationViewController: UIViewController {
self.view.layoutIfNeeded()
},
completion: { _ in
pageSheet.endAppearanceTransition()
vc.endAppearanceTransition()
pageSheet.didMove(toParentViewController: self)
vc.didMove(toParentViewController: pageSheet)

pageSheet.endAppearanceTransition()

vc.removeKeyboardObservers()

self.pageSheetTemplate = pageSheet
completion?()
})

vc.removeKeyboardObservers()
modules.append(vc)
self.pageSheetTemplate = pageSheet
}

private func presentActionSheetAnimated(_ vc: UIViewController, completion: (() -> Void)? = nil) {
let actionSheetTemplate = ActionSheetTemplate()
actionSheetTemplate.delegate = self

addChildViewController(actionSheetTemplate)
actionSheetTemplate.beginAppearanceTransition(true, animated: false)
actionSheetTemplate.addChildViewController(vc)
vc.didMove(toParentViewController: actionSheetTemplate)

actionSheetTemplate.beginAppearanceTransition(true, animated: true)

view.addSubview(actionSheetTemplate.view)
actionSheetTemplate.dummyView.addSubview(vc.view)

Expand Down Expand Up @@ -595,9 +596,10 @@ class TokenizationViewController: UIViewController {
self.view.layoutIfNeeded()
},
completion: { _ in
actionSheetTemplate.endAppearanceTransition()
actionSheetTemplate.didMove(toParentViewController: self)

actionSheetTemplate.endAppearanceTransition()

completion?()
})

Expand Down Expand Up @@ -677,9 +679,6 @@ class TokenizationViewController: UIViewController {
pageSheet.dummyView.setNeedsLayout()
pageSheet.dummyView.layoutIfNeeded()

pvc.beginAppearanceTransition(false, animated: true)
nvc.beginAppearanceTransition(true, animated: true)

NSLayoutConstraint.deactivate(startConstraints)
pageSheet.setContentView(nvc.view)

Expand All @@ -698,11 +697,9 @@ class TokenizationViewController: UIViewController {
pageSheet.view.layoutIfNeeded()
},
completion: { _ in
nvc.endAppearanceTransition()
nvc.didMove(toParentViewController: pageSheet)
})

pvc.endAppearanceTransition()
pvc.removeFromParentViewController()

self.modules.append(nvc)
Expand Down

0 comments on commit 5666ced

Please sign in to comment.