react-native-terra-ui 0.4.0 → 0.4.1

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 (30) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/lib/module/components/screen/Screen.js +4 -1
  3. package/lib/module/components/screen/Screen.js.map +1 -1
  4. package/lib/module/components/screen/ScreenFlashList.js +48 -35
  5. package/lib/module/components/screen/ScreenFlashList.js.map +1 -1
  6. package/lib/module/components/screen/ScreenFlatList.js +40 -31
  7. package/lib/module/components/screen/ScreenFlatList.js.map +1 -1
  8. package/lib/module/components/screen/ScreenList.js +160 -0
  9. package/lib/module/components/screen/ScreenList.js.map +1 -0
  10. package/lib/module/components/screen/ScreenScrollView.js +26 -14
  11. package/lib/module/components/screen/ScreenScrollView.js.map +1 -1
  12. package/lib/module/components/screen/index.js +1 -0
  13. package/lib/module/components/screen/index.js.map +1 -1
  14. package/lib/module/theme/tokens/primitives.js +3 -3
  15. package/lib/typescript/src/components/screen/Screen.d.ts +2 -0
  16. package/lib/typescript/src/components/screen/Screen.d.ts.map +1 -1
  17. package/lib/typescript/src/components/screen/ScreenFlashList.d.ts.map +1 -1
  18. package/lib/typescript/src/components/screen/ScreenFlatList.d.ts.map +1 -1
  19. package/lib/typescript/src/components/screen/ScreenList.d.ts +64 -0
  20. package/lib/typescript/src/components/screen/ScreenList.d.ts.map +1 -0
  21. package/lib/typescript/src/components/screen/index.d.ts +2 -0
  22. package/lib/typescript/src/components/screen/index.d.ts.map +1 -1
  23. package/package.json +1 -1
  24. package/src/components/screen/Screen.tsx +5 -1
  25. package/src/components/screen/ScreenFlashList.tsx +51 -38
  26. package/src/components/screen/ScreenFlatList.tsx +41 -30
  27. package/src/components/screen/ScreenList.tsx +269 -0
  28. package/src/components/screen/ScreenScrollView.tsx +19 -10
  29. package/src/components/screen/index.ts +2 -0
  30. package/src/theme/tokens/primitives.ts +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"Screen.d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;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,EACjC,IAAI,EACJ,KAAK,EACL,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,UAAkB,EAClB,OAAe,EACf,gBAAgB,EAChB,cAAc,EACd,OAAO,EACP,WAAW,EACX,QAAQ,EACR,GAAG,IAAI,EACR,EAAE,oBAAoB,CAAC,CAAC,CAAC,+BAkFzB"}
