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

New Sheet Style API #101

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
60 changes: 44 additions & 16 deletions Sources/FluidInterfaceKit-Demo/DemoSheetViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private final class ListViewController: CodeBasedViewController {

let controller = DetailViewController()

fluidPush(controller, target: .current, relation: .modality)
fluidPush(controller, target: .current)

print("hey")
}
Expand Down Expand Up @@ -73,27 +73,55 @@ private final class ListViewController: CodeBasedViewController {
}
}

private final class DetailViewController: FluidViewController {
private final class DetailViewController: FluidSheetViewController {

override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = .neon(.purple)
}
}

extension AnyRemovingInteraction {

static var sheet: Self {

return .init(handlers: [
.gestureOnScreen(handler: { gesture, context in

view.backgroundColor = .systemBackground

let horizontalContent = ScrollableContainerView(scrollDirection: .horizontal)

horizontalContent.setContent(AnyView { _ in
HStackBlock(spacing: 8) {
UIView.mock(backgroundColor: .neon(.purple), preferredSize: .init(width: 60, height: 60))
UIView.mock(backgroundColor: .neon(.purple), preferredSize: .init(width: 60, height: 60))
UIView.mock(backgroundColor: .neon(.purple), preferredSize: .init(width: 60, height: 60))
UIView.mock(backgroundColor: .neon(.purple), preferredSize: .init(width: 60, height: 60))
UIView.mock(backgroundColor: .neon(.purple), preferredSize: .init(width: 60, height: 60))
UIView.mock(backgroundColor: .neon(.purple), preferredSize: .init(width: 60, height: 60))
UIView.mock(backgroundColor: .neon(.purple), preferredSize: .init(width: 60, height: 60))
UIView.mock(backgroundColor: .neon(.purple), preferredSize: .init(width: 60, height: 60))
}
})

let verticalContent = ScrollableContainerView(scrollDirection: .vertical)

})
])
verticalContent.setContent(AnyView { _ in
VStackBlock(spacing: 8) {
UIView.mock(backgroundColor: .neon(.purple), preferredSize: .init(width: 60, height: 60))
UIView.mock(backgroundColor: .neon(.purple), preferredSize: .init(width: 60, height: 60))
UIView.mock(backgroundColor: .neon(.purple), preferredSize: .init(width: 60, height: 60))
UIView.mock(backgroundColor: .neon(.purple), preferredSize: .init(width: 60, height: 60))
UIView.mock(backgroundColor: .neon(.purple), preferredSize: .init(width: 60, height: 60))
UIView.mock(backgroundColor: .neon(.purple), preferredSize: .init(width: 60, height: 60))
UIView.mock(backgroundColor: .neon(.purple), preferredSize: .init(width: 60, height: 60))
UIView.mock(backgroundColor: .neon(.purple), preferredSize: .init(width: 60, height: 60))
UIView.mock(backgroundColor: .neon(.purple), preferredSize: .init(width: 60, height: 60))
UIView.mock(backgroundColor: .neon(.purple), preferredSize: .init(width: 60, height: 60))
UIView.mock(backgroundColor: .neon(.purple), preferredSize: .init(width: 60, height: 60))
UIView.mock(backgroundColor: .neon(.purple), preferredSize: .init(width: 60, height: 60))
}
})

Mondrian.buildSubviews(on: view) {
VStackBlock {
horizontalContent

verticalContent
}
.container(respectingSafeAreaEdges: .all)
}
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ extension FluidExtentionViewController {

}

public func fluidPush(
_ viewController: FluidSheetViewController,
target strategy: UIViewController.FluidStackFindStrategy,
transition: AnyAddingTransition? = nil,
completion: ((AddingTransitionContext.CompletionEvent) -> Void)? = nil
) {

fluidPushUnsafely(
viewController,
target: strategy,
transition: transition,
afterViewDidLoad: {}
)

}

public func fluidPush(
_ viewController: FluidPopoverViewController,
target strategy: UIViewController.FluidStackFindStrategy,
Expand Down
81 changes: 81 additions & 0 deletions Sources/FluidInterfaceKit/ViewController/File.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import UIKit

open class FluidSheetViewController: FluidGestureHandlingViewController {

public enum Content {
case viewController(UIViewController)
case view(UIView)
}

public init(
addingTransition: AnyAddingTransition? = nil,
removingTransition: AnyRemovingTransition? = nil
) {

super.init(
content: nil,
addingTransition: addingTransition ?? .sheet,
removingTransition: removingTransition ?? .sheet,
removingInteraction: .sheet
)

fluidStackContentConfiguration.contentType = .overlay

}

open override func viewDidLoad() {
super.viewDidLoad()



}
}

extension AnyAddingTransition {

public static var sheet: Self {
return .modalStyle
}

}

extension AnyRemovingTransition {

public static var sheet: Self {
return .modalStyle
}

}

extension AnyRemovingInteraction {

public static var sheet: Self {

return .init(handlers: [
.gestureOnScreen(handler: { gesture, context in

let targetViewController = context.viewController
let targetView = targetViewController.view!

switch gesture.state {
case .possible:
break
case .began, .changed:
let translation = gesture.translation(in: nil)
targetView.layer.transform = CATransform3DMakeAffineTransform(CGAffineTransform(translationX: 0, y: translation.y))

case .ended:
break
case .cancelled, .failed:
break
@unknown default:
assertionFailure()
break
}

})
])

}

}
2 changes: 1 addition & 1 deletion submodules/CompositionKit