@expo/ui 58.0.22 → 58.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/android/build.gradle +2 -2
  3. package/android/src/main/java/expo/modules/ui/ComposeViews.kt +53 -29
  4. package/android/src/main/java/expo/modules/ui/ExpoUIModule.kt +6 -4
  5. package/android/src/main/java/expo/modules/ui/HostView.kt +85 -15
  6. package/android/src/main/java/expo/modules/ui/ModifierRegistry.kt +40 -12
  7. package/android/src/main/java/expo/modules/ui/RNHostView.kt +138 -2
  8. package/android/src/main/java/expo/modules/ui/SliderView.kt +5 -4
  9. package/android/src/main/java/expo/modules/ui/UniversalLayout.kt +610 -0
  10. package/android/src/main/java/expo/modules/ui/VerticalSliderView.kt +5 -4
  11. package/android/src/main/java/expo/modules/ui/state/ObservableState.kt +2 -0
  12. package/android/src/main/java/expo/modules/ui/state/WorkletCallback.kt +2 -0
  13. package/build/community/bottom-sheet/BottomSheet.android.js +2 -0
  14. package/build/community/bottom-sheet/BottomSheet.android.js.map +1 -1
  15. package/build/community/menu/MenuView.ios.js +2 -1
  16. package/build/community/menu/MenuView.ios.js.map +1 -1
  17. package/build/jetpack-compose/Column/index.d.ts +5 -0
  18. package/build/jetpack-compose/Column/index.js.map +1 -1
  19. package/build/jetpack-compose/Row/index.d.ts +5 -0
  20. package/build/jetpack-compose/Row/index.js.map +1 -1
  21. package/build/jetpack-compose/Text/index.js +5 -4
  22. package/build/jetpack-compose/Text/index.js.map +1 -1
  23. package/build/recycling/useRecycledRows.d.ts +2 -0
  24. package/build/recycling/useRecycledRows.js +1 -0
  25. package/build/recycling/useRecycledRows.js.map +1 -1
  26. package/build/swift-ui/ContentUnavailableView/index.d.ts +5 -0
  27. package/build/swift-ui/ContentUnavailableView/index.js +7 -2
  28. package/build/swift-ui/ContentUnavailableView/index.js.map +1 -1
  29. package/build/swift-ui/HStack/index.d.ts +6 -0
  30. package/build/swift-ui/HStack/index.js.map +1 -1
  31. package/build/swift-ui/RNHostView.d.ts +7 -1
  32. package/build/swift-ui/RNHostView.js +2 -1
  33. package/build/swift-ui/RNHostView.js.map +1 -1
  34. package/build/swift-ui/Text/index.js +2 -1
  35. package/build/swift-ui/Text/index.js.map +1 -1
  36. package/build/swift-ui/VStack/index.d.ts +6 -0
  37. package/build/swift-ui/VStack/index.js.map +1 -1
  38. package/build/swift-ui/modifiers/index.d.ts +18 -0
  39. package/build/swift-ui/modifiers/index.js +9 -0
  40. package/build/swift-ui/modifiers/index.js.map +1 -1
  41. package/build/universal/BottomSheet/index.android.js +5 -5
  42. package/build/universal/BottomSheet/index.android.js.map +1 -1
  43. package/build/universal/Button/index.android.js +3 -1
  44. package/build/universal/Button/index.android.js.map +1 -1
  45. package/build/universal/Button/index.ios.js +3 -1
  46. package/build/universal/Button/index.ios.js.map +1 -1
  47. package/build/universal/Collapsible/index.ios.js +1 -0
  48. package/build/universal/Collapsible/index.ios.js.map +1 -1
  49. package/build/universal/Column/index.android.js +4 -1
  50. package/build/universal/Column/index.android.js.map +1 -1
  51. package/build/universal/Column/index.ios.js +2 -0
  52. package/build/universal/Column/index.ios.js.map +1 -1
  53. package/build/universal/Column/index.js +13 -4
  54. package/build/universal/Column/index.js.map +1 -1
  55. package/build/universal/FieldGroup/FieldGroup.android.js +3 -1
  56. package/build/universal/FieldGroup/FieldGroup.android.js.map +1 -1
  57. package/build/universal/FieldGroup/FieldGroup.ios.js +3 -1
  58. package/build/universal/FieldGroup/FieldGroup.ios.js.map +1 -1
  59. package/build/universal/FieldGroup/FieldSection.android.js +13 -4
  60. package/build/universal/FieldGroup/FieldSection.android.js.map +1 -1
  61. package/build/universal/FieldGroup/FieldSection.ios.js +3 -1
  62. package/build/universal/FieldGroup/FieldSection.ios.js.map +1 -1
  63. package/build/universal/Icon/index.android.js +3 -1
  64. package/build/universal/Icon/index.android.js.map +1 -1
  65. package/build/universal/Icon/index.ios.js +3 -1
  66. package/build/universal/Icon/index.ios.js.map +1 -1
  67. package/build/universal/List/ListForEach.android.d.ts +7 -0
  68. package/build/universal/List/ListForEach.android.js +6 -0
  69. package/build/universal/List/ListForEach.android.js.map +1 -0
  70. package/build/universal/List/ListForEach.d.ts +5 -0
  71. package/build/universal/List/ListForEach.ios.d.ts +5 -0
  72. package/build/universal/List/ListForEach.ios.js +11 -0
  73. package/build/universal/List/ListForEach.ios.js.map +1 -0
  74. package/build/universal/List/ListForEach.js +263 -0
  75. package/build/universal/List/ListForEach.js.map +1 -0
  76. package/build/universal/List/ListScrollContext.d.ts +5 -0
  77. package/build/universal/List/ListScrollContext.js +6 -0
  78. package/build/universal/List/ListScrollContext.js.map +1 -0
  79. package/build/universal/List/index.android.d.ts +5 -0
  80. package/build/universal/List/index.android.js +3 -0
  81. package/build/universal/List/index.android.js.map +1 -1
  82. package/build/universal/List/index.d.ts +5 -0
  83. package/build/universal/List/index.ios.d.ts +5 -0
  84. package/build/universal/List/index.ios.js +3 -0
  85. package/build/universal/List/index.ios.js.map +1 -1
  86. package/build/universal/List/index.js +12 -1
  87. package/build/universal/List/index.js.map +1 -1
  88. package/build/universal/List/types.d.ts +42 -1
  89. package/build/universal/List/types.js +1 -3
  90. package/build/universal/List/types.js.map +1 -1
  91. package/build/universal/RNHostView/index.android.js +3 -1
  92. package/build/universal/RNHostView/index.android.js.map +1 -1
  93. package/build/universal/Row/index.android.js +4 -1
  94. package/build/universal/Row/index.android.js.map +1 -1
  95. package/build/universal/Row/index.ios.js +2 -0
  96. package/build/universal/Row/index.ios.js.map +1 -1
  97. package/build/universal/Row/index.js +13 -7
  98. package/build/universal/Row/index.js.map +1 -1
  99. package/build/universal/ScrollView/index.android.js +8 -1
  100. package/build/universal/ScrollView/index.android.js.map +1 -1
  101. package/build/universal/ScrollView/index.ios.js +3 -1
  102. package/build/universal/ScrollView/index.ios.js.map +1 -1
  103. package/build/universal/Spacer/index.android.js +3 -1
  104. package/build/universal/Spacer/index.android.js.map +1 -1
  105. package/build/universal/Spacer/index.ios.js +3 -1
  106. package/build/universal/Spacer/index.ios.js.map +1 -1
  107. package/build/universal/Text/index.android.js +3 -1
  108. package/build/universal/Text/index.android.js.map +1 -1
  109. package/build/universal/Text/index.ios.js +3 -1
  110. package/build/universal/Text/index.ios.js.map +1 -1
  111. package/build/universal/TextInput/index.android.js +22 -7
  112. package/build/universal/TextInput/index.android.js.map +1 -1
  113. package/build/universal/TextInput/index.ios.js +1 -0
  114. package/build/universal/TextInput/index.ios.js.map +1 -1
  115. package/build/universal/index.d.ts +1 -1
  116. package/build/universal/modifierUtils.d.ts +34 -1
  117. package/build/universal/modifierUtils.js +98 -2
  118. package/build/universal/modifierUtils.js.map +1 -1
  119. package/build/universal/stackAxis.d.ts +9 -0
  120. package/build/universal/stackAxis.js +11 -0
  121. package/build/universal/stackAxis.js.map +1 -0
  122. package/build/universal/transformStyle.android.d.ts +6 -2
  123. package/build/universal/transformStyle.android.js +18 -11
  124. package/build/universal/transformStyle.android.js.map +1 -1
  125. package/build/universal/transformStyle.ios.d.ts +5 -1
  126. package/build/universal/transformStyle.ios.js +29 -11
  127. package/build/universal/transformStyle.ios.js.map +1 -1
  128. package/build/universal/types.d.ts +26 -1
  129. package/build/universal/types.js.map +1 -1
  130. package/build/utils/flattenFragments.d.ts +7 -0
  131. package/build/utils/flattenFragments.js +17 -0
  132. package/build/utils/flattenFragments.js.map +1 -0
  133. package/ios/ContentUnavailableView.swift +9 -1
  134. package/ios/GroupView.swift +3 -0
  135. package/ios/HStackView.swift +26 -2
  136. package/ios/HostView.swift +21 -12
  137. package/ios/Modifiers/FontModifier.swift +27 -0
  138. package/ios/Modifiers/SectionIndexLabelModifier.swift +21 -0
  139. package/ios/Modifiers/ViewModifierRegistry.swift +26 -0
  140. package/ios/RNHostView.swift +4 -0
  141. package/ios/ScrollViewComponent.swift +20 -0
  142. package/ios/UIBaseView.swift +4 -1
  143. package/ios/UniversalLayout.swift +691 -0
  144. package/ios/VStackView.swift +26 -2
  145. package/local-maven-repo/expo/modules/ui/expo.modules.ui/{58.0.22/expo.modules.ui-58.0.22-sources.jar → 58.0.24/expo.modules.ui-58.0.24-sources.jar} +0 -0
  146. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.24/expo.modules.ui-58.0.24-sources.jar.md5 +1 -0
  147. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.24/expo.modules.ui-58.0.24-sources.jar.sha1 +1 -0
  148. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.24/expo.modules.ui-58.0.24-sources.jar.sha256 +1 -0
  149. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.24/expo.modules.ui-58.0.24-sources.jar.sha512 +1 -0
  150. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.24/expo.modules.ui-58.0.24.aar +0 -0
  151. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.24/expo.modules.ui-58.0.24.aar.md5 +1 -0
  152. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.24/expo.modules.ui-58.0.24.aar.sha1 +1 -0
  153. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.24/expo.modules.ui-58.0.24.aar.sha256 +1 -0
  154. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.24/expo.modules.ui-58.0.24.aar.sha512 +1 -0
  155. package/local-maven-repo/expo/modules/ui/expo.modules.ui/{58.0.22/expo.modules.ui-58.0.22.module → 58.0.24/expo.modules.ui-58.0.24.module} +22 -22
  156. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.24/expo.modules.ui-58.0.24.module.md5 +1 -0
  157. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.24/expo.modules.ui-58.0.24.module.sha1 +1 -0
  158. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.24/expo.modules.ui-58.0.24.module.sha256 +1 -0
  159. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.24/expo.modules.ui-58.0.24.module.sha512 +1 -0
  160. package/local-maven-repo/expo/modules/ui/expo.modules.ui/{58.0.22/expo.modules.ui-58.0.22.pom → 58.0.24/expo.modules.ui-58.0.24.pom} +1 -1
  161. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.24/expo.modules.ui-58.0.24.pom.md5 +1 -0
  162. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.24/expo.modules.ui-58.0.24.pom.sha1 +1 -0
  163. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.24/expo.modules.ui-58.0.24.pom.sha256 +1 -0
  164. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.24/expo.modules.ui-58.0.24.pom.sha512 +1 -0
  165. package/package.json +1 -1
  166. package/src/community/bottom-sheet/BottomSheet.android.tsx +2 -1
  167. package/src/community/menu/MenuView.ios.tsx +3 -2
  168. package/src/jetpack-compose/Column/index.tsx +5 -0
  169. package/src/jetpack-compose/Row/index.tsx +5 -0
  170. package/src/jetpack-compose/Text/index.tsx +5 -4
  171. package/src/recycling/useRecycledRows.tsx +3 -0
  172. package/src/swift-ui/ContentUnavailableView/index.tsx +19 -4
  173. package/src/swift-ui/HStack/index.tsx +6 -0
  174. package/src/swift-ui/RNHostView.tsx +8 -1
  175. package/src/swift-ui/Text/index.tsx +2 -1
  176. package/src/swift-ui/VStack/index.tsx +6 -0
  177. package/src/swift-ui/modifiers/index.ts +19 -0
  178. package/src/universal/BottomSheet/index.android.tsx +3 -1
  179. package/src/universal/Button/index.android.tsx +3 -1
  180. package/src/universal/Button/index.ios.tsx +2 -1
  181. package/src/universal/Collapsible/index.ios.tsx +4 -1
  182. package/src/universal/Column/index.android.tsx +3 -1
  183. package/src/universal/Column/index.ios.tsx +2 -1
  184. package/src/universal/Column/index.tsx +9 -4
  185. package/src/universal/FieldGroup/FieldGroup.android.tsx +8 -1
  186. package/src/universal/FieldGroup/FieldGroup.ios.tsx +2 -1
  187. package/src/universal/FieldGroup/FieldSection.android.tsx +17 -4
  188. package/src/universal/FieldGroup/FieldSection.ios.tsx +2 -1
  189. package/src/universal/Icon/index.android.tsx +2 -1
  190. package/src/universal/Icon/index.ios.tsx +2 -1
  191. package/src/universal/List/ListForEach.android.tsx +6 -0
  192. package/src/universal/List/ListForEach.ios.tsx +9 -0
  193. package/src/universal/List/ListForEach.tsx +246 -0
  194. package/src/universal/List/ListScrollContext.ts +6 -0
  195. package/src/universal/List/index.android.tsx +5 -0
  196. package/src/universal/List/index.ios.tsx +5 -0
  197. package/src/universal/List/index.tsx +11 -2
  198. package/src/universal/List/types.ts +45 -1
  199. package/src/universal/RNHostView/index.android.tsx +2 -1
  200. package/src/universal/Row/index.android.tsx +3 -1
  201. package/src/universal/Row/index.ios.tsx +2 -1
  202. package/src/universal/Row/index.tsx +9 -10
  203. package/src/universal/ScrollView/index.android.tsx +15 -3
  204. package/src/universal/ScrollView/index.ios.tsx +2 -1
  205. package/src/universal/Spacer/index.android.tsx +6 -4
  206. package/src/universal/Spacer/index.ios.tsx +2 -1
  207. package/src/universal/Text/index.android.tsx +2 -1
  208. package/src/universal/Text/index.ios.tsx +2 -1
  209. package/src/universal/TextInput/index.android.tsx +26 -5
  210. package/src/universal/TextInput/index.ios.tsx +1 -1
  211. package/src/universal/index.ts +6 -1
  212. package/src/universal/modifierUtils.ts +159 -2
  213. package/src/universal/stackAxis.ts +17 -0
  214. package/src/universal/transformStyle.android.ts +30 -12
  215. package/src/universal/transformStyle.ios.ts +41 -13
  216. package/src/universal/types.ts +27 -3
  217. package/src/utils/flattenFragments.ts +22 -0
  218. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22-sources.jar.md5 +0 -1
  219. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22-sources.jar.sha1 +0 -1
  220. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22-sources.jar.sha256 +0 -1
  221. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22-sources.jar.sha512 +0 -1
  222. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.aar +0 -0
  223. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.aar.md5 +0 -1
  224. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.aar.sha1 +0 -1
  225. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.aar.sha256 +0 -1
  226. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.aar.sha512 +0 -1
  227. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.module.md5 +0 -1
  228. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.module.sha1 +0 -1
  229. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.module.sha256 +0 -1
  230. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.module.sha512 +0 -1
  231. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.pom.md5 +0 -1
  232. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.pom.sha1 +0 -1
  233. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.pom.sha256 +0 -1
  234. package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.pom.sha512 +0 -1
