11import ExpoModulesCore
22import UIKit
33
4- /// Reports the body geometry of a native navigation column.
4+ /// Reports geometry in the observing view's coordinate space, including system
5+ /// reservations that safe-area rectangles cannot represent, such as the fold.
56final class T3LayoutMetricsView : ExpoView {
67 let onMetricsChange = EventDispatcher ( )
78 private var lastMetrics : NSDictionary ?
9+ private var hasHinge : Bool ? = false
810
911 required init ( appContext : AppContext ? = nil ) {
1012 super . init ( appContext : appContext )
1113 isUserInteractionEnabled = false
1214 registerForTraitChanges ( [ UITraitHorizontalSizeClass . self , UITraitVerticalSizeClass . self ] ) { ( view : T3LayoutMetricsView , _ : UITraitCollection ) in
1315 view . publishMetrics ( )
1416 }
17+ #if compiler( >= 6 . 4 )
18+ if #available( iOS 27 . 1 , * ) {
19+ hasHinge = nil
20+ addInteraction ( UIHingeInteraction { [ weak self ] _ , update in
21+ guard let self , self . window != nil else { return }
22+ // Capability survives temporary detachment and does not follow the hinge angle.
23+ let hasHinge = self . hasHinge == true || update . hinge != nil
24+ guard self . hasHinge != hasHinge else { return }
25+ self . hasHinge = hasHinge
26+ self . publishMetrics ( )
27+ } )
28+ registerForTraitChanges ( UITraitCollection . systemTraitsAffectingVerticalBarEdge ) { ( view : T3LayoutMetricsView , _ : UITraitCollection ) in
29+ view . publishMetrics ( )
30+ }
31+ }
32+ #endif
1533 }
1634
1735 override func didMoveToWindow ( ) {
@@ -31,14 +49,43 @@ final class T3LayoutMetricsView: ExpoView {
3149 }
3250
3351 private func publishMetrics ( ) {
34- guard window != nil , bounds . width > 0 , bounds . height > 0 else { return }
52+ guard let window , bounds . width > 0 , bounds . height > 0 , let hasHinge else { return }
53+ if hasHinge {
54+ T3WorkspaceOrientationSubscriber . allowHingeOrientations ( in : window )
55+ }
56+ var verticalBarEdge = " none "
57+ var regions : [ [ String : Any ] ] = [ ]
58+ #if compiler( >= 6 . 4 )
59+ if #available( iOS 27 . 1 , * ) {
60+ let rtl = effectiveUserInterfaceLayoutDirection == . rightToLeft
61+ switch traitCollection . verticalBarEdge {
62+ case . leading : verticalBarEdge = rtl ? " right " : " left "
63+ case . trailing : verticalBarEdge = rtl ? " left " : " right "
64+ default : break
65+ }
66+ for kind in [ UIView . ReservedRegion . Kind . division , . occlusion ] {
67+ for region in reservedRegions ( kind : kind ) where region . isActive {
68+ let frame = region . frame . intersection ( bounds )
69+ guard ! frame . isNull , ! frame . isEmpty else { continue }
70+ regions . append ( [
71+ " kind " : kind == . division ? " division " : " occlusion " ,
72+ " x " : frame . minX , " y " : frame . minY ,
73+ " width " : frame . width , " height " : frame . height ,
74+ ] )
75+ }
76+ }
77+ }
78+ #endif
3579 let metrics : [ String : Any ] = [
3680 " width " : bounds . width , " height " : bounds . height ,
81+ " hasHinge " : hasHinge ,
3782 " horizontalSizeClass " : traitCollection . horizontalSizeClass == . regular ? " regular " : " compact " ,
83+ " verticalBarEdge " : verticalBarEdge ,
3884 " safeArea " : [
3985 " top " : safeAreaInsets . top , " bottom " : safeAreaInsets . bottom ,
4086 " left " : safeAreaInsets . left , " right " : safeAreaInsets . right ,
4187 ] ,
88+ " reservedRegions " : regions ,
4289 ]
4390 let next = metrics as NSDictionary
4491 guard lastMetrics ? . isEqual ( next ) != true else { return }
0 commit comments