1
+ {"version":3,"file":"ScreenFlashList.d.ts","sourceRoot":"","sources":["../../../../../src/components/screen/ScreenFlashList.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAmBrE,OAAO,KAAK,EAAiB,qBAAqB,EAAE,MAAM,YAAS,CAAC;AAOpE,MAAM,WAAW,oBAAoB,CAAC,CAAC,CACrC,SAAQ,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,EAC3C,qBAAqB;IACvB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,EACjC,IAAI,EACJ,KAAK,EACL,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,UAAkB,EAClB,OAAe,EACf,gBAAgB,EAChB,cAAc,EACd,OAAO,EACP,WAAW,EACX,QAAQ,EACR,GAAG,IAAI,EACR,EAAE,oBAAoB,CAAC,CAAC,CAAC,+BAyFzB"}
@@ -1 +1 @@
1
- {"version":3,"file":"ScreenFlatList.d.ts","sourceRoot":"","sources":["../../../../../src/components/screen/ScreenFlatList.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAInB,MAAM,cAAc,CAAC;AActB,OAAO,KAAK,EAAiB,qBAAqB,EAAE,MAAM,YAAS,CAAC;AAGpE,MAAM,WAAW,mBAAmB,CAAC,CAAC,CACpC,SAAQ,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,uBAAuB,GAAG,YAAY,CAAC,EACpE,qBAAqB;IACvB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,EAChC,IAAI,EACJ,KAAK,EACL,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,UAAkB,EAClB,OAAe,EACf,gBAAgB,EAChB,cAAc,EACd,OAAO,EACP,WAAW,EACX,QAAQ,EACR,GAAG,IAAI,EACR,EAAE,mBAAmB,CAAC,CAAC,CAAC,+BA2ExB"}
1
+ {"version":3,"file":"ScreenFlatList.d.ts","sourceRoot":"","sources":["../../../../../src/components/screen/ScreenFlatList.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAInB,MAAM,cAAc,CAAC;AActB,OAAO,KAAK,EAAiB,qBAAqB,EAAE,MAAM,YAAS,CAAC;AAGpE,MAAM,WAAW,mBAAmB,CAAC,CAAC,CACpC,SAAQ,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,uBAAuB,GAAG,YAAY,CAAC,EACpE,qBAAqB;IACvB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,EAChC,IAAI,EACJ,KAAK,EACL,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,UAAkB,EAClB,OAAe,EACf,gBAAgB,EAChB,cAAc,EACd,OAAO,EACP,WAAW,EACX,QAAQ,EACR,GAAG,IAAI,EACR,EAAE,mBAAmB,CAAC,CAAC,CAAC,+BAiFxB"}
@@ -0,0 +1,64 @@
1
+ import { type ComponentPropsWithoutRef, type ElementType, type ReactElement } from 'react';
2
+ import { FlatList, type NativeScrollEvent, type NativeSyntheticEvent, type StyleProp, type ViewStyle } from 'react-native';
3
+ import type { ScreenScrollableProps } from './types.js';
4
+ import { type ListHeaderComponent } from './utils.js';
5
+ export interface ScreenListRenderItemInfo<T> {
6
+ item: T;
7
+ index: number;
8
+ }
9
+ export type ScreenListProps<T = unknown, As extends ElementType = typeof FlatList> = ScreenScrollableProps & Omit<ComponentPropsWithoutRef<As>, 'data' | 'renderItem' | 'keyExtractor' | 'style' | 'contentContainerStyle' | 'onScroll' | 'ListHeaderComponent' | 'ListFooterComponent' | 'ListEmptyComponent' | keyof ScreenScrollableProps> & {
10
+ /**
11
+ * Which list component to render as. Defaults to React Native's
12
+ * `FlatList` — pass any list with a FlatList-shaped prop surface
13
+ * (`data`, `renderItem`, `ListHeaderComponent`, …), e.g. `FlashList`
14
+ * from `@shopify/flash-list`, or a custom virtualized list.
15
+ *
16
+ * Only the default `FlatList` binds the screen's shared imperative
17
+ * scroll ref — a custom `as` is responsible for its own ref if it needs
18
+ * one, since not every list exposes a Reanimated-compatible ref (this is
19
+ * why `Screen.FlashList` doesn't bind it either).
20
+ */
21
+ as?: As;
22
+ data?: readonly T[] | null;
23
+ renderItem?: (info: ScreenListRenderItemInfo<T>) => ReactElement | null;
24
+ keyExtractor?: (item: T, index: number) => string;
25
+ ListHeaderComponent?: ListHeaderComponent;
26
+ ListFooterComponent?: ListHeaderComponent;
27
+ ListEmptyComponent?: ListHeaderComponent;
28
+ style?: StyleProp<ViewStyle>;
29
+ contentContainerStyle?: StyleProp<ViewStyle>;
30
+ onScroll?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
31
+ /**
32
+ * Extra bottom padding on the list content — clearance for a tab bar or
33
+ * home indicator. Defaults to the `layout.screen.margin.y` token when
34
+ * margins are enabled, otherwise `0`.
35
+ */
36
+ bottomInset?: number;
37
+ };
38
+ /**
39
+ * Polymorphic list container — renders whichever list `as` names (defaults
40
+ * to `FlatList`), applying the same margin/header/safe-area/scroll-handler
41
+ * chrome regardless of which one it is. A screen can swap list
42
+ * implementations by changing `as`, without relearning the surrounding API.
43
+ *
44
+ * @example
45
+ * ```tsx
46
+ * <Screen.List data={items} renderItem={({ item }) => <Row item={item} />} />
47
+ * ```
48
+ *
49
+ * @example Any other list component
50
+ * ```tsx
51
+ * import { FlashList } from '@shopify/flash-list';
52
+ *
53
+ * <Screen.List
54
+ * as={FlashList}
55
+ * data={items}
56
+ * renderItem={({ item }) => <Row item={item} />}
57
+ * />
58
+ * ```
59
+ */
60
+ export declare function ScreenList<T = unknown, As extends ElementType = typeof FlatList>({ as, data, renderItem, style, contentContainerStyle, ListHeaderComponent, ListFooterComponent, ListEmptyComponent, horizontal, loading, LoadingComponent, EmptyComponent, margins, bottomInset, onScroll, ...rest }: ScreenListProps<T, As>): import("react").JSX.Element;
61
+ export declare namespace ScreenList {
62
+ var displayName: string;
63
+ }
64
+ //# sourceMappingURL=ScreenList.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ScreenList.d.ts","sourceRoot":"","sources":["../../../../../src/components/screen/ScreenList.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,wBAAwB,EAE7B,KAAK,WAAW,EAChB,KAAK,YAAY,EAElB,MAAM,OAAO,CAAC;AACf,OAAO,EACL,QAAQ,EACR,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,SAAS,EAEd,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AActB,OAAO,KAAK,EAAiB,qBAAqB,EAAE,MAAM,YAAS,CAAC;AACpE,OAAO,EAGL,KAAK,mBAAmB,EAEzB,MAAM,YAAS,CAAC;AAEjB,MAAM,WAAW,wBAAwB,CAAC,CAAC;IACzC,IAAI,EAAE,CAAC,CAAC;IACR,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,eAAe,CACzB,CAAC,GAAG,OAAO,EACX,EAAE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WAAW,EACX,QAAQ,EACR,GAAG,IAAI,EACR,EAAE,eAAe,CAAC,CAAC,EAAE,EAAE,CAAC,+BAkGxB;yBAtHe,UAAU"}
@@ -6,6 +6,8 @@ export type { ScreenFlashListProps } from './ScreenFlashList.js';
6
6
  export { ScreenFlashList } from './ScreenFlashList.js';
7
7
  export type { ScreenFlatListProps } from './ScreenFlatList.js';
8
8
  export { ScreenFlatList } from './ScreenFlatList.js';
9
+ export type { ScreenListProps } from './ScreenList.js';
10
+ export { ScreenList } from './ScreenList.js';
9
11
  export type { ScreenScrollViewProps } from './ScreenScrollView.js';
10
12
  export { ScreenScrollView } from './ScreenScrollView.js';
11
13
  export type { ScreenMargins, ScreenScrollableProps } from './types.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/screen/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,aAAU,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAU,CAAC;AAClC,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAiB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAiB,CAAC;AAC5C,YAAY,EAAE,oBAAoB,EAAE,MAAM,sBAAmB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAmB,CAAC;AACpD,YAAY,EAAE,mBAAmB,EAAE,MAAM,qBAAkB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAkB,CAAC;AAClD,YAAY,EAAE,qBAAqB,EAAE,MAAM,uBAAoB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAoB,CAAC;AACtD,YAAY,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,YAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/screen/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,aAAU,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAU,CAAC;AAClC,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAiB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAiB,CAAC;AAC5C,YAAY,EAAE,oBAAoB,EAAE,MAAM,sBAAmB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAmB,CAAC;AACpD,YAAY,EAAE,mBAAmB,EAAE,MAAM,qBAAkB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAkB,CAAC;AAClD,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAc,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAc,CAAC;AAC1C,YAAY,EAAE,qBAAqB,EAAE,MAAM,uBAAoB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAoB,CAAC;AACtD,YAAY,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,YAAS,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-terra-ui",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Themeable React Native UI components built on react-native-unistyles",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -19,6 +19,7 @@ import { PortalProvider } from '../portal';
19
19
  import { ScreenScrollProvider } from './ScreenContext';
20
20
  import { ScreenFlashList } from './ScreenFlashList';
21
21
  import { ScreenFlatList } from './ScreenFlatList';
22
+ import { ScreenList } from './ScreenList';
22
23
  import { ScreenScrollView } from './ScreenScrollView';
23
24
  import type { ScreenMargins } from './types';
24
25
 
@@ -96,12 +97,14 @@ type ScreenComponent = ReturnType<
96
97
  ScrollView: typeof ScreenScrollView;
97
98
  FlatList: typeof ScreenFlatList;
98
99
  FlashList: typeof ScreenFlashList;
100
+ List: typeof ScreenList;
99
101
  };
100
102
 
101
103
  /**
102
104
  * Themed page container: solid themed background, safe-area handling, and a
103
105
  * shared scroll context for headers. Pair with `Screen.ScrollView` /
104
- * `Screen.FlatList` and a `Header.LargeTitle` / `Header.Title`.
106
+ * `Screen.List` (or `Screen.FlatList` / `Screen.FlashList` directly) and a
107
+ * `Header.LargeTitle` / `Header.Title`.
105
108
  *
106
109
  * @example
107
110
  * ```tsx
@@ -139,6 +142,7 @@ ScreenBase.Header = ScreenHeader;
139
142
  ScreenBase.ScrollView = ScreenScrollView;
140
143
  ScreenBase.FlatList = ScreenFlatList;
141
144
  ScreenBase.FlashList = ScreenFlashList;
145
+ ScreenBase.List = ScreenList;
142
146
 
143
147
  export const Screen = ScreenBase;
144
148
 
@@ -137,10 +137,17 @@ export function ScreenFlashList<T>({
137
137
  );
138
138
 
139
139
  const headerComponent = (
140
- <View style={styles.headerWrapper(resolvedMargins)}>
141
- <PortalHost name={SCREEN_HEADER_PORTAL_HOST} />
140
+ <>
141
+ {/* `headerWrapper`'s negative margin cancels the list's inherited
142
+ content padding for the portaled header (`LargeTitlePortalContent`
143
+ etc. manage their own horizontal padding) — a caller's own
144
+ `ListHeaderComponent` has no such self-padding, so it stays outside
145
+ this wrapper and gets the list's normal item padding instead. */}
146
+ <View style={styles.headerWrapper(resolvedMargins)}>
147
+ <PortalHost name={SCREEN_HEADER_PORTAL_HOST} />
148
+ </View>
142
149
  {renderListHeader(ListHeaderComponent)}
143
- </View>
150
+ </>
144
151
  );
