Skip to content

Instantly share code, notes, and snippets.

import SwiftUI
@main
public enum SheeKitTestsHostApp {
public static var app = _TestApp()
static func main() {
app.run()
}
}
@edudnyk
edudnyk / SheeImplementation-SheetModifier.swift
Last active October 20, 2021 04:31
Initial sandwich solution implementation in SheeKit
struct SheetModifier<Item, SheetContent>: ViewModifier where Item : Identifiable, SheetContent : View {
@Binding var item: Item?
let presentationStyle: ModalPresentationStyle
let presentedViewControllerParameters: UIViewControllerProxy?
let onDismiss: (() -> Void)?
@ViewBuilder
let content: (Item) -> SheetContent
@State var proxy = UIViewControllerProxy()
func body(content: Content) -> some View {
@edudnyk
edudnyk / SheeImplementation-UIViewControllerRepresentable-updates.swift
Last active October 11, 2021 01:06
Initial sandwich solution implementation in SheeKit
struct SheetPresenterControllerRepresentable<Item>: UIViewControllerRepresentable where Item : Identifiable {
@Binding var item: Item?
@Environment(\.shee_isInteractiveDismissDisabled) private var isInteractiveDismissDisabled
let onDismiss: (() -> Void)?
let sheetHostProvider: (AdaptiveDelegate<Item>, UIViewController, Item, DismissAction) -> SheetHostingController<Item>
let sheetHostUpdater: (AdaptiveDelegate<Item>, UIViewController, Bool, DismissAction) -> Void
func makeCoordinator() -> AdaptiveDelegate<Item> { .init() }
func makeUIViewController(context: Context) -> SheetPresenterController { .init() }
@edudnyk
edudnyk / SheeImplementation-SheetHostingController.swift
Last active October 1, 2021 04:26
Initial sandwich solution implementation in SheeKit
final class SheetHostingController<Item>: UIHostingController<AnyView> where Item : Identifiable {
var itemId: Item.ID?
var item: Item
var onDismiss: (() -> Void)?
init(rootView: AnyView, item: Item) {
self.itemId = item.id
self.item = item
super.init(rootView: rootView)
}
@edudnyk
edudnyk / SheeImplementation-UIViewControllerRepresentable.swift
Last active October 2, 2021 14:43
Initial sandwich solution implementation in SheeKit
final class AdaptiveDelegate<Item>: NSObject, UIPopoverPresentationControllerDelegate, UISheetPresentationControllerDelegate where Item : Identifiable {
weak var sheetHost: SheetHostingController<Item>?
var dismissedByUserCallback: DismissAction?
var isInteractiveDismissDisabled = false
var selectedDetentIdentifierBinding: Binding<UISheetPresentationController.Detent.Identifier?>?
override init() {
super.init()
}
@edudnyk
edudnyk / SheeInterface-Modifiers.swift
Last active October 3, 2021 07:09
The snippet of the public interface provided by SheeKit
public struct DismissAction {
public func callAsFunction()
}
extension EnvironmentValues {
public internal(set) var shee_dismiss: DismissAction
public internal(set) var shee_isPresented: Bool
}
extension View {
@edudnyk
edudnyk / SheeInterface-UIViewControllerProxy.swift
Created October 1, 2021 02:53
The snippet of the public interface provided by SheeKit
public struct UIViewControllerProxy {
public var modalTransitionStyle: UIModalTransitionStyle = .coverVertical
public var modalPresentationCapturesStatusBarAppearance = false
public var disablesAutomaticKeyboardDismissal: Bool?
public var edgesForExtendedLayout: UIRectEdge = .all
public var extendedLayoutIncludesOpaqueBars: Bool = false
public var preferredContentSize: CGSize = .zero
public var preferredStatusBarStyle: UIStatusBarStyle?
public var prefersStatusBarHidden: Bool?
public var preferredStatusBarUpdateAnimation: UIStatusBarAnimation?
@edudnyk
edudnyk / SheeInterface-SheetProperties.swift
Created October 1, 2021 02:52
The snippet of the public interface provided by SheeKit
public struct SheetProperties {
/// Set to true to cause the sheet to layout with an edge-attached appearance in compact height instead of full screen.
/// Default: ``false``
public var prefersEdgeAttachedInCompactHeight: Bool
/// Set to true to allow ``preferredContentSize`` to influence the width of the sheet when edge-attached.
/// When ``false``, the width of the sheet when edge-attached is always equal to the safe area width of the container.
/// The value of this property is not respected in compact width regular height.
/// Default: ``false``
public var widthFollowsPreferredContentSizeWhenEdgeAttached: Bool
@edudnyk
edudnyk / SheeInterface-ModalPresentationStyle.swift
Last active October 1, 2021 02:55
The snippet of the public interface provided by SheeKit
public enum ModalPresentationStyle {
/// The default presentation style chosen by the system.
case automatic
/// A presentation style that partially covers the underlying content.
///
/// - Parameters:
/// - properties: properties to assign to ``UISheetPresentationController``
case pageSheet(properties: SheetProperties? = nil)
/// A presentation style that displays the content centered in the screen.
///
@edudnyk
edudnyk / TestsApp.swift
Last active November 13, 2024 04:51
SwiftUI Easter Eggs: Performance Benchmarking with _ViewTest and more
import SwiftUI
@main
struct App {
static func main() {
_TestApp().runBenchmarks([Benchmark()])
}
}
extension UIHostingController: _Test where Content == AnyView {}