Skip to content

Commit

Permalink
0.1.23
Browse files Browse the repository at this point in the history
  • Loading branch information
nathantannar4 committed Jul 21, 2023
1 parent 30cc0c3 commit 974519f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 26 deletions.
45 changes: 32 additions & 13 deletions Sources/Transmission/Sources/DestinationLinkModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,6 @@ private struct DestinationLinkModifierBody<

context.coordinator.isPresented = isPresented

let isPresented = Binding<Bool>(
get: { true },
set: { newValue, transaction in
if !newValue {
let isAnimated = transaction.isAnimated || DestinationCoordinator.transaction.isAnimated
context.coordinator.adapter?.viewController._popViewController(animated: isAnimated) {
DestinationCoordinator.transaction = nil
}
}
}
)

let isAnimated = context.transaction.isAnimated || (presentingViewController.transitionCoordinator?.isAnimated ?? false)
context.coordinator.isAnimated = isAnimated

Expand Down Expand Up @@ -497,13 +485,15 @@ private class DestinationLinkDestinationViewControllerAdapter<Destination: View>
context: context
)
} else {
self.viewController = DestinationController(
let viewController = DestinationController(
content: destination.modifier(
DestinationBridgeAdapter(
isPresented: isPresented
)
)
)
transition.update(viewController)
self.viewController = viewController
}
}

Expand All @@ -524,6 +514,21 @@ private class DestinationLinkDestinationViewControllerAdapter<Destination: View>
isPresented: Binding<Bool>,
context: DestinationLinkModifierBody<Destination>.Context
) {
let transaction = context.transaction
let isPresented = Binding<Bool>(
get: { true },
set: { [weak viewController] newValue, transaction in
if !newValue, let viewController = viewController {
let isAnimated = transaction.isAnimated
|| viewController.transitionCoordinator?.isAnimated == true
|| DestinationCoordinator.transaction.isAnimated
viewController._popViewController(animated: isAnimated) {
DestinationCoordinator.transaction = nil
}
}
}
)

if let conformance = conformance {
var visitor = Visitor(
destination: destination,
Expand All @@ -539,6 +544,7 @@ private class DestinationLinkDestinationViewControllerAdapter<Destination: View>
isPresented: isPresented
)
)
transition.update(viewController)
}
}

Expand Down Expand Up @@ -645,4 +651,17 @@ private class DestinationLinkDestinationViewControllerAdapter<Destination: View>
}
}

@available(iOS 14.0, *)
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
extension DestinationLinkTransition.Value {

func update<Content: View>(_ viewController: HostingController<Content>) {

viewController.view.backgroundColor = options.preferredPresentationBackgroundUIColor ?? .systemBackground
}
}


#endif
17 changes: 16 additions & 1 deletion Sources/Transmission/Sources/DestinationLinkTransition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,26 @@ extension DestinationLinkTransition {
public struct Options {
/// When `true`, the destination will be dismissed when the presentation source is dismantled
public var shouldAutomaticallyDismissDestination: Bool
public var preferredPresentationBackgroundColor: Color?

public init(
shouldAutomaticallyDismissDestination: Bool = true
shouldAutomaticallyDismissDestination: Bool = true,
preferredPresentationBackgroundColor: Color? = nil
) {
self.shouldAutomaticallyDismissDestination = shouldAutomaticallyDismissDestination
self.preferredPresentationBackgroundColor = preferredPresentationBackgroundColor
}

var preferredPresentationBackgroundUIColor: UIColor? {
guard let color = preferredPresentationBackgroundColor else {
return nil
}
// Need to extract the UIColor since because SwiftUI's UIColor init
// from a Color does not work for dynamic colors when set on UIView's
let uiColor = Mirror(reflecting: color).children.lazy.compactMap({ child in
Mirror(reflecting: child.value).children.first?.value as? UIColor
}).first
return uiColor ?? UIColor(color)
}
}
}
Expand Down
26 changes: 14 additions & 12 deletions Sources/Transmission/Sources/PresentationLinkModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,6 @@ private struct PresentationLinkModifierBody<
UITraitCollection(userInterfaceLevel: .elevated)
])

let isPresented = Binding<Bool>(
get: { true },
set: { newValue, transaction in
if !newValue {
let isAnimated = transaction.isAnimated || PresentationCoordinator.transaction.isAnimated
context.coordinator.adapter?.viewController?.dismiss(animated: isAnimated) {
PresentationCoordinator.transaction = nil
}
}
}
)

let isAnimated = context.transaction.isAnimated || (presentingViewController.transitionCoordinator?.isAnimated ?? false)
context.coordinator.isAnimated = isAnimated
if let adapter = context.coordinator.adapter,
Expand Down Expand Up @@ -859,6 +847,20 @@ private class PresentationLinkDestinationViewControllerAdapter<
sourceView: UIView,
context: PresentationLinkModifierBody<Destination>.Context
) {
let transaction = context.transaction
let isPresented = Binding<Bool>(
get: { true },
set: { [weak viewController] newValue, transaction in
if !newValue, let viewController = viewController {
let isAnimated = transaction.isAnimated
|| viewController.transitionCoordinator?.isAnimated == true
|| PresentationCoordinator.transaction.isAnimated
viewController.dismiss(animated: isAnimated) {
PresentationCoordinator.transaction = nil
}
}
}
)
if let conformance = conformance {
var visitor = Visitor(
destination: destination,
Expand Down

0 comments on commit 974519f

Please sign in to comment.