Transmission
repository·main·Indexed 22 days ago
https://github.com/nathantannar4/transmissionA library that bridges UIKit's presentation and transition APIs into a SwiftUI-native interface. It enables advanced features such as presentation controllers, interactive transitions, and UIWindow overlays. Key components include PresentationLink, DestinationLink, WindowLink, ShareSheetLink, and QuickLookPreviewLink, as well as TransitionReader for accessing transition progress and coordinators for programmatic dismissal.
What's inside Transmission
- Transmission is a library designed to improve SwiftUI view presentations and transitions. It bridges UIKit presentation APIs to a SwiftUI-friendly API, enabling the use of presentation controllers, interactive transitions, and other advanced UIKit presentation features within SwiftUI applications.
Access transition progress with TransitionReader
mainUse
TransitionReaderto build interactive presentation and dismissal transitions. It provides a container view that exposes theUIViewControllerTransitionCoordinatorprogress.Inside the
TransitionReaderclosure, you receive aProxyobject containing:progress: ACGFloatfrom 0 to 1 representing the transition state.isPresented: ABoolindicating if the view is currently presented.
TransitionReader { Proxy(progress: progress, isPresented: isPresented) in // Use progress to drive animations or opacity MyView() .opacity(progress) }Requirements for Transmission
mainTo use Transmission, ensure your project meets the following requirements:
- Deployment Targets:
- iOS 13.0+
- macOS 10.15+
- tvOS 13.0+
- watchOS 6.0+
- visionOS 1.0+
- Xcode Version: 16.4+
- Deployment Targets:
Install Transmission in Xcode Projects
mainTo add Transmission to an existing Xcode project:
- Open your project in Xcode.
- Select
File->Swift Packages->Add Package Dependency. - Enter the repository URL:
https://github.com/nathantannar4/Transmission.
Install Transmission in Swift Package Manager Projects
mainAdd
Transmissionas a dependency in yourPackage.swiftfile by adding the URL to yourdependenciesarray and referencing theTransmissionproduct in your target dependencies.let package = Package( //... dependencies: [ .package(url: "https://github.com/nathantannar4/Transmission"), ], targets: [ .target( name: "YourPackageTarget", dependencies: [ .product(name: "Transmission", package: "Transmission"), ], //... ), //... ], //... )Configure Status Bar style and visibility
mainTransmission provides view modifiers to control the status bar of the hosting
UIViewController:preferredStatusBarStyle(_:): Sets theUIStatusBarStyle.prefersStatusBarHidden(_:): Sets whether the status bar is hidden.
MyView() .preferredStatusBarStyle(.light) .prefersStatusBarHidden(true)Programmatically dismiss views with Coordinators
mainTransmission provides coordinators to programmatically control dismissal from within the view hierarchy via the
Environment.PresentationCoordinator (for
PresentationLink):dismiss(count:animation:): Dismisses a specified number of presented views.dismiss(count:transaction:): Dismisses with a specific transaction.- Access via
@Environment(\.presentationCoordinator).
DestinationCoordinator (for
DestinationLink):pop(count:animation:): Pops a specified number of views from the navigation stack.pop(count:transaction:): Pops with a specific transaction.- Access via
@Environment(\.destinationCoordinator).
struct MySubView: View { @Environment(\.presentationCoordinator) var coordinator var body: some View { Button("Dismiss") { coordinator.dismiss(count: 1) } } }Preview files with QuickLookPreviewLink
mainUse
QuickLookPreviewLinkto present aQLPreviewControllerfor quick look previews.QuickLookPreviewItem:
- Requires a
URLand an optionalTextlabel.
Usage:
- Pass
items: [QuickLookPreviewItem]to the link. - Pass a
url: URLdirectly to the link. - Use the
.quickLookPreview(...)view modifier.
// Using a URL directly QuickLookPreviewLink(url: myFileURL) label: { Text("Preview") } // Using the .quickLookPreview modifier MyView() .quickLookPreview(url: myFileURL, isPresented: $isShowing)- Requires a
Present views in a new UIWindow with WindowLink
mainUse
WindowLinkto present a destination view in a completely newUIWindow. This is useful for overlays or alerts that need to exist outside the main view hierarchy.WindowLinkLevel:
.default.overlay.background.alert.custom(CGFloat)
WindowLinkTransition:
.identity.opacity.move(edge: Edge).scale(CGFloat).combined(with: WindowLinkTransition)
You can also use the
.window(...)view modifier.// Using the WindowLink view WindowLink(level: .alert, transition: .opacity) { MyOverlayView() } label: { Text("Show Alert Window") } // Using the .window modifier MyView() .window(isPresented: $isShowing, level: .overlay, transition: .scale(1.2)) { MyOverlayView() }Push views with DestinationLink
mainUse
DestinationLinkto create a button that pushes a destination view onto a navigation stack (usingUINavigationController). You can specify a transition style usingDestinationLinkTransition.Available transitions include:
.default.zoom(iOS 18.0+).custom(_:)for implementingDestinationLinkTransitionRepresentable.
You can also use the
.destination(...)view modifier to push views based on a binding.// Using the DestinationLink view DestinationLink(transition: .default) { MyDestinationView() } label: { Text("Push View") } // Using the .destination modifier MyView() .destination(isPresented: $isShowing) { MyDestinationView() }Show Share Sheets with ShareSheetLink
mainUse
ShareSheetLinkto present aUIActivityViewController. To provide items to the share sheet, implement theShareSheetItemProviderprotocol.Supported Item Providers:
String(via extension)URL(via extension)SnapshotItemProvider<Content>(for sharing a view as an image).
You can also use the
.share(...)view modifier orShareSheetLinkModifier.// Sharing a URL ShareSheetLink(items: [myURL]) { Text("Share Link") } // Using the .share modifier MyView() .share(items: [myString], isPresented: $isShowing)Present views with PresentationLink
mainUse
PresentationLinkto create a button that presents a destination view in a newUIViewController. You can specify a transition style usingPresentationLinkTransition.Available transitions include:
.default.sheet.currentContext.fullscreen.popover.slide.card.zoom(iOS 18.0+).matchedGeometry.toast.custom(_:)for implementingPresentationLinkTransitionRepresentable.
You can also use the
.presentation(...)view modifier to present views based on a binding.// Using the PresentationLink view PresentationLink(transition: .sheet) { MyDestinationView() } label: { Text("Open Sheet") } // Using the .presentation modifier MyView() .presentation(isPresented: $isShowing, transition: .card) { MyDestinationView() }