@expo/ui 58.0.21 → 58.0.23
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.
- package/CHANGELOG.md +34 -0
- package/README.md +86 -2
- package/android/build.gradle +2 -2
- package/android/src/main/java/expo/modules/ui/ComposeViews.kt +53 -29
- package/android/src/main/java/expo/modules/ui/CompositionLocalProviderView.kt +26 -0
- package/android/src/main/java/expo/modules/ui/ExpoUIModule.kt +12 -0
- package/android/src/main/java/expo/modules/ui/HostView.kt +56 -9
- package/android/src/main/java/expo/modules/ui/MaskView.kt +3 -2
- package/android/src/main/java/expo/modules/ui/ModifierRegistry.kt +43 -13
- package/android/src/main/java/expo/modules/ui/RNHostView.kt +11 -7
- package/android/src/main/java/expo/modules/ui/SwitchView.kt +6 -1
- package/android/src/main/java/expo/modules/ui/TopAppBarView.kt +62 -0
- package/android/src/main/java/expo/modules/ui/UniversalLayout.kt +610 -0
- package/android/src/main/java/expo/modules/ui/colors/MaterialColors.kt +61 -0
- package/android/src/main/java/expo/modules/ui/state/ObservableState.kt +2 -0
- package/android/src/main/java/expo/modules/ui/state/WorkletCallback.kt +2 -0
- package/build/community/bottom-sheet/BottomSheet.ios.js +8 -3
- package/build/community/bottom-sheet/BottomSheet.ios.js.map +1 -1
- package/build/community/pager-view/PagerView.ios.js +25 -8
- package/build/community/pager-view/PagerView.ios.js.map +1 -1
- package/build/community/segmented-control/SegmentedControl.ios.js +11 -2
- package/build/community/segmented-control/SegmentedControl.ios.js.map +1 -1
- package/build/community/segmented-control/types.d.ts +5 -1
- package/build/community/segmented-control/types.js.map +1 -1
- package/build/jetpack-compose/Column/index.d.ts +5 -0
- package/build/jetpack-compose/Column/index.js.map +1 -1
- package/build/jetpack-compose/CompositionLocalProvider/index.d.ts +28 -0
- package/build/jetpack-compose/CompositionLocalProvider/index.js +15 -0
- package/build/jetpack-compose/CompositionLocalProvider/index.js.map +1 -0
- package/build/jetpack-compose/Host/index.d.ts +8 -0
- package/build/jetpack-compose/Host/index.js +38 -5
- package/build/jetpack-compose/Host/index.js.map +1 -1
- package/build/jetpack-compose/Row/index.d.ts +5 -0
- package/build/jetpack-compose/Row/index.js.map +1 -1
- package/build/jetpack-compose/Switch/index.d.ts +2 -0
- package/build/jetpack-compose/Switch/index.js +1 -0
- package/build/jetpack-compose/Switch/index.js.map +1 -1
- package/build/jetpack-compose/TopAppBar/index.d.ts +72 -0
- package/build/jetpack-compose/TopAppBar/index.js +45 -0
- package/build/jetpack-compose/TopAppBar/index.js.map +1 -0
- package/build/jetpack-compose/index.d.ts +2 -0
- package/build/jetpack-compose/index.js +2 -0
- package/build/jetpack-compose/index.js.map +1 -1
- package/build/jetpack-compose/modifiers/index.d.ts +5 -1
- package/build/jetpack-compose/modifiers/index.js +6 -2
- package/build/jetpack-compose/modifiers/index.js.map +1 -1
- package/build/recycling/useRecycledRows.d.ts +2 -0
- package/build/recycling/useRecycledRows.js +1 -0
- package/build/recycling/useRecycledRows.js.map +1 -1
- package/build/swift-ui/BottomSheet/index.d.ts +6 -0
- package/build/swift-ui/BottomSheet/index.js +9 -3
- package/build/swift-ui/BottomSheet/index.js.map +1 -1
- package/build/swift-ui/HStack/index.d.ts +6 -0
- package/build/swift-ui/HStack/index.js.map +1 -1
- package/build/swift-ui/VStack/index.d.ts +6 -0
- package/build/swift-ui/VStack/index.js.map +1 -1
- package/build/universal/Button/index.android.js +3 -1
- package/build/universal/Button/index.android.js.map +1 -1
- package/build/universal/Button/index.ios.js +3 -1
- package/build/universal/Button/index.ios.js.map +1 -1
- package/build/universal/Checkbox/index.android.js +16 -4
- package/build/universal/Checkbox/index.android.js.map +1 -1
- package/build/universal/Collapsible/index.ios.js +1 -0
- package/build/universal/Collapsible/index.ios.js.map +1 -1
- package/build/universal/Column/index.android.js +4 -1
- package/build/universal/Column/index.android.js.map +1 -1
- package/build/universal/Column/index.ios.js +2 -0
- package/build/universal/Column/index.ios.js.map +1 -1
- package/build/universal/Column/index.js +13 -4
- package/build/universal/Column/index.js.map +1 -1
- package/build/universal/FieldGroup/FieldGroup.android.js +3 -1
- package/build/universal/FieldGroup/FieldGroup.android.js.map +1 -1
- package/build/universal/FieldGroup/FieldGroup.ios.js +3 -1
- package/build/universal/FieldGroup/FieldGroup.ios.js.map +1 -1
- package/build/universal/FieldGroup/FieldSection.android.js +13 -4
- package/build/universal/FieldGroup/FieldSection.android.js.map +1 -1
- package/build/universal/FieldGroup/FieldSection.ios.js +3 -1
- package/build/universal/FieldGroup/FieldSection.ios.js.map +1 -1
- package/build/universal/Icon/index.android.js +3 -1
- package/build/universal/Icon/index.android.js.map +1 -1
- package/build/universal/Icon/index.ios.js +3 -1
- package/build/universal/Icon/index.ios.js.map +1 -1
- package/build/universal/List/ListForEach.android.d.ts +7 -0
- package/build/universal/List/ListForEach.android.js +6 -0
- package/build/universal/List/ListForEach.android.js.map +1 -0
- package/build/universal/List/ListForEach.d.ts +5 -0
- package/build/universal/List/ListForEach.ios.d.ts +5 -0
- package/build/universal/List/ListForEach.ios.js +11 -0
- package/build/universal/List/ListForEach.ios.js.map +1 -0
- package/build/universal/List/ListForEach.js +263 -0
- package/build/universal/List/ListForEach.js.map +1 -0
- package/build/universal/List/ListScrollContext.d.ts +5 -0
- package/build/universal/List/ListScrollContext.js +6 -0
- package/build/universal/List/ListScrollContext.js.map +1 -0
- package/build/universal/List/index.android.d.ts +5 -0
- package/build/universal/List/index.android.js +3 -0
- package/build/universal/List/index.android.js.map +1 -1
- package/build/universal/List/index.d.ts +5 -0
- package/build/universal/List/index.ios.d.ts +5 -0
- package/build/universal/List/index.ios.js +3 -0
- package/build/universal/List/index.ios.js.map +1 -1
- package/build/universal/List/index.js +12 -1
- package/build/universal/List/index.js.map +1 -1
- package/build/universal/List/types.d.ts +42 -1
- package/build/universal/List/types.js +1 -3
- package/build/universal/List/types.js.map +1 -1
- package/build/universal/RNHostView/index.android.js +3 -1
- package/build/universal/RNHostView/index.android.js.map +1 -1
- package/build/universal/Row/index.android.js +4 -1
- package/build/universal/Row/index.android.js.map +1 -1
- package/build/universal/Row/index.ios.js +2 -0
- package/build/universal/Row/index.ios.js.map +1 -1
- package/build/universal/Row/index.js +13 -7
- package/build/universal/Row/index.js.map +1 -1
- package/build/universal/ScrollView/index.android.js +8 -1
- package/build/universal/ScrollView/index.android.js.map +1 -1
- package/build/universal/ScrollView/index.ios.js +15 -7
- package/build/universal/ScrollView/index.ios.js.map +1 -1
- package/build/universal/Spacer/index.android.js +3 -1
- package/build/universal/Spacer/index.android.js.map +1 -1
- package/build/universal/Spacer/index.ios.js +3 -1
- package/build/universal/Spacer/index.ios.js.map +1 -1
- package/build/universal/Switch/index.android.js +17 -4
- package/build/universal/Switch/index.android.js.map +1 -1
- package/build/universal/Switch/index.js +1 -0
- package/build/universal/Switch/index.js.map +1 -1
- package/build/universal/Text/index.android.js +3 -1
- package/build/universal/Text/index.android.js.map +1 -1
- package/build/universal/Text/index.ios.js +3 -1
- package/build/universal/Text/index.ios.js.map +1 -1
- package/build/universal/Text/index.js +2 -2
- package/build/universal/Text/index.js.map +1 -1
- package/build/universal/TextInput/index.android.js +22 -7
- package/build/universal/TextInput/index.android.js.map +1 -1
- package/build/universal/TextInput/index.ios.js +1 -0
- package/build/universal/TextInput/index.ios.js.map +1 -1
- package/build/universal/index.d.ts +1 -1
- package/build/universal/modifierUtils.d.ts +34 -1
- package/build/universal/modifierUtils.js +98 -2
- package/build/universal/modifierUtils.js.map +1 -1
- package/build/universal/stackAxis.d.ts +9 -0
- package/build/universal/stackAxis.js +11 -0
- package/build/universal/stackAxis.js.map +1 -0
- package/build/universal/transformStyle.android.d.ts +6 -2
- package/build/universal/transformStyle.android.js +18 -11
- package/build/universal/transformStyle.android.js.map +1 -1
- package/build/universal/transformStyle.ios.d.ts +5 -1
- package/build/universal/transformStyle.ios.js +29 -11
- package/build/universal/transformStyle.ios.js.map +1 -1
- package/build/universal/types.d.ts +26 -1
- package/build/universal/types.js.map +1 -1
- package/build/universal/webUtils.js +4 -0
- package/build/universal/webUtils.js.map +1 -1
- package/ios/BottomSheetView.swift +11 -2
- package/ios/DatePickerView.swift +134 -9
- package/ios/GroupView.swift +3 -0
- package/ios/HStackView.swift +26 -2
- package/ios/HostView.swift +21 -12
- package/ios/Modifiers/SelectedSegmentTintColorModifier.swift +86 -0
- package/ios/Modifiers/ViewModifierRegistry.swift +8 -0
- package/ios/RNHostView.swift +34 -16
- package/ios/ScrollViewComponent.swift +20 -0
- package/ios/UIBaseView.swift +4 -1
- package/ios/UniversalLayout.swift +691 -0
- package/ios/VStackView.swift +26 -2
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/{58.0.21/expo.modules.ui-58.0.21-sources.jar → 58.0.23/expo.modules.ui-58.0.23-sources.jar} +0 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23-sources.jar.md5 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23-sources.jar.sha1 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23-sources.jar.sha256 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23-sources.jar.sha512 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.aar +0 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.aar.md5 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.aar.sha1 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.aar.sha256 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.aar.sha512 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/{58.0.21/expo.modules.ui-58.0.21.module → 58.0.23/expo.modules.ui-58.0.23.module} +22 -22
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.module.md5 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.module.sha1 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.module.sha256 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.module.sha512 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/{58.0.21/expo.modules.ui-58.0.21.pom → 58.0.23/expo.modules.ui-58.0.23.pom} +1 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.pom.md5 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.pom.sha1 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.pom.sha256 +1 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.23/expo.modules.ui-58.0.23.pom.sha512 +1 -0
- package/package.json +2 -2
- package/src/community/bottom-sheet/BottomSheet.ios.tsx +7 -3
- package/src/community/pager-view/PagerView.ios.tsx +25 -8
- package/src/community/segmented-control/SegmentedControl.ios.tsx +13 -1
- package/src/community/segmented-control/types.tsx +5 -1
- package/src/jetpack-compose/Column/index.tsx +5 -0
- package/src/jetpack-compose/CompositionLocalProvider/index.tsx +43 -0
- package/src/jetpack-compose/Host/index.tsx +50 -4
- package/src/jetpack-compose/Row/index.tsx +5 -0
- package/src/jetpack-compose/Switch/index.tsx +4 -0
- package/src/jetpack-compose/TopAppBar/index.tsx +113 -0
- package/src/jetpack-compose/index.ts +2 -0
- package/src/jetpack-compose/modifiers/index.ts +11 -3
- package/src/recycling/useRecycledRows.tsx +3 -0
- package/src/swift-ui/BottomSheet/index.tsx +24 -3
- package/src/swift-ui/HStack/index.tsx +6 -0
- package/src/swift-ui/VStack/index.tsx +6 -0
- package/src/universal/Button/index.android.tsx +3 -1
- package/src/universal/Button/index.ios.tsx +2 -1
- package/src/universal/Checkbox/index.android.tsx +24 -5
- package/src/universal/Collapsible/index.ios.tsx +4 -1
- package/src/universal/Column/index.android.tsx +3 -1
- package/src/universal/Column/index.ios.tsx +2 -1
- package/src/universal/Column/index.tsx +9 -4
- package/src/universal/FieldGroup/FieldGroup.android.tsx +8 -1
- package/src/universal/FieldGroup/FieldGroup.ios.tsx +2 -1
- package/src/universal/FieldGroup/FieldSection.android.tsx +17 -4
- package/src/universal/FieldGroup/FieldSection.ios.tsx +2 -1
- package/src/universal/Icon/index.android.tsx +2 -1
- package/src/universal/Icon/index.ios.tsx +2 -1
- package/src/universal/List/ListForEach.android.tsx +6 -0
- package/src/universal/List/ListForEach.ios.tsx +9 -0
- package/src/universal/List/ListForEach.tsx +246 -0
- package/src/universal/List/ListScrollContext.ts +6 -0
- package/src/universal/List/index.android.tsx +5 -0
- package/src/universal/List/index.ios.tsx +5 -0
- package/src/universal/List/index.tsx +11 -2
- package/src/universal/List/types.ts +45 -1
- package/src/universal/RNHostView/index.android.tsx +2 -1
- package/src/universal/Row/index.android.tsx +3 -1
- package/src/universal/Row/index.ios.tsx +2 -1
- package/src/universal/Row/index.tsx +9 -10
- package/src/universal/ScrollView/index.android.tsx +15 -3
- package/src/universal/ScrollView/index.ios.tsx +16 -4
- package/src/universal/Spacer/index.android.tsx +6 -4
- package/src/universal/Spacer/index.ios.tsx +2 -1
- package/src/universal/Switch/index.android.tsx +23 -4
- package/src/universal/Switch/index.tsx +1 -0
- package/src/universal/Text/index.android.tsx +2 -1
- package/src/universal/Text/index.ios.tsx +2 -1
- package/src/universal/Text/index.tsx +2 -2
- package/src/universal/TextInput/index.android.tsx +26 -5
- package/src/universal/TextInput/index.ios.tsx +1 -1
- package/src/universal/index.ts +6 -1
- package/src/universal/modifierUtils.ts +159 -2
- package/src/universal/stackAxis.ts +17 -0
- package/src/universal/transformStyle.android.ts +30 -12
- package/src/universal/transformStyle.ios.ts +41 -13
- package/src/universal/types.ts +27 -3
- package/src/universal/webUtils.ts +4 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21-sources.jar.md5 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21-sources.jar.sha1 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21-sources.jar.sha256 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21-sources.jar.sha512 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.aar +0 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.aar.md5 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.aar.sha1 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.aar.sha256 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.aar.sha512 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.module.md5 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.module.sha1 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.module.sha256 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.module.sha512 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.pom.md5 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.pom.sha1 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.pom.sha256 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.21/expo.modules.ui-58.0.21.pom.sha512 +0 -1
|
@@ -59,6 +59,7 @@ export * from './SearchBar';
|
|
|
59
59
|
export * from './Snackbar';
|
|
60
60
|
export * from './DockedSearchBar';
|
|
61
61
|
export * from './HorizontalFloatingToolbar';
|
|
62
|
+
export * from './TopAppBar';
|
|
62
63
|
export * from './FloatingActionButton';
|
|
63
64
|
export * from './PullToRefreshBox';
|
|
64
65
|
export * from './RadioButton';
|
|
@@ -71,6 +72,7 @@ export * from './AnimatedVisibility';
|
|
|
71
72
|
export * from './Box';
|
|
72
73
|
export * from './Row';
|
|
73
74
|
export * from './Column';
|
|
75
|
+
export * from './CompositionLocalProvider';
|
|
74
76
|
export * from './FlowRow';
|
|
75
77
|
export { useNativeState, useWorkletCallback, type WorkletCallback } from '../State';
|
|
76
78
|
export type { ViewEvent } from '../types';
|
|
@@ -403,13 +403,21 @@ export const selectableGroup = () => createModifier('selectableGroup');
|
|
|
403
403
|
* @param value - The current toggle state.
|
|
404
404
|
* @param handler - Function to call when toggled.
|
|
405
405
|
* @param options - Optional configuration.
|
|
406
|
-
* @param options.role - The semantic role for accessibility: `'checkbox'`, `'radioButton'`,
|
|
406
|
+
* @param options.role - The semantic role for accessibility: `'checkbox'`, `'radioButton'`,
|
|
407
|
+
* `'switch'`, or `'tab'`.
|
|
408
|
+
* @param options.enabled - Whether the view responds to input and is reported as enabled to
|
|
409
|
+
* accessibility services. Defaults to `true`.
|
|
407
410
|
*/
|
|
408
411
|
export const toggleable = (
|
|
409
412
|
value: boolean,
|
|
410
413
|
handler: () => void,
|
|
411
|
-
options?: { role?: 'checkbox' | 'radioButton' | 'switch' | 'tab' }
|
|
412
|
-
) =>
|
|
414
|
+
options?: { role?: 'checkbox' | 'radioButton' | 'switch' | 'tab'; enabled?: boolean }
|
|
415
|
+
) =>
|
|
416
|
+
createModifierWithEventListener('toggleable', handler, {
|
|
417
|
+
value,
|
|
418
|
+
role: options?.role,
|
|
419
|
+
enabled: options?.enabled,
|
|
420
|
+
});
|
|
413
421
|
|
|
414
422
|
// =============================================================================
|
|
415
423
|
// Lifecycle Modifiers
|
|
@@ -53,6 +53,8 @@ export type RecycledRows = {
|
|
|
53
53
|
revision: number;
|
|
54
54
|
/** The pooled rows to mount, one per slot. */
|
|
55
55
|
rows: ReactElement[];
|
|
56
|
+
/** Index of the first item in the pool. */
|
|
57
|
+
start: number;
|
|
56
58
|
/** Applies a native window request. */
|
|
57
59
|
onWindowChange: (event: WindowChangeEvent) => void;
|
|
58
60
|
/** Whether a native event was sent for the data currently committed to native. */
|
|
@@ -169,6 +171,7 @@ export function useRecycledRows<ItemT>({
|
|
|
169
171
|
itemKeys,
|
|
170
172
|
revision: current.revision,
|
|
171
173
|
rows,
|
|
174
|
+
start,
|
|
172
175
|
isCurrentRevision: (revision) => revision === committedRevision.current,
|
|
173
176
|
onWindowChange: (event) => {
|
|
174
177
|
if (
|
|
@@ -18,6 +18,12 @@ export interface BottomSheetProps extends CommonViewModifierProps {
|
|
|
18
18
|
* kept mounted, so presenting the sheet doesn't shift surrounding layout. Optional.
|
|
19
19
|
*/
|
|
20
20
|
anchor?: ReactNode;
|
|
21
|
+
/**
|
|
22
|
+
* A view that fills the whole sheet behind its content, for example a `Rectangle` filled with a
|
|
23
|
+
* material. Unlike the `presentationBackground` modifier, a material in a view stays translucent
|
|
24
|
+
* on iOS 26 and later.
|
|
25
|
+
*/
|
|
26
|
+
presentationBackground?: ReactNode;
|
|
21
27
|
/**
|
|
22
28
|
* Whether the `BottomSheet` is presented.
|
|
23
29
|
*/
|
|
@@ -40,7 +46,7 @@ export interface BottomSheetProps extends CommonViewModifierProps {
|
|
|
40
46
|
|
|
41
47
|
type NativeBottomSheetProps = Omit<
|
|
42
48
|
BottomSheetProps,
|
|
43
|
-
'onIsPresentedChange' | 'onDismiss' | 'anchor'
|
|
49
|
+
'onIsPresentedChange' | 'onDismiss' | 'anchor' | 'presentationBackground'
|
|
44
50
|
> & {
|
|
45
51
|
onIsPresentedChange: (event: NativeSyntheticEvent<{ isPresented: boolean }>) => void;
|
|
46
52
|
onDismiss: (event: NativeSyntheticEvent<object>) => void;
|
|
@@ -55,7 +61,15 @@ const BottomSheetNativeView: ComponentType<NativeBottomSheetProps> = requireNati
|
|
|
55
61
|
* `BottomSheet` presents content from the bottom of the screen.
|
|
56
62
|
*/
|
|
57
63
|
function BottomSheet(props: BottomSheetProps) {
|
|
58
|
-
const {
|
|
64
|
+
const {
|
|
65
|
+
modifiers,
|
|
66
|
+
onIsPresentedChange,
|
|
67
|
+
onDismiss,
|
|
68
|
+
anchor,
|
|
69
|
+
presentationBackground,
|
|
70
|
+
children,
|
|
71
|
+
...restProps
|
|
72
|
+
} = props;
|
|
59
73
|
const [isMounted, setIsMounted] = useState(props.isPresented);
|
|
60
74
|
|
|
61
75
|
if (props.isPresented && !isMounted) {
|
|
@@ -79,7 +93,14 @@ function BottomSheet(props: BottomSheetProps) {
|
|
|
79
93
|
{anchor != null ? <Slot name="anchor">{anchor}</Slot> : null}
|
|
80
94
|
{/* Only the sheet's content is presented in its own view controller. The anchor renders in
|
|
81
95
|
place, in the React Native surface, so it stays outside `PresentedContent`. */}
|
|
82
|
-
{isMounted ?
|
|
96
|
+
{isMounted ? (
|
|
97
|
+
<PresentedContent>
|
|
98
|
+
{presentationBackground != null ? (
|
|
99
|
+
<Slot name="presentationBackground">{presentationBackground}</Slot>
|
|
100
|
+
) : null}
|
|
101
|
+
{children}
|
|
102
|
+
</PresentedContent>
|
|
103
|
+
) : null}
|
|
83
104
|
</BottomSheetNativeView>
|
|
84
105
|
);
|
|
85
106
|
}
|
|
@@ -13,6 +13,12 @@ export interface HStackProps extends CommonViewModifierProps {
|
|
|
13
13
|
* The vertical alignment of children within the stack.
|
|
14
14
|
*/
|
|
15
15
|
alignment?: 'top' | 'center' | 'bottom' | 'firstTextBaseline' | 'lastTextBaseline';
|
|
16
|
+
/**
|
|
17
|
+
* When `true`, a child percentage is a fraction of this stack.
|
|
18
|
+
* Universal `Row` sets this. Leave it unset to keep the SwiftUI `HStack`.
|
|
19
|
+
* @hidden
|
|
20
|
+
*/
|
|
21
|
+
resolvesChildPercentages?: boolean;
|
|
16
22
|
}
|
|
17
23
|
|
|
18
24
|
const HStackNativeView: React.ComponentType<HStackProps> = requireNativeView(
|
|
@@ -13,6 +13,12 @@ export interface VStackProps extends CommonViewModifierProps {
|
|
|
13
13
|
* The spacing between children.
|
|
14
14
|
*/
|
|
15
15
|
spacing?: number;
|
|
16
|
+
/**
|
|
17
|
+
* When `true`, a child percentage is a fraction of this stack.
|
|
18
|
+
* Universal `Column` sets this. Leave it unset to keep the SwiftUI `VStack`.
|
|
19
|
+
* @hidden
|
|
20
|
+
*/
|
|
21
|
+
resolvesChildPercentages?: boolean;
|
|
16
22
|
}
|
|
17
23
|
|
|
18
24
|
const VStackNativeView: React.ComponentType<VStackProps> = requireNativeView(
|
|
@@ -26,7 +26,9 @@ export function Button({
|
|
|
26
26
|
|
|
27
27
|
if (hidden) return null;
|
|
28
28
|
|
|
29
|
-
const modifiers = transformToModifiers(style, { disabled, hidden, testID }, extraModifiers
|
|
29
|
+
const modifiers = transformToModifiers(style, { disabled, hidden, testID }, extraModifiers, {
|
|
30
|
+
componentName: 'Button',
|
|
31
|
+
});
|
|
30
32
|
|
|
31
33
|
const content = children ?? <Text>{label ?? ''}</Text>;
|
|
32
34
|
const commonProps = {
|
|
@@ -34,7 +34,8 @@ export function Button({
|
|
|
34
34
|
const universalModifiers = transformToModifiers(
|
|
35
35
|
style,
|
|
36
36
|
{ onAppear, onDisappear, disabled, hidden, testID },
|
|
37
|
-
extraModifiers
|
|
37
|
+
extraModifiers,
|
|
38
|
+
{ componentName: 'Button' }
|
|
38
39
|
);
|
|
39
40
|
|
|
40
41
|
const modifiers = [...buttonSpecificModifiers, ...universalModifiers];
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { Checkbox as ComposeCheckbox, Row, Text } from '@expo/ui/jetpack-compose';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
defaultMinSize,
|
|
4
|
+
testID as testIDModifier,
|
|
5
|
+
toggleable,
|
|
6
|
+
} from '@expo/ui/jetpack-compose/modifiers';
|
|
3
7
|
|
|
4
8
|
import type { CheckboxProps } from './types';
|
|
5
9
|
|
|
10
|
+
// Material's minimum touch target.
|
|
11
|
+
const MIN_INTERACTIVE_SIZE = 48;
|
|
12
|
+
|
|
6
13
|
export function Checkbox({
|
|
7
14
|
value,
|
|
8
15
|
onValueChange,
|
|
@@ -11,22 +18,34 @@ export function Checkbox({
|
|
|
11
18
|
testID,
|
|
12
19
|
modifiers,
|
|
13
20
|
}: CheckboxProps) {
|
|
21
|
+
const isLabeled = label != null;
|
|
14
22
|
const checkbox = (
|
|
15
23
|
<ComposeCheckbox
|
|
16
24
|
value={value}
|
|
17
|
-
onCheckedChange={
|
|
25
|
+
onCheckedChange={isLabeled ? undefined : onValueChange}
|
|
18
26
|
enabled={!disabled}
|
|
19
|
-
modifiers={[
|
|
27
|
+
modifiers={[
|
|
28
|
+
...(modifiers ?? []),
|
|
29
|
+
...(isLabeled
|
|
30
|
+
? [defaultMinSize({ minWidth: MIN_INTERACTIVE_SIZE, minHeight: MIN_INTERACTIVE_SIZE })]
|
|
31
|
+
: []),
|
|
32
|
+
...(testID ? [testIDModifier(testID)] : []),
|
|
33
|
+
]}
|
|
20
34
|
/>
|
|
21
35
|
);
|
|
22
36
|
|
|
23
|
-
if (
|
|
37
|
+
if (!isLabeled) return checkbox;
|
|
24
38
|
|
|
25
39
|
return (
|
|
26
40
|
<Row
|
|
27
41
|
verticalAlignment="center"
|
|
28
42
|
horizontalArrangement={{ spacedBy: 8 }}
|
|
29
|
-
modifiers={[
|
|
43
|
+
modifiers={[
|
|
44
|
+
toggleable(value, () => !disabled && onValueChange(!value), {
|
|
45
|
+
role: 'checkbox',
|
|
46
|
+
enabled: !disabled,
|
|
47
|
+
}),
|
|
48
|
+
]}>
|
|
30
49
|
{checkbox}
|
|
31
50
|
<Text>{label}</Text>
|
|
32
51
|
</Row>
|
|
@@ -14,7 +14,10 @@ export function Collapsible({
|
|
|
14
14
|
children,
|
|
15
15
|
}: CollapsibleProps) {
|
|
16
16
|
const labelTextModifiers = labelStyle
|
|
17
|
-
? transformToModifiers(undefined, {}, undefined, {
|
|
17
|
+
? transformToModifiers(undefined, {}, undefined, {
|
|
18
|
+
componentName: 'Collapsible',
|
|
19
|
+
textStyle: labelStyle,
|
|
20
|
+
})
|
|
18
21
|
: undefined;
|
|
19
22
|
|
|
20
23
|
return (
|
|
@@ -31,13 +31,15 @@ export function Column({
|
|
|
31
31
|
const modifiers = transformToModifiers(
|
|
32
32
|
style,
|
|
33
33
|
{ onPress: disabled ? undefined : onPress, disabled, hidden, testID },
|
|
34
|
-
extraModifiers
|
|
34
|
+
extraModifiers,
|
|
35
|
+
{ componentName: 'Column' }
|
|
35
36
|
);
|
|
36
37
|
|
|
37
38
|
return (
|
|
38
39
|
<ComposeColumn
|
|
39
40
|
horizontalAlignment={alignmentMap[alignment]}
|
|
40
41
|
verticalArrangement={spacing != null ? { spacedBy: spacing } : undefined}
|
|
42
|
+
resolvesChildPercentages
|
|
41
43
|
modifiers={modifiers}>
|
|
42
44
|
{children}
|
|
43
45
|
</ComposeColumn>
|
|
@@ -33,7 +33,7 @@ export function Column({
|
|
|
33
33
|
style,
|
|
34
34
|
{ onPress, onAppear, onDisappear, disabled, hidden, testID },
|
|
35
35
|
extraModifiers,
|
|
36
|
-
{ frameAlignment: frameAlignmentMap[alignment] }
|
|
36
|
+
{ componentName: 'Column', frameAlignment: frameAlignmentMap[alignment] }
|
|
37
37
|
);
|
|
38
38
|
|
|
39
39
|
return (
|
|
@@ -41,6 +41,7 @@ export function Column({
|
|
|
41
41
|
alignment={alignmentMap[alignment]}
|
|
42
42
|
spacing={spacing}
|
|
43
43
|
modifiers={modifiers}
|
|
44
|
+
resolvesChildPercentages
|
|
44
45
|
testID={testID}>
|
|
45
46
|
{children}
|
|
46
47
|
</VStack>
|
|
@@ -1,13 +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 { ColumnProps } from './types';
|
|
6
7
|
|
|
7
8
|
const styles = StyleSheet.create({
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
|
|
9
|
+
column: { flexDirection: 'column' },
|
|
10
|
+
// Fill the parent's cross axis when this column has no size of its own on that axis.
|
|
11
|
+
// A set size must not use stretch: that overrides the parent's `alignItems`,
|
|
12
|
+
// and the column then sits at the start.
|
|
13
|
+
stretch: { alignSelf: 'stretch' },
|
|
11
14
|
hidden: { display: 'none' },
|
|
12
15
|
disabled: {
|
|
13
16
|
opacity: 0.5,
|
|
@@ -37,6 +40,7 @@ export function Column({
|
|
|
37
40
|
testID,
|
|
38
41
|
}: ColumnProps) {
|
|
39
42
|
useUniversalLifecycle(onAppear, onDisappear);
|
|
43
|
+
const crossAxisSize = useCrossAxisSize(style);
|
|
40
44
|
|
|
41
45
|
const Container = onPress ? Pressable : View;
|
|
42
46
|
|
|
@@ -47,13 +51,14 @@ export function Column({
|
|
|
47
51
|
testID={testID}
|
|
48
52
|
style={[
|
|
49
53
|
styles.column,
|
|
54
|
+
crossAxisSize == null && styles.stretch,
|
|
50
55
|
alignmentStyles[alignment],
|
|
51
56
|
spacing != null && { gap: spacing },
|
|
52
57
|
style,
|
|
53
58
|
hidden && styles.hidden,
|
|
54
59
|
disabled && styles.disabled,
|
|
55
60
|
]}>
|
|
56
|
-
{children}
|
|
61
|
+
<StackAxisContext.Provider value="vertical">{children}</StackAxisContext.Provider>
|
|
57
62
|
</Container>
|
|
58
63
|
);
|
|
59
64
|
}
|
|
@@ -27,7 +27,14 @@ export function FieldGroup({
|
|
|
27
27
|
if (hidden) return null;
|
|
28
28
|
|
|
29
29
|
const mergedStyle = { backgroundColor: colors.surface, ...style };
|
|
30
|
-
const modifiers = transformToModifiers(
|
|
30
|
+
const modifiers = transformToModifiers(
|
|
31
|
+
mergedStyle,
|
|
32
|
+
{ disabled, hidden, testID },
|
|
33
|
+
extraModifiers,
|
|
34
|
+
{
|
|
35
|
+
componentName: 'FieldGroup',
|
|
36
|
+
}
|
|
37
|
+
);
|
|
31
38
|
|
|
32
39
|
return (
|
|
33
40
|
<LazyColumn
|
|
@@ -20,7 +20,8 @@ export function FieldGroup({
|
|
|
20
20
|
const modifiers = transformToModifiers(
|
|
21
21
|
style,
|
|
22
22
|
{ onAppear, onDisappear, disabled, hidden, testID },
|
|
23
|
-
extraModifiers
|
|
23
|
+
extraModifiers,
|
|
24
|
+
{ componentName: 'FieldGroup' }
|
|
24
25
|
);
|
|
25
26
|
|
|
26
27
|
return <Form modifiers={modifiers}>{children}</Form>;
|
|
@@ -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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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 ??
|
|
@@ -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
|
+
}
|