Skip to content

Commit

Permalink
Merge branch 'main' of github.com:shaps80/SwiftUIBackports
Browse files Browse the repository at this point in the history
  • Loading branch information
shaps80 committed Apr 26, 2024
2 parents 673b26c + 72f75c6 commit 6c7bc33
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/shaps80/SwiftBackports",
"state" : {
"revision" : "fafbeabf78b7e364abbbb7565cdfeee42af16211",
"version" : "1.0.2"
"revision" : "ddca6a237c1ba2291d5a3cc47ec8480ce6e9f805",
"version" : "1.0.3"
}
}
],
Expand Down
10 changes: 5 additions & 5 deletions Sources/SwiftUIBackports/Shared/Task/Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,22 @@ private struct TaskModifier<ID: Equatable>: ViewModifier {
var action: @Sendable () async -> Void

@State private var task: Task<Void, Never>?
@State private var oldID: ID
@State private var publisher = PassthroughSubject<(), Never>()

init(id: ID, priority: TaskPriority, action: @Sendable @escaping () async -> Void) {
self.id = id
self.priority = priority
self.action = action
_oldID = .init(initialValue: id)
}

func body(content: Content) -> some View {
content
.onReceive(Just(id)) { newID in
guard newID != oldID else { return }
.backport.onChange(of: id) { _ in
publisher.send()
}
.onReceive(publisher) { _ in
task?.cancel()
task = Task(priority: priority, operation: action)
oldID = newID
}
.onAppear {
task?.cancel()
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftUIBackports/iOS/FocusState/ViewFocused.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private final class Coordinator: NSObject, ObservableObject, UITextFieldDelegate
func observe(field: UITextField) {
self.field = field

if field.delegate !== self {
if field.delegate !== self && _delegate == nil {
_delegate = field.delegate
field.delegate = self
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftUIBackports/iOS/Presentation/Detents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private extension Backport.Representable {
override func willMove(toParent parent: UIViewController?) {
super.willMove(toParent: parent)
if let controller = parent?.sheetPresentationController {
if controller.delegate !== self {
if controller.delegate !== self && _delegate == nil {
_delegate = controller.delegate
controller.delegate = self
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private extension Backport.Representable {
override func willMove(toParent parent: UIViewController?) {
super.willMove(toParent: parent)
if let controller = parent?.presentationController {
if controller.delegate !== self {
if controller.delegate !== self && _delegate == nil {
_delegate = controller.delegate
controller.delegate = self
}
Expand Down
39 changes: 39 additions & 0 deletions Sources/SwiftUIBackports/iOS/TextEditor/ColorProviders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,39 @@ struct UICachedDeviceRGBColor: ColorProvider {
}
}

struct NamedColor: ColorProvider {
var color: UIColor?

init(provider: Any) {
let mirror = Mirror(reflecting: provider)
if let colorName = mirror.descendant("name") as? String {
let bundle = mirror.descendant("bundle") as? Bundle
color = UIColor(named: colorName, in: bundle, compatibleWith: nil)
}
}
}

struct UICGColor: ColorProvider {
var color: UIColor?

init(provider: Any) {
if let color = provider as? UIColor {
self.color = color
}
}
}

struct NSCFType: ColorProvider {
var color: UIColor?

init(provider: Any) {
let isCGColor = CFGetTypeID(provider as CFTypeRef) == CGColor.typeID
if isCGColor {
color = UIColor(cgColor: provider as! CGColor)
}
}
}

struct UIDynamicCatalogSystemColor: ColorProvider {
var color: UIColor?
}
Expand Down Expand Up @@ -196,6 +229,12 @@ func resolveColorProvider(_ provider: Any) -> ColorProvider? {
return DisplayP3(provider: provider)
case "Resolved":
return UICachedDeviceRGBColor(provider: provider)
case String(describing: NamedColor.self):
return NamedColor(provider: provider)
case String(describing: UICGColor.self):
return UICGColor(provider: provider)
case "__\(String(describing: NSCFType.self))":
return NSCFType(provider: provider)
default:
print("Unhandled color provider: \(String(describing: type(of: provider)))")
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ extension UICollectionViewCell {
}
}

@available(iOS, deprecated: 14)
@available(tvOS, deprecated: 14)
@available(iOS, deprecated: 16)
@available(tvOS, deprecated: 16)
@available(macOS, unavailable)
@available(watchOS, unavailable)
extension Backport where Wrapped: UICollectionViewCell {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ extension UITableViewCell {
}
}

@available(iOS, deprecated: 14)
@available(tvOS, deprecated: 14)
@available(iOS, deprecated: 16)
@available(tvOS, deprecated: 16)
@available(macOS, unavailable)
@available(watchOS, unavailable)
extension Backport where Wrapped: UITableViewCell {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import SwiftUI
/// default styling and content for a content view. The content configuration encapsulates
/// all of the supported properties and behaviors for content view customization.
/// You use the configuration to create the content view.
@available(iOS, deprecated: 14)
@available(tvOS, deprecated: 14)
@available(iOS, deprecated: 16)
@available(tvOS, deprecated: 16)
@available(macOS, unavailable)
@available(watchOS, unavailable)
public protocol BackportUIContentConfiguration {
Expand Down

0 comments on commit 6c7bc33

Please sign in to comment.