Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.
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
1 change: 1 addition & 0 deletions Demo/App/AppOtherViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ final class AppOtherController: StackScrollNodeViewController {
controller.modalPresentationStyle = .currentContext

self.present(controller, animated: true, completion: nil)

})
])
}
Expand Down
149 changes: 145 additions & 4 deletions Demo/App/AppSearchViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
// Created by Muukii on 2021/04/14.
//

import UIKit
import FluidPresentation
import TextureSwiftSupport
import UIKit

final class AppSearchViewController: StackScrollNodeViewController {

Expand All @@ -17,12 +18,152 @@ final class AppSearchViewController: StackScrollNodeViewController {

stackScrollNode.append(nodes: [

Components.makeTitleCell(title: "Search"),
Components.makeSelectionCell(
title: "Open VC stacked",
onTap: { [unowned self] in

let other = MenuViewController()
NavigatedFluidViewController(idiom: .presentation, bodyViewController: other)
.fluidContext
.present(from: self, animated: true, completion: nil)

}
)
])
}
}

private final class MenuViewController: DisplayNodeViewController {

private let stackScrollNode = StackScrollNode()

private let child = ChildMenuViewController()

override func viewDidLoad() {
super.viewDidLoad()

if #available(iOS 13.0, *) {
view.backgroundColor = .systemBackground
} else {
view.backgroundColor = .white
}

title = "Menu"

definesPresentationContext = true

stackScrollNode.append(nodes: [

Components.makeTitleCell(title: "Parent"),

Components.makeSelectionCell(
title: "Open in FullScreen",
onTap: { [unowned self] in

let other = MenuViewController()
NavigatedFluidViewController(idiom: .presentation, bodyViewController: other)
.fluidContext
.present(from: self, animated: true, completion: nil)

}
),

Components.makeSelectionCell(
title: "Open in Context",
onTap: { [unowned self] in

let other = MenuViewController()
NavigatedFluidViewController(idiom: .presentation, bodyViewController: other)
.fluidContext
.present(in: self, animated: true, completion: nil)

}
),
])

child: do {
addChild(child)
child.didMove(toParent: self)
}

}

override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
LayoutSpec {
VStackLayout {
stackScrollNode
.flexBasis(fraction: 0.5)
child.node
.flexGrow(1)
}
}
}

}

private final class ChildMenuViewController: DisplayNodeViewController {

private let stackScrollNode = StackScrollNode()

override func viewDidLoad() {
super.viewDidLoad()

if #available(iOS 13.0, *) {
view.backgroundColor = .systemBackground
} else {
view.backgroundColor = .white
}

title = "Menu"

definesPresentationContext = true

stackScrollNode.append(nodes: [

Components.makeTitleCell(title: "Child"),

Components.makeSelectionCell(
title: "Open in FullScreen",
onTap: { [unowned self] in

let other = MenuViewController()
NavigatedFluidViewController(idiom: .presentation, bodyViewController: other)
.fluidContext
.present(from: self, animated: true, completion: nil)

}
),

Components.makeSelectionCell(
title: "Open in Context",
onTap: { [unowned self] in

Components.makeSelectionCell(title: "Open", onTap: {
let other = MenuViewController()
NavigatedFluidViewController(idiom: .presentation, bodyViewController: other)
.fluidContext
.present(in: self, animated: true, completion: nil)

}
),

})
Components.makeSelectionCell(
title: "Open in Context Default",
onTap: { [unowned self] in

let other = MenuViewController()
other.modalPresentationStyle = .currentContext
self.present(other, animated: true, completion: nil)

}
),
])

}

