Skip to content

Commit

Permalink
Fix onPreferenceChange modifier on Xcode 16.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Calculable committed Dec 13, 2024
1 parent 7edaf15 commit f96a75c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct UBPopupPreferenceKey: PreferenceKey {
}
}

@MainActor
struct UBPopupPreference: Equatable {
let id = UUID()
let isPresented: Binding<Bool>
Expand All @@ -36,7 +37,7 @@ struct UBPopupPreference: Equatable {
self.content = content
}

static func == (lhs: UBPopupPreference, rhs: UBPopupPreference) -> Bool {
nonisolated static func == (lhs: UBPopupPreference, rhs: UBPopupPreference) -> Bool {
lhs.id == rhs.id
&& lhs.isPresented.wrappedValue == rhs.isPresented.wrappedValue
&& lhs.date == rhs.date
Expand Down
2 changes: 1 addition & 1 deletion Sources/UBUserInterface/SwiftUI/Popup/UBPopupStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import SwiftUI

public struct UBPopupStyle: Equatable {
public struct UBPopupStyle: Equatable, Sendable {
let extendsToEdges: Bool
let backgroundColor: Color
let backdropColor: Color
Expand Down
10 changes: 6 additions & 4 deletions Sources/UBUserInterface/SwiftUI/Popup/UBPopupWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ public struct UBPopupWrapper<V: View>: View {
UBPopupWindowManager.shared.setupWindow()
}
.onPreferenceChange(UBPopupPreferenceKey.self) { popupPreference in
if let popupPreference, popupPreference.isPresented.wrappedValue {
UBPopupWindowManager.shared.showPopup(isPresented: popupPreference.isPresented, style: popupPreference.customStyle ?? style, content: popupPreference.content)
} else {
UBPopupWindowManager.shared.hideWindow()
DispatchQueue.main.async {
if let popupPreference, popupPreference.isPresented.wrappedValue {
UBPopupWindowManager.shared.showPopup(isPresented: popupPreference.isPresented, style: popupPreference.customStyle ?? style, content: popupPreference.content)
} else {
UBPopupWindowManager.shared.hideWindow()
}
}
}
}
Expand Down

0 comments on commit f96a75c

Please sign in to comment.