Files
hapi/ios/Hapi/Features/Home/FoldableDevice.swift
T
AnanovoandGitHub 8e2b7ab80c fix(ios): unblock Mac Catalyst builds (#2275)
* fix(ios): mark attachment localization key manual

* fix(ios): guard hinge probe on Mac Catalyst
2026-11-04 14:48:14 +08:00

39 lines
1.2 KiB
Swift

import Observation
import SwiftUI
import UIKit
/// Whether this phone has a hinge (iPhone Duo) and can unfold to a
/// tablet-width display. UIKit reports hinges only asynchronously through
/// `UIHingeInteraction`, so this starts false and latches true for the
/// process; a nil update only means the probe left its hierarchy.
@MainActor @Observable
final class FoldableDevice {
static let shared = FoldableDevice()
private(set) var hasHinge = false
func recordHinge() {
if !hasHinge { hasHinge = true }
}
}
/// Invisible view that reports a hinge to `FoldableDevice.shared`.
struct HingeProbe: UIViewRepresentable {
func makeUIView(context: Context) -> UIView {
let view = UIView()
view.isUserInteractionEnabled = false
#if !targetEnvironment(macCatalyst)
// UIHingeInteraction is unavailable in the Mac Catalyst SDK; hinge
// detection is only meaningful on iPhone and iPad.
if #available(iOS 27.1, *) {
view.addInteraction(UIHingeInteraction { _, update in
if update.hinge != nil { FoldableDevice.shared.recordHinge() }
})
}
#endif
return view
}
func updateUIView(_ uiView: UIView, context: Context) {}
}