mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-08 01:43:07 +00:00
* fix(ios): mark attachment localization key manual * fix(ios): guard hinge probe on Mac Catalyst
39 lines
1.2 KiB
Swift
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) {}
|
|
}
|