override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
LayoutSpec {
stackScrollNode
}
}

}
5 changes: 5 additions & 0 deletions Demo/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct ContentView: View {
case pushNavigationBar
case pushInCurrentContext
case present
case presentOverFullScreen
case presentInCurrentContext
case presentInOverCurrentContext
case makePresentationContext(Bool)
Expand Down Expand Up @@ -90,6 +91,10 @@ struct ContentView: View {
onAction(.present)
}

Button("Present - OverFullScreen") {
onAction(.presentOverFullScreen)
}

Button("Present - CurrentContext") {
onAction(.presentInCurrentContext)
}
Expand Down
5 changes: 5 additions & 0 deletions Demo/NavigationSampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ final class NavigationSampleViewController: NavigatedFluidViewController {
let controller = SampleViewController()
controller.setIdiom(.presentation)
present(controller, animated: true, completion: nil)
case .presentOverFullScreen:
let controller = SampleViewController()
controller.setIdiom(.presentation)
controller.modalPresentationStyle = .overFullScreen
present(controller, animated: true, completion: nil)
case .presentInCurrentContext:
let controller = SampleViewController()
controller.setIdiom(.presentation)
Expand Down
5 changes: 5 additions & 0 deletions Demo/SampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ final class SampleViewController: FluidViewController {
let controller = SampleViewController()
controller.setIdiom(.presentation)
present(controller, animated: true, completion: nil)
case .presentOverFullScreen:
let controller = SampleViewController()
controller.setIdiom(.presentation)
controller.modalPresentationStyle = .overFullScreen
present(controller, animated: true, completion: nil)
case .presentInCurrentContext:
let controller = SampleViewController()
controller.modalPresentationStyle = .currentContext
Expand Down
8 changes: 8 additions & 0 deletions FluidPresentation/FluidViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ open class FluidViewController: UIViewController, UIViewControllerTransitioningD
open override func viewDidLoad() {
super.viewDidLoad()

view.accessibilityIdentifier = "\(type(of: self))"

setupGestures()

if let bodyViewController = bodyViewController {
Expand All @@ -190,6 +192,12 @@ open class FluidViewController: UIViewController, UIViewControllerTransitioningD
}
}

open override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

Log.debug(.transition, "ViewDidAppear \(self), presenting: \(self.presentingViewController as Any)")
}

/// Set presenting and dismissing transition according to the idiom
/// - Parameter idiom:
public func setIdiom(_ idiom: Idiom) {
Expand Down
1 change: 1 addition & 0 deletions FluidPresentation/NavigatedFluidViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ open class NavigatedFluidViewController: FluidViewController, UINavigationBarDel
open override func viewDidLoad() {
super.viewDidLoad()

view.clipsToBounds = true
view.addSubview(navigationBar)

navigationBar.translatesAutoresizingMaskIntoConstraints = false
Expand Down
43 changes: 37 additions & 6 deletions FluidPresentation/TransitionControllers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,23 @@ enum PresentingTransitionControllers {

transitionContext.logDebug()

let toView = transitionContext.view(forKey: .to)!
let fromViewController = transitionContext.viewController(forKey: .from)!
let toViewController = transitionContext.viewController(forKey: .to)!

let fromView = fromViewController.view!
let toView = toViewController.view!

switch transitionContext.presentationStyle {
case .overFullScreen, .overCurrentContext:
assert(fromView.superview != nil)
default:
transitionContext.containerView.addSubview(fromView)
}

transitionContext.containerView.addSubview(toView)

toView.frame = transitionContext.finalFrame(for: toViewController)

toView.transform = .init(translationX: 0, y: toView.bounds.height)

let animator = UIViewPropertyAnimator(duration: 0.55, dampingRatio: 1) {
Expand Down Expand Up @@ -176,6 +189,17 @@ enum PresentingTransitionControllers {
let toView = toViewController.view!

transitionContext.containerView.backgroundColor = .white

var restoreForFromView: ((Bool) -> Void)? = nil

switch transitionContext.presentationStyle {
case .overFullScreen, .overCurrentContext:
assert(fromView.superview != nil)
restoreForFromView = resorationHierarchyForDismissing(toView: fromView)
default:
break
}

transitionContext.containerView.addSubview(fromView)
transitionContext.containerView.addSubview(toView)

Expand Down Expand Up @@ -212,6 +236,7 @@ enum PresentingTransitionControllers {
animator.addCompletion { _ in
restoration()
transitionContext.completeTransition(true)
restoreForFromView?(true)
}

animator.startAnimation()
Expand All @@ -234,20 +259,26 @@ enum DismissingTransitionControllers {

transitionContext.logDebug()

let fromView = transitionContext.viewController(forKey: .from)!.view!
let toView = transitionContext.viewController(forKey: .to)!.view!
let fromViewController = transitionContext.viewController(forKey: .from)!
let toViewController = transitionContext.viewController(forKey: .to)!

let restore = resorationHierarchyForDismissing(toView: toView)
let fromView = fromViewController.view!
let toView = toViewController.view!

switch transitionContext.presentationStyle {
case .overFullScreen, .overCurrentContext:
assert(toView.superview != nil)
default:
transitionContext.containerView.addSubview(toView)
}

transitionContext.containerView.addSubview(toView)
transitionContext.containerView.addSubview(fromView)

let animator = UIViewPropertyAnimator(duration: 0.55, dampingRatio: 1) {
fromView.transform = .init(translationX: 0, y: fromView.bounds.height)
}

animator.addCompletion { _ in
restore(true)
transitionContext.completeTransition(true)
}

Expand Down