@expo/ui 58.0.22 → 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 +12 -0
- 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/HostView.kt +52 -8
- package/android/src/main/java/expo/modules/ui/ModifierRegistry.kt +40 -12
- package/android/src/main/java/expo/modules/ui/UniversalLayout.kt +610 -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/jetpack-compose/Column/index.d.ts +5 -0
- package/build/jetpack-compose/Column/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/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/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/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 +3 -1
- 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/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/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/ios/GroupView.swift +3 -0
- package/ios/HStackView.swift +26 -2
- package/ios/HostView.swift +21 -12
- package/ios/Modifiers/ViewModifierRegistry.swift +4 -0
- 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.22/expo.modules.ui-58.0.22-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.22/expo.modules.ui-58.0.22.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.22/expo.modules.ui-58.0.22.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 +1 -1
- package/src/jetpack-compose/Column/index.tsx +5 -0
- package/src/jetpack-compose/Row/index.tsx +5 -0
- package/src/recycling/useRecycledRows.tsx +3 -0
- 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/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 +2 -1
- package/src/universal/Spacer/index.android.tsx +6 -4
- package/src/universal/Spacer/index.ios.tsx +2 -1
- package/src/universal/Text/index.android.tsx +2 -1
- package/src/universal/Text/index.ios.tsx +2 -1
- 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/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22-sources.jar.md5 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22-sources.jar.sha1 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22-sources.jar.sha256 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22-sources.jar.sha512 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.aar +0 -0
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.aar.md5 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.aar.sha1 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.aar.sha256 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.aar.sha512 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.module.md5 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.module.sha1 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.module.sha256 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.module.sha512 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.pom.md5 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.pom.sha1 +0 -1
- package/local-maven-repo/expo/modules/ui/expo.modules.ui/58.0.22/expo.modules.ui-58.0.22.pom.sha256 +0 -1
- 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,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
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
35
|
+
return (
|
|
36
|
+
<Row resolvesChildPercentages modifiers={[...modifiers, horizontalScroll()]}>
|
|
37
|
+
{children}
|
|
38
|
+
</Row>
|
|
39
|
+
);
|
|
32
40
|
}
|
|
33
41
|
|
|
34
|
-
return
|
|
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(
|
|
52
|
-
|
|
53
|
-
|
|
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 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.
|
|
@@ -26,6 +26,17 @@ function mapReturnKeyType(value: ReturnKeyTypeOptions): TextFieldImeAction {
|
|
|
26
26
|
return value as TextFieldImeAction;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
function mapSecureKeyboardType(value: KeyboardTypeOptions | undefined): TextFieldKeyboardType {
|
|
30
|
+
switch (value) {
|
|
31
|
+
case 'numeric':
|
|
32
|
+
case 'number-pad':
|
|
33
|
+
case 'decimal-pad':
|
|
34
|
+
return 'numberPassword';
|
|
35
|
+
default:
|
|
36
|
+
return 'password';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
29
40
|
function mapKeyboardType(value: KeyboardTypeOptions): TextFieldKeyboardType {
|
|
30
41
|
switch (value) {
|
|
31
42
|
case 'default':
|
|
@@ -133,12 +144,23 @@ export function TextInput({
|
|
|
133
144
|
else onBlur?.();
|
|
134
145
|
};
|
|
135
146
|
|
|
147
|
+
// `visualTransformation` only masks the text. The keyboard reads the keyboard type,
|
|
148
|
+
// so a secure field also needs a password type.
|
|
149
|
+
const resolvedKeyboardType = secureTextEntry
|
|
150
|
+
? mapSecureKeyboardType(keyboardType)
|
|
151
|
+
: keyboardType
|
|
152
|
+
? mapKeyboardType(keyboardType)
|
|
153
|
+
: undefined;
|
|
154
|
+
const resolvedAutoCorrect = secureTextEntry ? false : autoCorrect;
|
|
155
|
+
|
|
136
156
|
const keyboardOptions =
|
|
137
|
-
|
|
157
|
+
resolvedKeyboardType || autoCapitalize || resolvedAutoCorrect !== undefined || returnKeyType
|
|
138
158
|
? {
|
|
139
|
-
...(
|
|
159
|
+
...(resolvedKeyboardType ? { keyboardType: resolvedKeyboardType } : null),
|
|
140
160
|
...(autoCapitalize ? { capitalization: autoCapitalize } : null),
|
|
141
|
-
...(
|
|
161
|
+
...(resolvedAutoCorrect !== undefined
|
|
162
|
+
? { autoCorrectEnabled: resolvedAutoCorrect }
|
|
163
|
+
: null),
|
|
142
164
|
...(returnKeyType ? { imeAction: mapReturnKeyType(returnKeyType) } : null),
|
|
143
165
|
}
|
|
144
166
|
: undefined;
|
|
@@ -158,8 +180,7 @@ export function TextInput({
|
|
|
158
180
|
<BasicTextField
|
|
159
181
|
ref={innerRef}
|
|
160
182
|
modifiers={[
|
|
161
|
-
...(userModifiers
|
|
162
|
-
...transformToModifiers(style, {}),
|
|
183
|
+
...transformToModifiers(style, {}, userModifiers, { componentName: 'TextInput' }),
|
|
163
184
|
...(testID ? [testIDModifier(testID)] : []),
|
|
164
185
|
...(autoComplete ? [semantics({ contentType: autoComplete })] : []),
|
|
165
186
|
...(onContentSizeChange ? [onSizeChanged(onContentSizeChange)] : []),
|
|
@@ -149,7 +149,7 @@ export function TextInput({
|
|
|
149
149
|
|
|
150
150
|
const modifiers: ModifierConfig[] = [
|
|
151
151
|
...(userModifiers ?? []),
|
|
152
|
-
...transformToModifiers(style, {}, undefined, { textStyle }),
|
|
152
|
+
...transformToModifiers(style, {}, undefined, { componentName: 'TextInput', textStyle }),
|
|
153
153
|
];
|
|
154
154
|
if (editable === false) modifiers.push(disabledMod(true));
|
|
155
155
|
if (keyboardType) modifiers.push(keyboardTypeMod(mapKeyboardType(keyboardType)));
|
package/src/universal/index.ts
CHANGED
|
@@ -19,4 +19,9 @@ export * from './Spacer';
|
|
|
19
19
|
export * from './State';
|
|
20
20
|
export { TextInput, type TextInputProps, type TextInputRef } from './TextInput';
|
|
21
21
|
|
|
22
|
-
export type {
|
|
22
|
+
export type {
|
|
23
|
+
UniversalStyle,
|
|
24
|
+
UniversalAlignment,
|
|
25
|
+
UniversalBaseProps,
|
|
26
|
+
UniversalDimension,
|
|
27
|
+
} from './types';
|