145
152
 
146
153
  return (
@@ -165,39 +172,45 @@ export function ScreenFlashList<T>({
165
172
  );
166
173
  }
167
174
 
168
- const styles = StyleSheet.create((theme, runtime) => {
169
- const { x: marginX, y: marginY } = resolveScreenMargin(
170
- theme,
171
- runtime.breakpoint
172
- );
173
-
174
- return {
175
- content: (
176
- margins: ScreenMargins,
177
- hasHeader: boolean,
178
- bottomInset: number | undefined
179
- ) => {
180
- return {
181
- flexGrow: 1,
182
- // The header is absolutely positioned, so the list reserves its full
183
- // height — bar plus top safe area. This assumes the scroll view does not
184
- // also get UIKit's automatic inset adjustment: on a native tab screen
185
- // that means `disableAutomaticContentInsets` on the tab, or the two
186
- // insets are counted twice.
187
- paddingTop:
188
- (hasHeader ? theme.layout.header.height + runtime.insets.top : 0) +
189
- (hasYMargin(margins) ? marginY : 0),
190
- paddingHorizontal: hasXMargin(margins) ? marginX : 0,
191
- // The safe area is `BottomSafeArea`'s job; counting it here as well
192
- // would leave a gap the height of the gesture bar.
193
- paddingBottom: bottomInset ?? (hasYMargin(margins) ? marginY : 0),
194
- };
195
- },
196
- safeArea: {
197
- height: runtime.insets.top,
198
- },
199
- headerWrapper: (margins: ScreenMargins) => ({
175
+ // `resolveScreenMargin` is called *inside* each dynamic function below, not
176
+ // hoisted to the factory's top level the Babel plugin only attributes a
177
+ // runtime dependency (here, breakpoint) to a style key when the `rt`/
178
+ // `runtime` read it derives from sits inside that key's own value. Hoisting
179
+ // it would silently drop the dependency, so the margin would freeze at
180
+ // whatever breakpoint was active on mount and never update on rotation.
181
+ const styles = StyleSheet.create((theme, runtime) => ({
182
+ content: (
183
+ margins: ScreenMargins,
184
+ hasHeader: boolean,
185
+ bottomInset: number | undefined
186
+ ) => {
187
+ const { x: marginX, y: marginY } = resolveScreenMargin(
188
+ theme,
189
+ runtime.breakpoint
190
+ );
191
+ return {
192
+ flexGrow: 1,
193
+ // The header is absolutely positioned, so the list reserves its full
194
+ // height — bar plus top safe area. This assumes the scroll view does not
195
+ // also get UIKit's automatic inset adjustment: on a native tab screen
196
+ // that means `disableAutomaticContentInsets` on the tab, or the two
197
+ // insets are counted twice.
198
+ paddingTop:
199
+ (hasHeader ? theme.layout.header.height + runtime.insets.top : 0) +
200
+ (hasYMargin(margins) ? marginY : 0),
201
+ paddingHorizontal: hasXMargin(margins) ? marginX : 0,
202
+ // The safe area is `BottomSafeArea`'s job; counting it here as well
203
+ // would leave a gap the height of the gesture bar.
204
+ paddingBottom: bottomInset ?? (hasYMargin(margins) ? marginY : 0),
205
+ };
206
+ },
207
+ safeArea: {
208
+ height: runtime.insets.top,
209
+ },
210
+ headerWrapper: (margins: ScreenMargins) => {
211
+ const { x: marginX } = resolveScreenMargin(theme, runtime.breakpoint);
212
+ return {
200
213
  marginHorizontal: hasXMargin(margins) ? -marginX : 0,
201
- }),
202
- };
203
- });
214
+ };
215
+ },
216
+ }));
@@ -117,11 +117,17 @@ export function ScreenFlatList<T>({
117
117
  );
118
118
 
119
119
  const headerComponent = (
120
- <View style={styles.headerWrapper(resolvedMargins)}>
121
- {hasHeader ? <View style={styles.header} /> : null}
122
- <PortalHost name={SCREEN_HEADER_PORTAL_HOST} />
120
+ <>
121
+ {/* `headerWrapper`'s negative margin cancels the list's inherited
122
+ content padding for the portaled header (`LargeTitlePortalContent`
123
+ etc. manage their own horizontal padding) — a caller's own
124
+ `ListHeaderComponent` has no such self-padding, so it stays outside
125
+ this wrapper and gets the list's normal item padding instead. */}
126
+ <View style={styles.headerWrapper(resolvedMargins)}>
127
+ <PortalHost name={SCREEN_HEADER_PORTAL_HOST} />
128
+ </View>
123
129
  {renderListHeader(ListHeaderComponent)}
124
- </View>
130
+ </>
125
131
  );
126
132
 
127
133
  return (
@@ -147,21 +153,26 @@ export function ScreenFlatList<T>({
147
153
  );
148
154
  }
149
155
 
150
- const styles = StyleSheet.create((theme, runtime) => {
151
- const { x: marginX, y: marginY } = resolveScreenMargin(
152
- theme,
153
- runtime.breakpoint
154
- );
155
-
156
- return {
157
- scrollContent: {
158
- flexGrow: 1,
159
- },
160
- content: (
161
- margins: ScreenMargins,
162
- hasHeader: boolean,
163
- bottomInset: number | undefined
164
- ) => ({
156
+ // `resolveScreenMargin` is called *inside* each dynamic function below, not
157
+ // hoisted to the factory's top level the Babel plugin only attributes a
158
+ // runtime dependency (here, breakpoint) to a style key when the `rt`/
159
+ // `runtime` read it derives from sits inside that key's own value. Hoisting
160
+ // it would silently drop the dependency, so the margin would freeze at
161
+ // whatever breakpoint was active on mount and never update on rotation.
162
+ const styles = StyleSheet.create((theme, runtime) => ({
163
+ scrollContent: {
164
+ flexGrow: 1,
165
+ },
166
+ content: (
167
+ margins: ScreenMargins,
168
+ hasHeader: boolean,
169
+ bottomInset: number | undefined
170
+ ) => {
171
+ const { x: marginX, y: marginY } = resolveScreenMargin(
172
+ theme,
173
+ runtime.breakpoint
174
+ );
175
+ return {
165
176
  flexGrow: 1,
166
177
  // The header is absolutely positioned, so the list reserves its full
167
178
  // height — bar plus top safe area. This assumes the scroll view does not
@@ -175,15 +186,15 @@ const styles = StyleSheet.create((theme, runtime) => {
175
186
  // The safe area is `BottomSafeArea`'s job; counting it here as well
176
187
  // would leave a gap the height of the gesture bar.
177
188
  paddingBottom: bottomInset ?? (hasYMargin(margins) ? marginY : 0),
178
- }),
179
- safeArea: {
180
- height: runtime.insets.top,
181
- },
182
- headerWrapper: (margins: ScreenMargins) => ({
189
+ };
190
+ },
191
+ safeArea: {
192
+ height: runtime.insets.top,
193
+ },
194
+ headerWrapper: (margins: ScreenMargins) => {
195
+ const { x: marginX } = resolveScreenMargin(theme, runtime.breakpoint);
196
+ return {
183
197
  marginHorizontal: hasXMargin(margins) ? -marginX : 0,
184
- }),
185
- header: {
186
- height: theme.layout.header.height,
187
- },
188
- };
189
- });
198
+ };
199
+ },
200
+ }));
@@ -0,0 +1,269 @@
1
+ import {
2
+ type ComponentPropsWithoutRef,
3
+ type ComponentType,
4
+ type ElementType,
5
+ type ReactElement,
6
+ useMemo,
7
+ } from 'react';
8
+ import {
9
+ FlatList,
10
+ type NativeScrollEvent,
11
+ type NativeSyntheticEvent,
12
+ type StyleProp,
13
+ View,
14
+ type ViewStyle,
15
+ } from 'react-native';
16
+
17
+ import Animated, {
18
+ type AnimatedRef,
19
+ useAnimatedScrollHandler,
20
+ useComposedEventHandler,
21
+ } from 'react-native-reanimated';
22
+ import { StyleSheet } from 'react-native-unistyles';
23
+
24
+ import { resolveScreenMargin } from '#theme/screen-margin';
25
+ import { PortalHost } from '../portal';
26
+ import { BottomSafeArea } from './parts/BottomSafeArea';
27
+ import { renderScreenPlaceholder } from './parts/ScreenPlaceholder';
28
+ import { SCREEN_HEADER_PORTAL_HOST, useScreen } from './ScreenContext';
29
+ import type { ScreenMargins, ScreenScrollableProps } from './types';
30
+ import {
31
+ hasXMargin,
32
+ hasYMargin,
33
+ type ListHeaderComponent,
34
+ renderListHeader,
35
+ } from './utils';
36
+
37
+ export interface ScreenListRenderItemInfo<T> {
38
+ item: T;
39
+ index: number;
40
+ }
41
+
42
+ export type ScreenListProps<
43
+ T = unknown,
44
+ As extends ElementType = typeof FlatList,
45
+ > = ScreenScrollableProps &
46
+ Omit<
47
+ ComponentPropsWithoutRef<As>,
48
+ | 'data'
49
+ | 'renderItem'
50
+ | 'keyExtractor'
51
+ | 'style'
52
+ | 'contentContainerStyle'
53
+ | 'onScroll'
54
+ | 'ListHeaderComponent'
55
+ | 'ListFooterComponent'
56
+ | 'ListEmptyComponent'
57
+ | keyof ScreenScrollableProps
58
+ > & {
59
+ /**
60
+ * Which list component to render as. Defaults to React Native's
61
+ * `FlatList` — pass any list with a FlatList-shaped prop surface
62
+ * (`data`, `renderItem`, `ListHeaderComponent`, …), e.g. `FlashList`
63
+ * from `@shopify/flash-list`, or a custom virtualized list.
64
+ *
65
+ * Only the default `FlatList` binds the screen's shared imperative
66
+ * scroll ref — a custom `as` is responsible for its own ref if it needs
67
+ * one, since not every list exposes a Reanimated-compatible ref (this is
68
+ * why `Screen.FlashList` doesn't bind it either).
69
+ */
70
+ as?: As;
71
+ data?: readonly T[] | null;
72
+ renderItem?: (info: ScreenListRenderItemInfo<T>) => ReactElement | null;
73
+ keyExtractor?: (item: T, index: number) => string;
74
+ ListHeaderComponent?: ListHeaderComponent;
75
+ ListFooterComponent?: ListHeaderComponent;
76
+ ListEmptyComponent?: ListHeaderComponent;
77
+ style?: StyleProp<ViewStyle>;
78
+ contentContainerStyle?: StyleProp<ViewStyle>;
79
+ onScroll?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
80
+ /**
81
+ * Extra bottom padding on the list content — clearance for a tab bar or
82
+ * home indicator. Defaults to the `layout.screen.margin.y` token when
83
+ * margins are enabled, otherwise `0`.
84
+ */
85
+ bottomInset?: number;
86
+ };
87
+
88
+ /**
89
+ * Polymorphic list container — renders whichever list `as` names (defaults
90
+ * to `FlatList`), applying the same margin/header/safe-area/scroll-handler
91
+ * chrome regardless of which one it is. A screen can swap list
92
+ * implementations by changing `as`, without relearning the surrounding API.
93
+ *
94
+ * @example
95
+ * ```tsx
96
+ * <Screen.List data={items} renderItem={({ item }) => <Row item={item} />} />
97
+ * ```
98
+ *
99
+ * @example Any other list component
100
+ * ```tsx
101
+ * import { FlashList } from '@shopify/flash-list';
102
+ *
103
+ * <Screen.List
104
+ * as={FlashList}
105
+ * data={items}
106
+ * renderItem={({ item }) => <Row item={item} />}
107
+ * />
108
+ * ```
109
+ */
110
+ export function ScreenList<
111
+ T = unknown,
112
+ As extends ElementType = typeof FlatList,
113
+ >({
114
+ as,
115
+ data,
116
+ renderItem,
117
+ style,
118
+ contentContainerStyle,
119
+ ListHeaderComponent,
120
+ ListFooterComponent,
121
+ ListEmptyComponent,
122
+ horizontal = false,
123
+ loading = false,
124
+ LoadingComponent,
125
+ EmptyComponent,
126
+ margins,
127
+ bottomInset,
128
+ onScroll,
129
+ ...rest
130
+ }: ScreenListProps<T, As>) {
131
+ const isDefaultFlatList = as === undefined;
132
+ const Component = (as ?? FlatList) as ComponentType<Record<string, unknown>>;
133
+
134
+ // `Animated.createAnimatedComponent` should only run once per component,
135
+ // not on every render — `as` is arbitrary here (not a fixed module-scope
136
+ // reference like `Screen.FlatList`/`Screen.FlashList` use), so it's
137
+ // memoized on the resolved component instead of hoisted to module scope.
138
+ const AnimatedComponent = useMemo(
139
+ () => Animated.createAnimatedComponent(Component),
140
+ [Component]
141
+ );
142
+
143
+ const {
144
+ background,
145
+ scrollRef,
146
+ scrollHandler,
147
+ headerSnapOffsets,
148
+ margins: screenMargins,
149
+ hasHeader,
150
+ } = useScreen();
151
+
152
+ const resolvedMargins = margins ?? screenMargins;
153
+ // The placeholder rides in on `ListEmptyComponent` rather than replacing the
154
+ // list, so the header portal, scroll binding and snap offsets all stay put.
155
+ // While loading the list is fed an empty `data` so that slot is the one that
156
+ // renders.
157
+ const placeholder = renderScreenPlaceholder({
158
+ loading,
159
+ LoadingComponent,
160
+ EmptyComponent,
161
+ isEmpty: !data || data.length === 0,
162
+ });
163
+
164
+ const jsScrollHandler = useAnimatedScrollHandler(
165
+ (event) => {
166
+ if (onScroll)
167
+ onScroll(event as unknown as NativeSyntheticEvent<NativeScrollEvent>);
168
+ },
169
+ [onScroll]
170
+ );
171
+
172
+ const composedHandler = useComposedEventHandler([
173
+ scrollHandler,
174
+ jsScrollHandler,
175
+ ]);
176
+
177
+ // A caller naming its own `bottomInset` has taken the bottom over entirely,
178
+ // and a horizontal list has no bottom edge to clear.
179
+ const needsBottomSafeArea = bottomInset === undefined && !horizontal;
180
+
181
+ const footerComponent = (
182
+ <>
183
+ {renderListHeader(ListFooterComponent)}
184
+ {needsBottomSafeArea ? <BottomSafeArea /> : null}
185
+ </>
186
+ );
187
+
188
+ const headerComponent = (
189
+ <>
190
+ {/* `headerWrapper`'s negative margin cancels the list's inherited
191
+ content padding for the portaled header (`LargeTitlePortalContent`
192
+ etc. manage their own horizontal padding) — a caller's own
193
+ `ListHeaderComponent` has no such self-padding, so it stays outside
194
+ this wrapper and gets the list's normal item padding instead. */}
195
+ <View style={styles.headerWrapper(resolvedMargins)}>
196
+ <PortalHost name={SCREEN_HEADER_PORTAL_HOST} />
197
+ </View>
198
+ {renderListHeader(ListHeaderComponent)}
199
+ </>
200
+ );
201
+
202
+ return (
203
+ <AnimatedComponent
204
+ ref={
205
+ isDefaultFlatList
206
+ ? (scrollRef as unknown as AnimatedRef<never>)
207
+ : undefined
208
+ }
209
+ data={loading ? [] : data}
210
+ renderItem={renderItem}
211
+ style={[{ backgroundColor: background }, style]}
212
+ horizontal={horizontal}
213
+ contentInsetAdjustmentBehavior={hasHeader ? 'never' : undefined}
214
+ contentContainerStyle={[
215
+ styles.content(resolvedMargins, hasHeader, bottomInset),
216
+ contentContainerStyle,
217
+ ]}
218
+ ListHeaderComponent={headerComponent}
219
+ ListFooterComponent={footerComponent}
220
+ ListEmptyComponent={placeholder ?? ListEmptyComponent}
221
+ showsVerticalScrollIndicator={false}
222
+ scrollEventThrottle={16}
223
+ snapToOffsets={headerSnapOffsets}
224
+ {...rest}
225
+ onScroll={composedHandler}
226
+ />
227
+ );
228
+ }
229
+ ScreenList.displayName = 'Screen.List';
230
+
231
+ // `resolveScreenMargin` is called *inside* each dynamic function below, not
232
+ // hoisted to the factory's top level — the Babel plugin only attributes a
233
+ // runtime dependency (here, breakpoint) to a style key when the `rt`/
234
+ // `runtime` read it derives from sits inside that key's own value. Hoisting
235
+ // it would silently drop the dependency, so the margin would freeze at
236
+ // whatever breakpoint was active on mount and never update on rotation.
237
+ const styles = StyleSheet.create((theme, runtime) => ({
238
+ content: (
239
+ margins: ScreenMargins,
240
+ hasHeader: boolean,
241
+ bottomInset: number | undefined
242
+ ) => {
243
+ const { x: marginX, y: marginY } = resolveScreenMargin(
244
+ theme,
245
+ runtime.breakpoint
246
+ );
247
+ return {
248
+ flexGrow: 1,
249
+ // The header is absolutely positioned, so the list reserves its full
250
+ // height — bar plus top safe area. This assumes the scroll view does not
251
+ // also get UIKit's automatic inset adjustment: on a native tab screen
252
+ // that means `disableAutomaticContentInsets` on the tab, or the two
253
+ // insets are counted twice.
254
+ paddingTop:
255
+ (hasHeader ? theme.layout.header.height + runtime.insets.top : 0) +
256
+ (hasYMargin(margins) ? marginY : 0),
257
+ paddingHorizontal: hasXMargin(margins) ? marginX : 0,
258
+ // The safe area is `BottomSafeArea`'s job; counting it here as well
259
+ // would leave a gap the height of the gesture bar.
260
+ paddingBottom: bottomInset ?? (hasYMargin(margins) ? marginY : 0),
261
+ };
262
+ },
263
+ headerWrapper: (margins: ScreenMargins) => {
264
+ const { x: marginX } = resolveScreenMargin(theme, runtime.breakpoint);
265
+ return {
266
+ marginHorizontal: hasXMargin(margins) ? -marginX : 0,
267
+ };
268
+ },
269
+ }));
@@ -172,11 +172,17 @@ export function ScreenScrollView({
172
172
  );
173
173
  }
174
174
 
175
- const styles = StyleSheet.create((theme, rt) => {
176
- const { x: marginX, y: marginY } = resolveScreenMargin(theme, rt.breakpoint);
177
-
178
- return {
179
- scrollContent: (hasHeader: boolean, margins: ScreenMargins) => ({
175
+ const styles = StyleSheet.create((theme, rt) => ({
176
+ // `resolveScreenMargin` is called *inside* each dynamic function, not
177
+ // hoisted above `return` — the Babel plugin only attributes a runtime
178
+ // dependency (here, breakpoint) to a style key when the `rt` read it
179
+ // derives from sits inside that key's own value. Hoisting it to the
180
+ // factory's top level silently drops the dependency, so the margin would
181
+ // freeze at whatever breakpoint was active on mount and never update on
182
+ // rotation.
183
+ scrollContent: (hasHeader: boolean, margins: ScreenMargins) => {
184
+ const { y: marginY } = resolveScreenMargin(theme, rt.breakpoint);
185
+ return {
180
186
  flexGrow: 1,
181
187
  // The header inset and the safe area are structural — they apply
182
188
  // whether or not margins are on; the y margin stacks on top of them.
@@ -186,12 +192,15 @@ const styles = StyleSheet.create((theme, rt) => {
186
192
  // The safe area is `BottomSafeArea`'s job; counting it here as well
187
193
  // would leave a gap the height of the gesture bar.
188
194
  paddingBottom: hasYMargin(margins) ? marginY : 0,
189
- }),
195
+ };
196
+ },
190
197
 
191
- content: (horizontal: boolean, margins: ScreenMargins) => ({
198
+ content: (horizontal: boolean, margins: ScreenMargins) => {
199
+ const { x: marginX } = resolveScreenMargin(theme, rt.breakpoint);
200
+ return {
192
201
  flexGrow: 1,
193
202
  paddingHorizontal: hasXMargin(margins) ? marginX : 0,
194
203
  flexDirection: horizontal ? 'row' : 'column',
195
- }),
196
- };
197
- });
204
+ };
205
+ },
206
+ }));