@@ -0,0 +1,691 @@
1
+ // Copyright 2015-present 650 Industries. All rights reserved.
2
+
3
+ import ExpoModulesCore
4
+ import SwiftUI
5
+
6
+ /**
7
+ Sizes shared by a universal `width` or `height`.
8
+ Points are density-independent pixels. Fractions are a portion of the parent, so `0.5` is `50%`.
9
+ */
10
+ internal struct UniversalLayoutDimensions: Hashable {
11
+ var widthPoints: CGFloat?
12
+ var widthFraction: CGFloat?
13
+ var heightPoints: CGFloat?
14
+ var heightFraction: CGFloat?
15
+
16
+ var hasFraction: Bool { widthFraction != nil || heightFraction != nil }
17
+ }
18
+
19
+ internal struct UniversalLayoutDimensionsKey: LayoutValueKey {
20
+ static let defaultValue = UniversalLayoutDimensions()
21
+ }
22
+
23
+ internal func universalLayoutDimensions(from modifiers: ModifierArray?) -> UniversalLayoutDimensions {
24
+ guard let values = modifiers?.last(where: { $0["$type"] as? String == "universalLayout" }) else {
25
+ return UniversalLayoutDimensions()
26
+ }
27
+ return UniversalLayoutDimensions(
28
+ widthPoints: finiteDimension(values["widthPoints"]),
29
+ widthFraction: finiteDimension(values["widthFraction"]),
30
+ heightPoints: finiteDimension(values["heightPoints"]),
31
+ heightFraction: finiteDimension(values["heightFraction"])
32
+ )
33
+ }
34
+
35
+ private func finiteDimension(_ value: Any?) -> CGFloat? {
36
+ if let value = value as? Double {
37
+ return finite(CGFloat(value))
38
+ }
39
+ if let value = value as? Int {
40
+ return finite(CGFloat(value))
41
+ }
42
+ return nil
43
+ }
44
+
45
+ /// A missing, negative, or non-finite value is nil.
46
+ private func finite(_ value: CGFloat?) -> CGFloat? {
47
+ guard let value, value.isFinite, value >= 0 else { return nil }
48
+ return value
49
+ }
50
+
51
+ /**
52
+ Resolves a percentage against the proposal this view actually received.
53
+ Fixed sizes are applied separately, as a SwiftUI `frame`.
54
+ A view with no percentage keeps its own layout.
55
+ */
56
+ internal struct UniversalLayoutModifier: ViewModifier, Record {
57
+ @Field var widthPoints: CGFloat?
58
+ @Field var widthFraction: CGFloat?
59
+ @Field var heightPoints: CGFloat?
60
+ @Field var heightFraction: CGFloat?
61
+
62
+ @ViewBuilder
63
+ func body(content: Content) -> some View {
64
+ let dimensions = UniversalLayoutDimensions(
65
+ widthPoints: finite(widthPoints),
66
+ widthFraction: finite(widthFraction),
67
+ heightPoints: finite(heightPoints),
68
+ heightFraction: finite(heightFraction)
69
+ )
70
+ if dimensions.hasFraction {
71
+ ResolvedUniversalLayout(dimensions: dimensions, content: content)
72
+ } else {
73
+ content
74
+ }
75
+ }
76
+ }
77
+
78
+ private struct ResolvedUniversalLayout<Content: View>: View {
79
+ @Environment(\.universalPercentageParent) private var resolvesPercentages
80
+ let dimensions: UniversalLayoutDimensions
81
+ let content: Content
82
+
83
+ var body: some View {
84
+ UniversalPercentageLayout(dimensions: dimensions, resolvesPercentages: resolvesPercentages) {
85
+ content
86
+ }
87
+ .layoutValue(key: UniversalLayoutDimensionsKey.self, value: dimensions)
88
+ }
89
+ }
90
+
91
+ private struct UniversalPercentageParentKey: EnvironmentKey {
92
+ static let defaultValue = false
93
+ }
94
+
95
+ private struct ResolvesOwnPercentageKey: EnvironmentKey {
96
+ static let defaultValue = false
97
+ }
98
+
99
+ extension EnvironmentValues {
100
+ /// `Host`, universal `Row` / `Column`, and `ScrollView` set this for their children.
101
+ /// Other views clear it.
102
+ /// `Group` passes the parent's value through.
103
+ var universalPercentageParent: Bool {
104
+ get { self[UniversalPercentageParentKey.self] }
105
+ set { self[UniversalPercentageParentKey.self] = newValue }
106
+ }
107
+
108
+ /// Parent opt-in captured for this view, after descendants have been cleared.
109
+ var resolvesOwnPercentage: Bool {
110
+ get { self[ResolvesOwnPercentageKey.self] }
111
+ set { self[ResolvesOwnPercentageKey.self] = newValue }
112
+ }
113
+ }
114
+
115
+ /**
116
+ The sizing modifier sits outside this wrapper, so it still sees the parent flag.
117
+ Descendants see the flag cleared unless this view sets it again.
118
+ */
119
+ internal struct UniversalPercentageParentBoundary<Content: View>: View {
120
+ @Environment(\.universalPercentageParent) private var parentOptedIn
121
+ let content: Content
122
+
123
+ var body: some View {
124
+ content
125
+ .environment(\.resolvesOwnPercentage, parentOptedIn)
126
+ .environment(\.universalPercentageParent, false)
127
+ }
128
+ }
129
+
130
+ internal struct UniversalPercentageLayout: Layout {
131
+ let dimensions: UniversalLayoutDimensions
132
+ let resolvesPercentages: Bool
133
+
134
+ func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
135
+ guard let subview = subviews.first else { return .zero }
136
+ guard resolvesPercentages else { return subview.sizeThatFits(proposal) }
137
+ let resolvedProposal = proposal.resolving(dimensions)
138
+ let childSize = subview.sizeThatFits(resolvedProposal)
139
+ return CGSize(
140
+ width: dimensions.widthFraction != nil ? finite(resolvedProposal.width) ?? childSize.width : childSize.width,
141
+ height: dimensions.heightFraction != nil ? finite(resolvedProposal.height) ?? childSize.height : childSize.height
142
+ )
143
+ }
144
+
145
+ func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {
146
+ guard let subview = subviews.first else { return }
147
+ // This modifier sits outside the stack, so the stack sees this proposal.
148
+ // Offering `bounds` would turn a nil scroll axis into a percentage base.
149
+ let childProposal = resolvesPercentages
150
+ ? placementProposal(bounds: bounds, proposal: proposal)
151
+ : proposal
152
+ subview.place(at: bounds.origin, proposal: childProposal)
153
+ }
154
+ }
155
+
156
+ /**
157
+ Opt-in replacement for `HStack`.
158
+ Universal `Row` uses it so a child percentage is a fraction of this stack.
159
+ A child that grows on the main axis, such as `Spacer`, shares the leftover space.
160
+ Text and other children that can shrink give up space when the ideals do not fit.
161
+ A higher `layoutPriority` keeps its size first in both cases.
162
+ The cross axis gets the size this stack was offered, so text can wrap.
163
+ */
164
+ internal struct ParentAwareHStackLayout: Layout {
165
+ let alignment: VerticalAlignmentOptions
166
+ let spacing: CGFloat?
167
+ let ownDimensions: UniversalLayoutDimensions
168
+ // A fraction counts only after a universal parent has resolved it.
169
+ // A child fraction adopts the parent offer only then, too.
170
+ let resolvesOwnPercentage: Bool
171
+
172
+ private var stack: StackConfiguration {
173
+ StackConfiguration(
174
+ axis: .horizontal,
175
+ alignment: alignment.stackAlignment,
176
+ spacing: spacing,
177
+ ownDimensions: ownDimensions,
178
+ resolvesOwnPercentage: resolvesOwnPercentage
179
+ )
180
+ }
181
+
182
+ func makeCache(subviews: Subviews) -> StackLayoutCache {
183
+ StackLayoutCache()
184
+ }
185
+
186
+ func updateCache(_ cache: inout StackLayoutCache, subviews: Subviews) {
187
+ cache.reset()
188
+ }
189
+
190
+ func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout StackLayoutCache) -> CGSize {
191
+ stack.measurement(for: proposal, subviews: subviews, cache: &cache).size
192
+ }
193
+
194
+ func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout StackLayoutCache) {
195
+ stack.place(in: bounds, proposal: proposal, subviews: subviews, cache: &cache)
196
+ }
197
+ }
198
+
199
+ /**
200
+ Opt-in replacement for `VStack`. Universal `Column` uses it. See `ParentAwareHStackLayout`.
201
+ */
202
+ internal struct ParentAwareVStackLayout: Layout {
203
+ let alignment: HorizontalAlignmentOptions
204
+ let spacing: CGFloat?
205
+ let ownDimensions: UniversalLayoutDimensions
206
+ // A fraction counts only after a universal parent has resolved it.
207
+ // A child fraction adopts the parent offer only then, too.
208
+ let resolvesOwnPercentage: Bool
209
+
210
+ private var stack: StackConfiguration {
211
+ StackConfiguration(
212
+ axis: .vertical,
213
+ alignment: alignment.stackAlignment,
214
+ spacing: spacing,
215
+ ownDimensions: ownDimensions,
216
+ resolvesOwnPercentage: resolvesOwnPercentage
217
+ )
218
+ }
219
+
220
+ func makeCache(subviews: Subviews) -> StackLayoutCache {
221
+ StackLayoutCache()
222
+ }
223
+
224
+ func updateCache(_ cache: inout StackLayoutCache, subviews: Subviews) {
225
+ cache.reset()
226
+ }
227
+
228
+ func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout StackLayoutCache) -> CGSize {
229
+ stack.measurement(for: proposal, subviews: subviews, cache: &cache).size
230
+ }
231
+
232
+ func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout StackLayoutCache) {
233
+ stack.place(in: bounds, proposal: proposal, subviews: subviews, cache: &cache)
234
+ }
235
+ }
236
+
237
+ /**
238
+ Measurements by proposal.
239
+ SwiftUI asks for several sizes and then places with one of them, so placement reuses that measurement.
240
+ SwiftUI resets the cache when the subviews change.
241
+ */
242
+ internal struct StackLayoutCache {
243
+ fileprivate var measurements: [StackMeasurementKey: StackMeasurement] = [:]
244
+
245
+ fileprivate mutating func reset() {
246
+ measurements.removeAll(keepingCapacity: true)
247
+ }
248
+ }
249
+
250
+ private struct StackMeasurementKey: Hashable {
251
+ let width: CGFloat?
252
+ let height: CGFloat?
253
+ let spacing: CGFloat?
254
+ let ownDimensions: UniversalLayoutDimensions
255
+ let resolvesOwnPercentage: Bool
256
+ }
257
+
258
+ private struct StackAlignment {
259
+ enum Fill {
260
+ case start
261
+ case center
262
+ case end
263
+ }
264
+
265
+ /// The guide every child lines up on.
266
+ let guide: (ViewDimensions) -> CGFloat
267
+ /// Where the aligned children sit when the stack is larger than they are.
268
+ let fill: Fill
269
+
270
+ func offset(container: CGFloat, content: CGFloat) -> CGFloat {
271
+ switch fill {
272
+ case .start:
273
+ return 0
274
+ case .center:
275
+ return (container - content) / 2
276
+ case .end:
277
+ return container - content
278
+ }
279
+ }
280
+ }
281
+
282
+ extension VerticalAlignmentOptions {
283
+ fileprivate var stackAlignment: StackAlignment {
284
+ let guide = toVerticalAlignment()
285
+ let fill: StackAlignment.Fill
286
+ switch self {
287
+ case .top, .firstTextBaseline, .lastTextBaseline:
288
+ fill = .start
289
+ case .center:
290
+ fill = .center
291
+ case .bottom:
292
+ fill = .end
293
+ }
294
+ return StackAlignment(guide: { $0[guide] }, fill: fill)
295
+ }
296
+ }
297
+
298
+ extension HorizontalAlignmentOptions {
299
+ fileprivate var stackAlignment: StackAlignment {
300
+ let guide = toHorizontalAlignment()
301
+ let fill: StackAlignment.Fill
302
+ switch self {
303
+ case .leading:
304
+ fill = .start
305
+ case .center:
306
+ fill = .center
307
+ case .trailing:
308
+ fill = .end
309
+ }
310
+ return StackAlignment(guide: { $0[guide] }, fill: fill)
311
+ }
312
+ }
313
+
314
+ private struct StackMeasurement {
315
+ let size: CGSize
316
+ let sizes: [CGSize]
317
+ let proposals: [ProposedViewSize]
318
+ let spacings: [CGFloat]
319
+ /// Cross-axis offset of each child inside the aligned content.
320
+ let crossOffsets: [CGFloat]
321
+ let contentCross: CGFloat
322
+ }
323
+
324
+ private struct MeasuredChild {
325
+ var size: CGSize
326
+ var proposal: ProposedViewSize
327
+ /// Cross-axis proposal from the first pass.
328
+ /// The flexible pass must keep it, or a `ScrollView` in a column loses the column width.
329
+ var crossProposal: CGFloat?
330
+ /// Grows past its ideal size on the main axis, so it shares the leftover space.
331
+ var flexible: Bool
332
+ /// False for a resolved percentage or a flexible child.
333
+ var canCompress: Bool
334
+ var priority: Double
335
+ var maxMain: CGFloat
336
+ }
337
+
338
+ private struct MeasuredChildren {
339
+ var children: [MeasuredChild]
340
+ var contentMain: CGFloat
341
+ var definiteMain: CGFloat?
342
+ var definiteCross: CGFloat?
343
+ }
344
+
345
+ private struct CompressionCandidate {
346
+ let index: Int
347
+ let idealMain: CGFloat
348
+ let minMain: CGFloat
349
+ let priority: Double
350
+
351
+ var slack: CGFloat { idealMain - minMain }
352
+ }
353
+
354
+ private struct StackConfiguration {
355
+ let axis: Axis
356
+ let alignment: StackAlignment
357
+ let spacing: CGFloat?
358
+ let ownDimensions: UniversalLayoutDimensions
359
+ let resolvesOwnPercentage: Bool
360
+
361
+ func measurement(
362
+ for proposal: ProposedViewSize,
363
+ subviews: LayoutSubviews,
364
+ cache: inout StackLayoutCache
365
+ ) -> StackMeasurement {
366
+ let key = StackMeasurementKey(
367
+ width: proposal.width,
368
+ height: proposal.height,
369
+ spacing: spacing,
370
+ ownDimensions: ownDimensions,
371
+ resolvesOwnPercentage: resolvesOwnPercentage
372
+ )
373
+ if let cached = cache.measurements[key] {
374
+ return cached
375
+ }
376
+ let measurement = measure(proposal: proposal, subviews: subviews)
377
+ if cache.measurements.count >= 8 {
378
+ cache.reset()
379
+ }
380
+ cache.measurements[key] = measurement
381
+ return measurement
382
+ }
383
+
384
+ func place(
385
+ in bounds: CGRect,
386
+ proposal: ProposedViewSize,
387
+ subviews: LayoutSubviews,
388
+ cache: inout StackLayoutCache
389
+ ) {
390
+ let measurement = self.measurement(
391
+ for: placementProposal(bounds: bounds, proposal: proposal),
392
+ subviews: subviews,
393
+ cache: &cache
394
+ )
395
+ let fill = alignment.offset(container: crossLength(bounds.size, axis: axis), content: measurement.contentCross)
396
+ // The origin stays leading.
397
+ // SwiftUI mirrors a custom layout in right-to-left.
398
+ var cursor = axis == .horizontal ? bounds.minX : bounds.minY
399
+ for index in subviews.indices {
400
+ let cross = (axis == .horizontal ? bounds.minY : bounds.minX) + fill + measurement.crossOffsets[index]
401
+ let origin = axis == .horizontal ? CGPoint(x: cursor, y: cross) : CGPoint(x: cross, y: cursor)
402
+ subviews[index].place(at: origin, proposal: measurement.proposals[index])
403
+ cursor += mainLength(measurement.sizes[index], axis: axis) + measurement.spacings[index]
404
+ }
405
+ }
406
+
407
+ private func measure(proposal: ProposedViewSize, subviews: LayoutSubviews) -> StackMeasurement {
408
+ let spacings = stackSpacings(subviews: subviews, explicit: spacing)
409
+ let measured = measureChildren(subviews: subviews, proposal: proposal, spacings: spacings)
410
+ // A flexible child reports its cross size for its final main size and no cross proposal.
411
+ // So a `Spacer` does not stretch the stack, and wrapped text counts its lines.
412
+ let dimensions = zip(subviews, measured.children).map { subview, child in
413
+ let dimensionProposal = child.flexible
414
+ ? proposedSize(main: mainLength(child.size, axis: axis), cross: nil, axis: axis)
415
+ : child.proposal
416
+ return subview.dimensions(in: dimensionProposal)
417
+ }
418
+ let guides = dimensions.map(alignment.guide)
419
+ let reference = guides.max() ?? 0
420
+ let extents = zip(dimensions, guides).map { dimension, guide in
421
+ crossLength(CGSize(width: dimension.width, height: dimension.height), axis: axis) - guide
422
+ }
423
+ let contentCross = reference + (extents.max() ?? 0)
424
+ return StackMeasurement(
425
+ size: stackSize(
426
+ main: measured.definiteMain ?? measured.contentMain,
427
+ cross: measured.definiteCross ?? contentCross,
428
+ axis: axis
429
+ ),
430
+ sizes: measured.children.map(\.size),
431
+ proposals: measured.children.map(\.proposal),
432
+ spacings: spacings,
433
+ crossOffsets: guides.map { reference - $0 },
434
+ contentCross: contentCross
435
+ )
436
+ }
437
+
438
+ private func measureChildren(
439
+ subviews: LayoutSubviews,
440
+ proposal: ProposedViewSize,
441
+ spacings: [CGFloat]
442
+ ) -> MeasuredChildren {
443
+ let offeredMain = finite(axis == .horizontal ? proposal.width : proposal.height)
444
+ let offeredCross = finite(axis == .horizontal ? proposal.height : proposal.width)
445
+ let ownMainPoints = axis == .horizontal ? ownDimensions.widthPoints : ownDimensions.heightPoints
446
+ let ownMainFraction = axis == .horizontal ? ownDimensions.widthFraction : ownDimensions.heightFraction
447
+ let ownCrossPoints = axis == .horizontal ? ownDimensions.heightPoints : ownDimensions.widthPoints
448
+ let ownCrossFraction = axis == .horizontal ? ownDimensions.heightFraction : ownDimensions.widthFraction
449
+ var childHasMainFraction = false
450
+ var childHasCrossFraction = false
451
+ for subview in subviews {
452
+ let dimensions = subview[UniversalLayoutDimensionsKey.self]
453
+ let mainFraction = axis == .horizontal ? dimensions.widthFraction : dimensions.heightFraction
454
+ let crossFraction = axis == .horizontal ? dimensions.heightFraction : dimensions.widthFraction
455
+ childHasMainFraction = childHasMainFraction || mainFraction != nil
456
+ childHasCrossFraction = childHasCrossFraction || crossFraction != nil
457
+ }
458
+ let ownsMain = ownMainPoints != nil || (ownMainFraction != nil && resolvesOwnPercentage)
459
+ let ownsCross = ownCrossPoints != nil || (ownCrossFraction != nil && resolvesOwnPercentage)
460
+ var definiteMain = ownsMain ? offeredMain : nil
461
+ var definiteCross = ownsCross ? offeredCross : nil
462
+ // A child fraction adopts a positive offer from a universal parent, and the stack returns that size.
463
+ // A zero proposal is the minimum-size probe, so it still shrink-wraps.
464
+ // Otherwise the next pass would resolve the fraction against the smaller result.
465
+ // Another parent, such as a scroll view with no height, offers its content size, which is not a base.
466
+ if definiteMain == nil, resolvesOwnPercentage, childHasMainFraction, let offeredMain, offeredMain > 0 {
467
+ definiteMain = offeredMain
468
+ }
469
+ if definiteCross == nil, resolvesOwnPercentage, childHasCrossFraction, let offeredCross, offeredCross > 0 {
470
+ definiteCross = offeredCross
471
+ }
472
+
473
+ var children: [MeasuredChild] = []
474
+ children.reserveCapacity(subviews.count)
475
+
476
+ for subview in subviews {
477
+ let dimensions = subview[UniversalLayoutDimensionsKey.self]
478
+ let mainFraction = axis == .horizontal ? dimensions.widthFraction : dimensions.heightFraction
479
+ let crossFraction = axis == .horizontal ? dimensions.heightFraction : dimensions.widthFraction
480
+ // A fraction uses the size chosen above.
481
+ // Every other child still gets the offered cross size, so text can wrap.
482
+ let crossProposal = crossFraction != nil ? definiteCross : offeredCross
483
+
484
+ if mainFraction != nil, let definiteMain {
485
+ let childProposal = proposedSize(main: definiteMain, cross: crossProposal, axis: axis)
486
+ let size = subview.sizeThatFits(childProposal)
487
+ children.append(MeasuredChild(
488
+ size: size,
489
+ proposal: childProposal,
490
+ crossProposal: crossProposal,
491
+ flexible: false,
492
+ canCompress: false,
493
+ priority: subview.priority,
494
+ maxMain: mainLength(size, axis: axis)
495
+ ))
496
+ continue
497
+ }
498
+
499
+ let idealProposal = proposedSize(main: nil, cross: crossProposal, axis: axis)
500
+ let ideal = subview.sizeThatFits(idealProposal)
501
+ let maxed = subview.sizeThatFits(proposedSize(main: .infinity, cross: crossProposal, axis: axis))
502
+ let idealMain = mainLength(ideal, axis: axis)
503
+ let maxMain = mainLength(maxed, axis: axis)
504
+ let flexible = offeredMain != nil && (maxMain.isInfinite || maxMain > idealMain + 1)
505
+ children.append(MeasuredChild(
506
+ size: ideal,
507
+ proposal: idealProposal,
508
+ crossProposal: crossProposal,
509
+ flexible: flexible,
510
+ canCompress: !flexible,
511
+ priority: subview.priority,
512
+ maxMain: maxMain
513
+ ))
514
+ }
515
+
516
+ if let offeredMain {
517
+ compressChildren(&children, subviews: subviews, offeredMain: offeredMain, spacings: spacings)
518
+ growChildren(&children, subviews: subviews, offeredMain: offeredMain, spacings: spacings)
519
+ }
520
+
521
+ let contentMain = children.reduce(CGFloat(0)) { $0 + mainLength($1.size, axis: axis) } + spacings.reduce(0, +)
522
+ return MeasuredChildren(
523
+ children: children,
524
+ contentMain: contentMain,
525
+ definiteMain: definiteMain,
526
+ definiteCross: definiteCross
527
+ )
528
+ }
529
+
530
+ private func compressChildren(
531
+ _ children: inout [MeasuredChild],
532
+ subviews: LayoutSubviews,
533
+ offeredMain: CGFloat,
534
+ spacings: [CGFloat]
535
+ ) {
536
+ let fixedMain = children.reduce(CGFloat(0)) { total, child in
537
+ child.flexible ? total : total + mainLength(child.size, axis: axis)
538
+ }
539
+ let overflow = fixedMain + spacings.reduce(0, +) - offeredMain
540
+ guard overflow > 1 else { return }
541
+
542
+ var candidates: [CompressionCandidate] = []
543
+ for index in children.indices where children[index].canCompress {
544
+ let minSize = subviews[index].sizeThatFits(
545
+ proposedSize(main: 0, cross: children[index].crossProposal, axis: axis)
546
+ )
547
+ let candidate = CompressionCandidate(
548
+ index: index,
549
+ idealMain: mainLength(children[index].size, axis: axis),
550
+ minMain: mainLength(minSize, axis: axis),
551
+ priority: children[index].priority
552
+ )
553
+ if candidate.slack > 1 {
554
+ candidates.append(candidate)
555
+ }
556
+ }
557
+ guard !candidates.isEmpty else { return }
558
+
559
+ // A higher priority keeps its ideal size while the lower ones can still reach their minimum.
560
+ // Among equals, smallest slack first, so a short label keeps its width when that fits an equal share.
561
+ // The long text then takes what remains.
562
+ candidates.sort { lhs, rhs in
563
+ if lhs.priority != rhs.priority { return lhs.priority > rhs.priority }
564
+ if lhs.slack != rhs.slack { return lhs.slack < rhs.slack }
565
+ return lhs.index < rhs.index
566
+ }
567
+ let candidateIndices = Set(candidates.map(\.index))
568
+ let reserved = children.enumerated().reduce(CGFloat(0)) { total, item in
569
+ if item.element.flexible || candidateIndices.contains(item.offset) {
570
+ return total
571
+ }
572
+ return total + mainLength(item.element.size, axis: axis)
573
+ }
574
+ var available = max(0, offeredMain - spacings.reduce(0, +) - reserved)
575
+ for (position, candidate) in candidates.enumerated() {
576
+ let rest = candidates[(position + 1)...]
577
+ let peers = rest.prefix { $0.priority == candidate.priority }.count + 1
578
+ let lowerMinimum = rest.dropFirst(peers - 1).reduce(CGFloat(0)) { $0 + $1.minMain }
579
+ let share = min(candidate.idealMain, max(0, available - lowerMinimum) / CGFloat(peers))
580
+ let proposal = proposedSize(
581
+ main: share,
582
+ cross: children[candidate.index].crossProposal,
583
+ axis: axis
584
+ )
585
+ let size = subviews[candidate.index].sizeThatFits(proposal)
586
+ children[candidate.index].size = size
587
+ children[candidate.index].proposal = proposal
588
+ available = max(0, available - mainLength(size, axis: axis))
589
+ }
590
+ }
591
+
592
+ /// Flexible children share the space left by the others.
593
+ /// A higher priority goes first.
594
+ /// Among equals, the least flexible goes first, so a capped child leaves the rest to a `Spacer`.
595
+ private func growChildren(
596
+ _ children: inout [MeasuredChild],
597
+ subviews: LayoutSubviews,
598
+ offeredMain: CGFloat,
599
+ spacings: [CGFloat]
600
+ ) {
601
+ let order = children.indices.filter { children[$0].flexible }.sorted { lhs, rhs in
602
+ if children[lhs].priority != children[rhs].priority { return children[lhs].priority > children[rhs].priority }
603
+ if children[lhs].maxMain != children[rhs].maxMain { return children[lhs].maxMain < children[rhs].maxMain }
604
+ return lhs < rhs
605
+ }
606
+ guard !order.isEmpty else { return }
607
+
608
+ let fixedMain = children.reduce(CGFloat(0)) { total, child in
609
+ child.flexible ? total : total + mainLength(child.size, axis: axis)
610
+ }
611
+ var remaining = max(0, offeredMain - fixedMain - spacings.reduce(0, +))
612
+ for (position, index) in order.enumerated() {
613
+ let peers = order[(position + 1)...].prefix { children[$0].priority == children[index].priority }.count + 1
614
+ let share = peers == 1 ? remaining : (remaining / CGFloat(peers)).rounded(.down)
615
+ let proposal = proposedSize(main: share, cross: children[index].crossProposal, axis: axis)
616
+ let size = subviews[index].sizeThatFits(proposal)
617
+ children[index].size = size
618
+ children[index].proposal = proposal
619
+ // A child that takes less than its share leaves the rest to the next one.
620
+ remaining = max(0, remaining - mainLength(size, axis: axis))
621
+ }
622
+ }
623
+ }
624
+
625
+ private func proposedSize(main: CGFloat?, cross: CGFloat?, axis: Axis) -> ProposedViewSize {
626
+ switch axis {
627
+ case .horizontal:
628
+ return ProposedViewSize(width: main, height: cross)
629
+ case .vertical:
630
+ return ProposedViewSize(width: cross, height: main)
631
+ }
632
+ }
633
+
634
+ private func stackSize(main: CGFloat, cross: CGFloat, axis: Axis) -> CGSize {
635
+ switch axis {
636
+ case .horizontal:
637
+ return CGSize(width: main, height: cross)
638
+ case .vertical:
639
+ return CGSize(width: cross, height: main)
640
+ }
641
+ }
642
+
643
+ private func mainLength(_ size: CGSize, axis: Axis) -> CGFloat {
644
+ axis == .horizontal ? size.width : size.height
645
+ }
646
+
647
+ private func crossLength(_ size: CGSize, axis: Axis) -> CGFloat {
648
+ axis == .horizontal ? size.height : size.width
649
+ }
650
+
651
+ /// Unset spacing is 0, as on Android and web.
652
+ /// The system distance sits on top of child percentages and pushes them past the stack.
653
+ /// An explicit spacing is kept.
654
+ private func stackSpacings(subviews: LayoutSubviews, explicit: CGFloat?) -> [CGFloat] {
655
+ let gap = explicit ?? 0
656
+ return subviews.indices.map { index in
657
+ guard index < subviews.count - 1 else { return 0 }
658
+ return gap
659
+ }
660
+ }
661
+
662
+ private extension ProposedViewSize {
663
+ func resolving(_ dimensions: UniversalLayoutDimensions) -> ProposedViewSize {
664
+ ProposedViewSize(
665
+ width: resolvedAxis(dimensions.widthFraction, proposal: width),
666
+ height: resolvedAxis(dimensions.heightFraction, proposal: height)
667
+ )
668
+ }
669
+ }
670
+
671
+ /// An axis with no fraction keeps the proposal, including infinity.
672
+ /// A fraction of a non-finite proposal is nil, not infinity.
673
+ /// A larger fraction is clamped to the proposal, so 150% stays inside the parent.
674
+ private func resolvedAxis(_ fraction: CGFloat?, proposal: CGFloat?) -> CGFloat? {
675
+ guard let fraction else {
676
+ return proposal
677
+ }
678
+ guard let base = finite(proposal) else {
679
+ return nil
680
+ }
681
+ return min(base * fraction, base)
682
+ }
683
+
684
+ /// Bounds replace an axis the parent already made finite.
685
+ /// An unspecified or infinite axis stays as proposed, so a content size is not a percentage base.
686
+ private func placementProposal(bounds: CGRect, proposal: ProposedViewSize) -> ProposedViewSize {
687
+ ProposedViewSize(
688
+ width: finite(proposal.width) != nil ? bounds.width : proposal.width,
689
+ height: finite(proposal.height) != nil ? bounds.height : proposal.height
690
+ )
691
+ }