@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
@@ -7,6 +7,7 @@ import {
7
7
  import { clip, fillMaxWidth, padding, Shapes } from '@expo/ui/jetpack-compose/modifiers';
8
8
 
9
9
  import { useUniversalLifecycle } from '../hooks';
10
+ import { getUserSizingOverrides } from '../modifierUtils';
10
11
  import { transformToModifiers } from '../transformStyle';
11
12
  import { extractFieldSectionSlots } from './FieldSectionSlots';
12
13
  import { getFieldItemPosition, type FieldItemPosition, type FieldSectionProps } from './types';
@@ -37,10 +38,22 @@ export function FieldSection({
37
38
 
38
39
  const { header, footer, rows } = extractFieldSectionSlots(children);
39
40
 
40
- const outerModifiers = transformToModifiers(style, { disabled, hidden, testID }, [
41
- fillMaxWidth(),
42
- ...(extraModifiers ?? []),
43
- ]);
41
+ // A numeric width owns the axis, so fillMaxWidth stays off.
42
+ // A percentage is only parent data. This LazyColumn does not read it.
43
+ // Stretch in that case, unless a user modifier already owns the width.
44
+ const widthIsPercentage = typeof style?.width === 'string';
45
+ const userOwnsWidth = getUserSizingOverrides(extraModifiers, 'android').width;
46
+ const sectionModifiers =
47
+ !userOwnsWidth && (style?.width == null || widthIsPercentage)
48
+ ? [fillMaxWidth(), ...(extraModifiers ?? [])]
49
+ : extraModifiers;
50
+
51
+ const outerModifiers = transformToModifiers(
52
+ style,
53
+ { disabled, hidden, testID },
54
+ sectionModifiers,
55
+ { componentName: 'FieldSection' }
56
+ );
44
57
 
45
58
  const headerNode =
46
59
  header ??
@@ -27,7 +27,8 @@ export function FieldSection({
27
27
  const modifiers = transformToModifiers(
28
28
  style,
29
29
  { onAppear, onDisappear, disabled, hidden, testID },
30
- extraModifiers
30
+ extraModifiers,
31
+ { componentName: 'FieldSection' }
31
32
  );
32
33
 
33
34
  return (
@@ -52,7 +52,8 @@ export function Icon({
52
52
  const modifiers = transformToModifiers(
53
53
  style,
54
54
  { onPress, disabled, hidden, testID },
55
- extraModifiers
55
+ extraModifiers,
56
+ { componentName: 'Icon' }
56
57
  );
57
58
 
58
59
  if (onPress) {
@@ -37,7 +37,8 @@ export function Icon({
37
37
  const modifiers = transformToModifiers(
38
38
  style,
39
39
  { onAppear, onDisappear, disabled, hidden, testID },
40
- extraModifiers
40
+ extraModifiers,
41
+ { componentName: 'Icon' }
41
42
  );
42
43
 
43
44
  return (
@@ -0,0 +1,6 @@
1
+ import { createLazyItems } from '../../jetpack-compose/LazyItems';
2
+
3
+ /**
4
+ * Android implementation of `List.ForEach`. Delegates to Jetpack Compose `LazyColumn.Items`.
5
+ */
6
+ export const ListForEach = createLazyItems('List.ForEach');
@@ -0,0 +1,9 @@
1
+ import { ListForEach as SwiftUIListForEach } from '../../swift-ui/List/ListForEach';
2
+ import type { ListForEachProps } from './types';
3
+
4
+ /**
5
+ * iOS implementation of `List.ForEach`. Delegates to SwiftUI `List.ForEach`.
6
+ */
7
+ export function ListForEach<T>(props: ListForEachProps<T>) {
8
+ return <SwiftUIListForEach {...props} />;
9
+ }
@@ -0,0 +1,246 @@
1
+ import {
2
+ createContext,
3
+ Fragment,
4
+ useCallback,
5
+ useContext,
6
+ useEffect,
7
+ useLayoutEffect,
8
+ useMemo,
9
+ useRef,
10
+ useState,
11
+ } from 'react';
12
+ import { View } from 'react-native';
13
+
14
+ import {
15
+ useItemKeys,
16
+ useRecycledRows,
17
+ type RecycledSlotProps,
18
+ } from '../../recycling/useRecycledRows';
19
+ import { ListScrollContext } from './ListScrollContext';
20
+ import type { ListForEachProps } from './types';
21
+
22
+ type RowSizes = {
23
+ measureAll: () => void;
24
+ register: (measure: () => void) => () => void;
25
+ report: (itemKey: string, height: number) => void;
26
+ };
27
+
28
+ const RowSizesContext = createContext<RowSizes | null>(null);
29
+
30
+ function asHTMLElement(value: unknown): HTMLElement | null {
31
+ return typeof HTMLElement !== 'undefined' && value instanceof HTMLElement ? value : null;
32
+ }
33
+
34
+ function getScrollParent(node: HTMLElement): Element | null {
35
+ for (let parent = node.parentElement; parent; parent = parent.parentElement) {
36
+ const { overflowY } = getComputedStyle(parent);
37
+ if (
38
+ (overflowY === 'auto' || overflowY === 'scroll') &&
39
+ parent.scrollHeight > parent.clientHeight
40
+ ) {
41
+ return parent;
42
+ }
43
+ }
44
+ return document.scrollingElement;
45
+ }
46
+
47
+ // Index of the item at `offset`, clamped to the data.
48
+ function getIndexAt(offsets: Float64Array, offset: number): number {
49
+ let low = 0;
50
+ let high = offsets.length - 2;
51
+ while (low < high) {
52
+ const middle = (low + high + 1) >> 1;
53
+ if (offsets[middle]! <= offset) low = middle;
54
+ else high = middle - 1;
55
+ }
56
+ return low;
57
+ }
58
+
59
+ /**
60
+ * Renders one row for each item of `data`, and reuses rows while the list scrolls.
61
+ */
62
+ export function ListForEach<T>({ recycling = true, ...props }: ListForEachProps<T>) {
63
+ return recycling ? <RecycledListForEach {...props} /> : <StaticListForEach {...props} />;
64
+ }
65
+
66
+ function StaticListForEach<T>({
67
+ data,
68
+ keyExtractor,
69
+ children: renderItem,
70
+ }: Omit<ListForEachProps<T>, 'recycling'>) {
71
+ const itemKeys = useItemKeys('List.ForEach', data, keyExtractor);
72
+ return (
73
+ <>
74
+ {data.map((item, index) => (
75
+ <Fragment key={itemKeys[index]}>{renderItem({ item, index })}</Fragment>
76
+ ))}
77
+ </>
78
+ );
79
+ }
80
+
81
+ function RecycledListForEach<T>({
82
+ data,
83
+ keyExtractor,
84
+ children: renderItem,
85
+ overscanCount,
86
+ estimatedItemSize = 64,
87
+ }: Omit<ListForEachProps<T>, 'recycling'>) {
88
+ const { itemKeys, revision, rows, start, onWindowChange } = useRecycledRows({
89
+ componentName: 'List.ForEach',
90
+ Slot,
91
+ data,
92
+ keyExtractor,
93
+ renderItem,
94
+ overscanCount,
95
+ estimatedItemSize,
96
+ });
97
+ const listRef = useContext(ListScrollContext);
98
+ const containerRef = useRef(null);
99
+ const heights = useRef(new Map<string, number>()).current;
100
+ const [heightsVersion, setHeightsVersion] = useState(0);
101
+
102
+ const rowSizes = useMemo<RowSizes>(() => {
103
+ const measures = new Set<() => void>();
104
+ return {
105
+ measureAll: () => measures.forEach((measure) => measure()),
106
+ register: (measure) => {
107
+ measures.add(measure);
108
+ return () => measures.delete(measure);
109
+ },
110
+ report: (itemKey, height) => {
111
+ if (!(height > 0) || heights.get(itemKey) === height) return;
112
+ heights.set(itemKey, height);
113
+ setHeightsVersion((version) => version + 1);
114
+ },
115
+ };
116
+ }, [heights]);
117
+
118
+ // `offsets[i]` is the top of item `i`; the last entry is the total height.
119
+ const offsets = useMemo(() => {
120
+ const result = new Float64Array(itemKeys.length + 1);
121
+ itemKeys.forEach((itemKey, index) => {
122
+ result[index + 1] = result[index]! + (heights.get(itemKey) ?? estimatedItemSize);
123
+ });
124
+ return result;
125
+ // `heightsVersion` tracks changes to `heights`.
126
+ }, [itemKeys, estimatedItemSize, heights, heightsVersion]);
127
+
128
+ const latest = useRef({ itemKeys, offsets, revision, onWindowChange });
129
+ latest.current = { itemKeys, offsets, revision, onWindowChange };
130
+ // The first visible item and its offset, from the last window update.
131
+ const anchor = useRef<{ itemKeys: string[]; index: number; offset: number } | null>(null);
132
+
133
+ const updateWindow = useCallback(() => {
134
+ const container = asHTMLElement(containerRef.current);
135
+ const { itemKeys, offsets, revision, onWindowChange } = latest.current;
136
+ if (!container || offsets.length < 2) return;
137
+ const containerTop = container.getBoundingClientRect().top;
138
+ let top = 0;
139
+ let bottom = window.innerHeight;
140
+ const list = asHTMLElement(listRef?.current);
141
+ if (list) {
142
+ const listRect = list.getBoundingClientRect();
143
+ top = Math.max(top, listRect.top);
144
+ bottom = Math.min(bottom, listRect.bottom);
145
+ }
146
+ const first = getIndexAt(offsets, top - containerTop);
147
+ const last = getIndexAt(offsets, bottom - containerTop);
148
+ anchor.current = { itemKeys, index: first, offset: offsets[first]! };
149
+ onWindowChange({ first, last: Math.max(first, last), revision });
150
+ }, [listRef]);
151
+
152
+ useLayoutEffect(() => {
153
+ // Rows measured above the first visible row move it, so scroll by the same amount.
154
+ const container = asHTMLElement(containerRef.current);
155
+ const previous = anchor.current;
156
+ if (container && previous?.itemKeys === itemKeys) {
157
+ const delta = offsets[previous.index]! - previous.offset;
158
+ const scrollParent = delta === 0 ? null : getScrollParent(container);
159
+ if (scrollParent) scrollParent.scrollTop += delta;
160
+ }
161
+ updateWindow();
162
+ }, [updateWindow, itemKeys, offsets, revision]);
163
+
164
+ useEffect(() => {
165
+ const container = asHTMLElement(containerRef.current);
166
+ if (!container) return;
167
+ const onScroll = (event: Event) => {
168
+ if (event.target instanceof Node && !event.target.contains(container)) return;
169
+ updateWindow();
170
+ };
171
+ const options = { capture: true, passive: true };
172
+ window.addEventListener('scroll', onScroll, options);
173
+ window.addEventListener('resize', updateWindow);
174
+ return () => {
175
+ window.removeEventListener('scroll', onScroll, options);
176
+ window.removeEventListener('resize', updateWindow);
177
+ };
178
+ }, [updateWindow]);
179
+
180
+ useEffect(() => {
181
+ const live = new Set(itemKeys);
182
+ for (const itemKey of heights.keys()) {
183
+ if (!live.has(itemKey)) heights.delete(itemKey);
184
+ }
185
+ }, [heights, itemKeys]);
186
+
187
+ // Row heights depend on the width.
188
+ useEffect(() => {
189
+ const container = asHTMLElement(containerRef.current);
190
+ if (!container || typeof ResizeObserver === 'undefined') return;
191
+ let width = container.getBoundingClientRect().width;
192
+ const observer = new ResizeObserver(() => {
193
+ const nextWidth = container.getBoundingClientRect().width;
194
+ if (nextWidth === width) return;
195
+ width = nextWidth;
196
+ heights.clear();
197
+ setHeightsVersion((version) => version + 1);
198
+ rowSizes.measureAll();
199
+ });
200
+ observer.observe(container);
201
+ return () => observer.disconnect();
202
+ }, [heights, rowSizes]);
203
+
204
+ // Rotate the pool from slot order to item order, so the DOM order matches the screen.
205
+ const pivot = rows.length === 0 ? 0 : start % rows.length;
206
+ const orderedRows = [...rows.slice(pivot), ...rows.slice(0, pivot)];
207
+ const end = start + rows.length;
208
+
209
+ return (
210
+ <RowSizesContext.Provider value={rowSizes}>
211
+ <View ref={containerRef}>
212
+ <View style={{ height: offsets[start] }} />
213
+ {orderedRows}
214
+ <View style={{ height: offsets[itemKeys.length]! - offsets[end]! }} />
215
+ </View>
216
+ </RowSizesContext.Provider>
217
+ );
218
+ }
219
+
220
+ function Slot({ itemKey, children }: RecycledSlotProps) {
221
+ const rowSizes = useContext(RowSizesContext);
222
+ const ref = useRef(null);
223
+ const itemKeyRef = useRef(itemKey);
224
+ itemKeyRef.current = itemKey;
225
+
226
+ const measure = useCallback(() => {
227
+ const node = asHTMLElement(ref.current);
228
+ if (node) rowSizes?.report(itemKeyRef.current, node.getBoundingClientRect().height);
229
+ }, [rowSizes]);
230
+
231
+ useLayoutEffect(measure, [measure, itemKey]);
232
+
233
+ useEffect(() => {
234
+ const node = asHTMLElement(ref.current);
235
+ if (!node || !rowSizes || typeof ResizeObserver === 'undefined') return;
236
+ const observer = new ResizeObserver(measure);
237
+ observer.observe(node);
238
+ const unregister = rowSizes.register(measure);
239
+ return () => {
240
+ observer.disconnect();
241
+ unregister();
242
+ };
243
+ }, [measure, rowSizes]);
244
+
245
+ return <View ref={ref}>{children}</View>;
246
+ }
@@ -0,0 +1,6 @@
1
+ import { createContext, type RefObject } from 'react';
2
+
3
+ /**
4
+ * The web `List` node. `List.ForEach` uses it to find its visible rows.
5
+ */
6
+ export const ListScrollContext = createContext<RefObject<unknown> | null>(null);
@@ -2,6 +2,7 @@ import { LazyColumn, PullToRefreshBox } from '@expo/ui/jetpack-compose';
2
2
  import { testID as testIDModifier, type ModifierConfig } from '@expo/ui/jetpack-compose/modifiers';
3
3
  import { useCallback, useState } from 'react';
4
4
 
5
+ import { ListForEach } from './ListForEach';
5
6
  import type { ListProps } from './types';
6
7
 
7
8
  /**
@@ -41,4 +42,8 @@ export function List({ children, onRefresh, testID }: ListProps) {
41
42
  );
42
43
  }
43
44
 
45
+ List.ForEach = ListForEach;
46
+
47
+ export { ListForEach } from './ListForEach';
48
+
44
49
  export * from './types';
@@ -1,6 +1,7 @@
1
1
  import { List as SwiftUIList } from '@expo/ui/swift-ui';
2
2
  import { refreshable, type ModifierConfig } from '@expo/ui/swift-ui/modifiers';
3
3
 
4
+ import { ListForEach } from './ListForEach';
4
5
  import type { ListProps } from './types';
5
6
 
6
7
  /**
@@ -16,4 +17,8 @@ export function List({ children, onRefresh, testID }: ListProps) {
16
17
  );
17
18
  }
18
19
 
20
+ List.ForEach = ListForEach;
21
+
22
+ export { ListForEach } from './ListForEach';
23
+
19
24
  export * from './types';
@@ -1,5 +1,8 @@
1
+ import { useRef } from 'react';
1
2
  import { StyleSheet, View } from 'react-native';
2
3
 
4
+ import { ListForEach } from './ListForEach';
5
+ import { ListScrollContext } from './ListScrollContext';
3
6
  import type { ListProps } from './types';
4
7
 
5
8
  /**
@@ -7,15 +10,17 @@ import type { ListProps } from './types';
7
10
  * Typically populated with [`ListItem`](#listitem) children.
8
11
  */
9
12
  export function List({ children, testID }: ListProps) {
13
+ const ref = useRef(null);
10
14
  return (
11
- <View style={styles.container} testID={testID}>
12
- {children}
15
+ <View ref={ref} style={styles.container} testID={testID}>
16
+ <ListScrollContext.Provider value={ref}>{children}</ListScrollContext.Provider>
13
17
  </View>
14
18
  );
15
19
  }
16
20
 
17
21
  const styles = StyleSheet.create({
18
22
  container: {
23
+ flex: 1,
19
24
  flexDirection: 'column',
20
25
  width: '100%',
21
26
  overflowX: 'auto',
@@ -23,4 +28,8 @@ const styles = StyleSheet.create({
23
28
  },
24
29
  });
25
30
 
31
+ List.ForEach = ListForEach;
32
+
33
+ export { ListForEach } from './ListForEach';
34
+
26
35
  export * from './types';
@@ -1,4 +1,4 @@
1
- import type { ReactNode } from 'react';
1
+ import type { ReactElement, ReactNode } from 'react';
2
2
 
3
3
  /**
4
4
  * Props for the [`List`](#list) component.
@@ -26,3 +26,47 @@ export interface ListProps {
26
26
  */
27
27
  testID?: string;
28
28
  }
29
+
30
+ /**
31
+ * Props for the `List.ForEach` component.
32
+ */
33
+ export interface ListForEachProps<T> {
34
+ /**
35
+ * Items to display. Pass a new array to update.
36
+ */
37
+ data: readonly T[];
38
+
39
+ /**
40
+ * Returns a stable, unique string key for each item.
41
+ */
42
+ keyExtractor: (item: T, index: number) => string;
43
+
44
+ /**
45
+ * Renders a row. Wrap it in `useCallback`, or every row re-renders on each parent render.
46
+ * A recycled row keeps its local state (`useState`) when it shows another item.
47
+ */
48
+ children: (info: { item: T; index: number }) => ReactElement;
49
+
50
+ /**
51
+ * Renders only the rows near the visible range. Set to `false` to render every row.
52
+ * Changing it remounts the rows.
53
+ *
54
+ * @default true
55
+ */
56
+ recycling?: boolean;
57
+
58
+ /**
59
+ * Extra rows to render above and below the visible rows.
60
+ *
61
+ * @default 10
62
+ */
63
+ overscanCount?: number;
64
+
65
+ /**
66
+ * Row height to use until a row is measured: dp on Android, points on iOS (without the row
67
+ * insets), and pixels on web.
68
+ *
69
+ * @default 64
70
+ */
71
+ estimatedItemSize?: number;
72
+ }
@@ -21,7 +21,8 @@ export function RNHostView({
21
21
  const modifiers = transformToModifiers(
22
22
  style,
23
23
  { onAppear, onDisappear, disabled, hidden, testID },
24
- extraModifiers
24
+ extraModifiers,
25
+ { componentName: 'RNHostView' }
25
26
  );
26
27
 
27
28
  return (
@@ -31,13 +31,15 @@ export function Row({
31
31
  const modifiers = transformToModifiers(
32
32
  style,
33
33
  { onPress: disabled ? undefined : onPress, disabled, hidden, testID },
34
- extraModifiers
34
+ extraModifiers,
35
+ { componentName: 'Row' }
35
36
  );
36
37
 
37
38
  return (
38
39
  <ComposeRow
39
40
  verticalAlignment={alignmentMap[alignment]}
40
41
  horizontalArrangement={spacing != null ? { spacedBy: spacing } : undefined}
42
+ resolvesChildPercentages
41
43
  modifiers={modifiers}>
42
44
  {children}
43
45
  </ComposeRow>
@@ -33,7 +33,7 @@ export function Row({
33
33
  style,
34
34
  { onPress, onAppear, onDisappear, disabled, hidden, testID },
35
35
  extraModifiers,
36
- { frameAlignment: frameAlignmentMap[alignment] }
36
+ { componentName: 'Row', frameAlignment: frameAlignmentMap[alignment] }
37
37
  );
38
38
 
39
39
  return (
@@ -41,6 +41,7 @@ export function Row({
41
41
  alignment={alignmentMap[alignment]}
42
42
  spacing={spacing}
43
43
  modifiers={modifiers}
44
+ resolvesChildPercentages
44
45
  testID={testID}>
45
46
  {children}
46
47
  </HStack>
@@ -1,19 +1,16 @@
1
1
  import { Pressable, StyleSheet, View, type ViewStyle } from 'react-native';
2
2
 
3
3
  import { useUniversalLifecycle } from '../hooks';
4
+ import { StackAxisContext, useCrossAxisSize } from '../stackAxis';
4
5
  import type { UniversalAlignment } from '../types';
5
6
  import type { RowProps } from './types';
6
7
 
7
8
  const styles = StyleSheet.create({
8
- row: {
9
- // Fill the parent's cross-axis by default so a `<Spacer flexible />`
10
- // child has room to grow. Without this, a Row placed inside a `Column`
11
- // with alignment other than 'stretch' is content-sized on web, which
12
- // leaves flex children with no leftover space. SwiftUI and Compose
13
- // achieve the same effect via their own layout phases.
14
- alignSelf: 'stretch',
15
- flexDirection: 'row',
16
- },
9
+ row: { flexDirection: 'row' },
10
+ // Fill the parent's cross axis when this row has no size of its own on that axis,
11
+ // so a flexible child still has leftover space. A set size must not use
12
+ // stretch, or the parent's alignment cannot move it.
13
+ stretch: { alignSelf: 'stretch' },
17
14
  hidden: { display: 'none' },
18
15
  disabled: {
19
16
  opacity: 0.5,
@@ -43,6 +40,7 @@ export function Row({
43
40
  testID,
44
41
  }: RowProps) {
45
42
  useUniversalLifecycle(onAppear, onDisappear);
43
+ const crossAxisSize = useCrossAxisSize(style);
46
44
 
47
45
  const Container = onPress ? Pressable : View;
48
46
 
@@ -53,13 +51,14 @@ export function Row({
53
51
  testID={testID}
54
52
  style={[
55
53
  styles.row,
54
+ crossAxisSize == null && styles.stretch,
56
55
  alignmentStyles[alignment],
57
56
  spacing != null && { gap: spacing },
58
57
  style,
59
58
  hidden && styles.hidden,
60
59
  disabled && styles.disabled,
61
60
  ]}>
62
- {children}
61
+ <StackAxisContext.Provider value="horizontal">{children}</StackAxisContext.Provider>
63
62
  </Container>
64
63
  );
65
64
  }
@@ -24,14 +24,26 @@ export function ScrollView({
24
24
  const modifiers = transformToModifiers(
25
25
  style,
26
26
  { onPress: disabled ? undefined : onPress, disabled, hidden, testID },
27
- extraModifiers
27
+ extraModifiers,
28
+ { componentName: 'ScrollView' }
28
29
  );
29
30
 
31
+ // verticalScroll and horizontalScroll clear the main-axis max before measure.
32
+ // A percentage on the scroll axis has no definite parent, so it is ignored.
33
+ // The cross axis still resolves.
30
34
  if (direction === 'horizontal') {
31
- return <Row modifiers={[...modifiers, horizontalScroll()]}>{children}</Row>;
35
+ return (
36
+ <Row resolvesChildPercentages modifiers={[...modifiers, horizontalScroll()]}>
37
+ {children}
38
+ </Row>
39
+ );
32
40
  }
33
41
 
34
- return <Column modifiers={[...modifiers, verticalScroll()]}>{children}</Column>;
42
+ return (
43
+ <Column resolvesChildPercentages modifiers={[...modifiers, verticalScroll()]}>
44
+ {children}
45
+ </Column>
46
+ );
35
47
  }
36
48
 
37
49
  export * from './types';
@@ -34,7 +34,8 @@ export function ScrollView({
34
34
  const scrollModifiers = transformToModifiers(
35
35
  Object.keys(styleWithoutPadding).length > 0 ? (styleWithoutPadding as typeof style) : undefined,
36
36
  { onPress, onAppear, onDisappear, disabled, hidden, testID },
37
- extraModifiers
37
+ extraModifiers,
38
+ { componentName: 'ScrollView' }
38
39
  );
39
40
 
40
41
  // SwiftUI ScrollView centers content by default. Stretch content to fill
@@ -48,10 +48,12 @@ export function Spacer({
48
48
  layoutMods.push(sizeModifier(size, size));
49
49
  }
50
50
 
51
- const modifiers = transformToModifiers(style, { disabled, hidden, testID }, [
52
- ...layoutMods,
53
- ...(extraModifiers ?? []),
54
- ]);
51
+ const modifiers = transformToModifiers(
52
+ style,
53
+ { disabled, hidden, testID },
54
+ [...layoutMods, ...(extraModifiers ?? [])],
55
+ { componentName: 'Spacer' }
56
+ );
55
57
 
56
58
  return <ComposeSpacer modifiers={modifiers} />;
57
59
  }
@@ -30,7 +30,8 @@ export function Spacer({
30
30
  const baseModifiers = transformToModifiers(
31
31
  style,
32
32
  { onAppear, onDisappear, disabled, hidden, testID },
33
- extraModifiers
33
+ extraModifiers,
34
+ { componentName: 'Spacer' }
34
35
  );
35
36
 
36
37
  if (flexible) {
@@ -30,7 +30,8 @@ export function Text({
30
30
  const modifiers = transformToModifiers(
31
31
  style,
32
32
  { onPress: disabled ? undefined : onPress, disabled, hidden, testID },
33
- extraModifiers
33
+ extraModifiers,
34
+ { componentName: 'Text' }
34
35
  );
35
36
 
36
37
  // Build Compose Text style object
@@ -96,7 +96,8 @@ export function Text({
96
96
  const universalModifiers = transformToModifiers(
97
97
  style,
98
98
  { onPress, onAppear, onDisappear, disabled, hidden, testID },
99
- extraModifiers
99
+ extraModifiers,
100
+ { componentName: 'Text' }
100
101
  );
101
102
 
102
103
  // A user-supplied modifier replaces any text-derived modifier of the same type.