mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-10-31 16:24:11 +00:00
Fix photo picker selection tint on iOS 26
On iOS 26 the picker's remote process samples the window's tint color when it connects, ignoring the view-level override, which left the selection badges white on grey in dark mode. Temporarily override the window tint while the picker is presented and restore it when picking finishes or the picker is dismantled.
This commit is contained in:
@@ -50,9 +50,19 @@ struct PhotoLibraryPicker: UIViewControllerRepresentable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func updateUIViewController(_ uiViewController: PHPickerViewController, context: Context) {
|
func updateUIViewController(_ uiViewController: PHPickerViewController, context: Context) {
|
||||||
// Override the app wide tint color (currently set to `.compound.texActionPrimary
|
// Override the app wide tint color (currently set to `.compound.texActionPrimary`)
|
||||||
// as it's not legible enough in dark mode
|
// as it's not legible enough in dark mode
|
||||||
uiViewController.view.tintColor = .compound.textActionAccent
|
uiViewController.view.tintColor = .compound.textActionAccent
|
||||||
|
|
||||||
|
// On iOS 26 the picker reads the window's tint instead so we need
|
||||||
|
// to make this workaround to override the window tint
|
||||||
|
DispatchQueue.main.async { [coordinator = context.coordinator] in
|
||||||
|
coordinator.overrideWindowTint(of: uiViewController)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static func dismantleUIViewController(_ uiViewController: PHPickerViewController, coordinator: Coordinator) {
|
||||||
|
coordinator.restoreWindowTint()
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeCoordinator() -> Coordinator {
|
func makeCoordinator() -> Coordinator {
|
||||||
@@ -62,15 +72,32 @@ struct PhotoLibraryPicker: UIViewControllerRepresentable {
|
|||||||
final class Coordinator: NSObject, PHPickerViewControllerDelegate {
|
final class Coordinator: NSObject, PHPickerViewControllerDelegate {
|
||||||
private var photoLibraryPicker: PhotoLibraryPicker
|
private var photoLibraryPicker: PhotoLibraryPicker
|
||||||
|
|
||||||
|
private weak var overriddenWindow: UIWindow?
|
||||||
|
private var originalWindowTint: UIColor?
|
||||||
|
|
||||||
init(_ photoLibraryPicker: PhotoLibraryPicker) {
|
init(_ photoLibraryPicker: PhotoLibraryPicker) {
|
||||||
self.photoLibraryPicker = photoLibraryPicker
|
self.photoLibraryPicker = photoLibraryPicker
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func overrideWindowTint(of pickerViewController: PHPickerViewController) {
|
||||||
|
guard overriddenWindow == nil, let window = pickerViewController.view.window else { return }
|
||||||
|
overriddenWindow = window
|
||||||
|
originalWindowTint = window.tintColor
|
||||||
|
window.tintColor = .compound.textActionAccent
|
||||||
|
}
|
||||||
|
|
||||||
|
func restoreWindowTint() {
|
||||||
|
overriddenWindow?.tintColor = originalWindowTint
|
||||||
|
overriddenWindow = nil
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: PHPickerViewControllerDelegate
|
// MARK: PHPickerViewControllerDelegate
|
||||||
|
|
||||||
private static let loadingIndicatorIdentifier = "\(PhotoLibraryPicker.self)-Loading"
|
private static let loadingIndicatorIdentifier = "\(PhotoLibraryPicker.self)-Loading"
|
||||||
|
|
||||||
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
|
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
|
||||||
|
restoreWindowTint()
|
||||||
|
|
||||||
guard !results.isEmpty else {
|
guard !results.isEmpty else {
|
||||||
photoLibraryPicker.callback(.cancel)
|
photoLibraryPicker.callback(.cancel)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user