@terreno/ui 57.1.0 → 57.3.0

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 (201) hide show
  1. package/.ai/guidelines/core.md +1 -1
  2. package/README.md +17 -8
  3. package/dist/ActionSheet.d.ts +3 -3
  4. package/dist/ActionSheet.js +2 -2
  5. package/dist/ActionSheet.js.map +1 -1
  6. package/dist/Box.d.ts +1 -1
  7. package/dist/Box.js +219 -177
  8. package/dist/Box.js.map +1 -1
  9. package/dist/Button.js +101 -34
  10. package/dist/Button.js.map +1 -1
  11. package/dist/Common.d.ts +119 -9
  12. package/dist/Common.js.map +1 -1
  13. package/dist/ConsentFormScreen.js +46 -12
  14. package/dist/ConsentFormScreen.js.map +1 -1
  15. package/dist/ConsentNavigator.d.ts +5 -1
  16. package/dist/ConsentNavigator.js.map +1 -1
  17. package/dist/DataTable.d.ts +2 -2
  18. package/dist/DataTable.js +203 -44
  19. package/dist/DataTable.js.map +1 -1
  20. package/dist/DataTableHeaderInfoMarkdown.d.ts +6 -0
  21. package/dist/DataTableHeaderInfoMarkdown.js +7 -0
  22. package/dist/DataTableHeaderInfoMarkdown.js.map +1 -0
  23. package/dist/EmojiSelector.d.ts +2 -46
  24. package/dist/EmojiSelector.js +46 -56
  25. package/dist/EmojiSelector.js.map +1 -1
  26. package/dist/GPTChat.js +1 -1
  27. package/dist/GPTChat.js.map +1 -1
  28. package/dist/Heading.d.ts +5 -2
  29. package/dist/Heading.js +6 -8
  30. package/dist/Heading.js.map +1 -1
  31. package/dist/Hyperlink.js.map +1 -1
  32. package/dist/Icon.d.ts +1 -2
  33. package/dist/Icon.js +4 -1
  34. package/dist/Icon.js.map +1 -1
  35. package/dist/MarkdownView.d.ts +6 -3
  36. package/dist/MarkdownView.js +45 -43
  37. package/dist/MarkdownView.js.map +1 -1
  38. package/dist/MediaQuery.d.ts +5 -3
  39. package/dist/MediaQuery.js +9 -40
  40. package/dist/MediaQuery.js.map +1 -1
  41. package/dist/OpenAPIContext.js +7 -6
  42. package/dist/OpenAPIContext.js.map +1 -1
  43. package/dist/Page.js +7 -1
  44. package/dist/Page.js.map +1 -1
  45. package/dist/PickerSelect.js +8 -1
  46. package/dist/PickerSelect.js.map +1 -1
  47. package/dist/Popover.d.ts +12 -0
  48. package/dist/Popover.js +37 -0
  49. package/dist/Popover.js.map +1 -0
  50. package/dist/PortalHost.js +10 -1
  51. package/dist/PortalHost.js.map +1 -1
  52. package/dist/ResponsiveBreakpoint.d.ts +65 -0
  53. package/dist/ResponsiveBreakpoint.js +111 -0
  54. package/dist/ResponsiveBreakpoint.js.map +1 -0
  55. package/dist/SplitPage.d.ts +2 -2
  56. package/dist/SplitPage.js +7 -12
  57. package/dist/SplitPage.js.map +1 -1
  58. package/dist/SplitPage.native.d.ts +2 -2
  59. package/dist/SplitPage.native.js +1 -6
  60. package/dist/SplitPage.native.js.map +1 -1
  61. package/dist/TapToEdit.js +12 -10
  62. package/dist/TapToEdit.js.map +1 -1
  63. package/dist/TerrenoFontProvider.d.ts +7 -0
  64. package/dist/TerrenoFontProvider.js +27 -0
  65. package/dist/TerrenoFontProvider.js.map +1 -0
  66. package/dist/TerrenoProvider.js +4 -2
  67. package/dist/TerrenoProvider.js.map +1 -1
  68. package/dist/Text.d.ts +5 -2
  69. package/dist/Text.js +6 -11
  70. package/dist/Text.js.map +1 -1
  71. package/dist/TextFieldNumberActionSheet.js +9 -2
  72. package/dist/TextFieldNumberActionSheet.js.map +1 -1
  73. package/dist/Theme.js +10 -8
  74. package/dist/Theme.js.map +1 -1
  75. package/dist/ToastNotifications.d.ts +4 -2
  76. package/dist/ToastNotifications.js.map +1 -1
  77. package/dist/Tooltip.d.ts +4 -3
  78. package/dist/Tooltip.js +14 -3
  79. package/dist/Tooltip.js.map +1 -1
  80. package/dist/Unifier.d.ts +26 -1
  81. package/dist/Unifier.js.map +1 -1
  82. package/dist/WebAddressAutocomplete.js +6 -1
  83. package/dist/WebAddressAutocomplete.js.map +1 -1
  84. package/dist/emojiCategories.d.ts +46 -0
  85. package/dist/emojiCategories.js +47 -0
  86. package/dist/emojiCategories.js.map +1 -0
  87. package/dist/index.d.ts +13 -13
  88. package/dist/index.js +2 -13
  89. package/dist/index.js.map +1 -1
  90. package/dist/lazyBoundaries/createLazyComponentExport.d.ts +6 -0
  91. package/dist/lazyBoundaries/createLazyComponentExport.js +35 -0
  92. package/dist/lazyBoundaries/createLazyComponentExport.js.map +1 -0
  93. package/dist/lazyBoundaries/heavyOptionalExports.d.ts +41 -0
  94. package/dist/lazyBoundaries/heavyOptionalExports.js +43 -0
  95. package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -0
  96. package/dist/login/LoginScreen.d.ts +1 -0
  97. package/dist/login/LoginScreen.js +4 -2
  98. package/dist/login/LoginScreen.js.map +1 -1
  99. package/dist/login/loginTypes.d.ts +2 -0
  100. package/package.json +41 -2
  101. package/src/AIRequestExplorer.test.tsx +141 -0
  102. package/src/ActionSheet.tsx +9 -7
  103. package/src/AttachmentPreview.test.tsx +80 -0
  104. package/src/Box.test.tsx +97 -10
  105. package/src/Box.tsx +263 -200
  106. package/src/Button.test.tsx +207 -0
  107. package/src/Button.tsx +146 -48
  108. package/src/Common.ts +124 -25
  109. package/src/ConsentFormScreen.markdownGate.test.tsx +129 -0
  110. package/src/ConsentFormScreen.test.tsx +145 -8
  111. package/src/ConsentFormScreen.tsx +74 -25
  112. package/src/ConsentNavigator.tsx +13 -5
  113. package/src/DataTable.tsx +418 -147
  114. package/src/DataTableHeaderInfoMarkdown.test.tsx +21 -0
  115. package/src/DataTableHeaderInfoMarkdown.tsx +17 -0
  116. package/src/DataTableVirtualizationRegression.test.tsx +266 -0
  117. package/src/DateTimeField.test.tsx +54 -0
  118. package/src/EmojiSelector.test.tsx +33 -42
  119. package/src/EmojiSelector.tsx +60 -57
  120. package/src/FilePickerButton.test.tsx +167 -0
  121. package/src/FilterAccordion.test.tsx +37 -0
  122. package/src/FilterBoolean.test.tsx +96 -0
  123. package/src/FilterSelectMenu.test.tsx +23 -0
  124. package/src/GPTChat.test.tsx +696 -0
  125. package/src/GPTChat.tsx +2 -2
  126. package/src/GPTMemoryModal.test.tsx +67 -0
  127. package/src/Heading.tsx +8 -14
  128. package/src/HeightActionSheet.test.tsx +6 -9
  129. package/src/Hyperlink.tsx +5 -18
  130. package/src/Icon.tsx +6 -2
  131. package/src/MarkdownEditor.test.tsx +134 -0
  132. package/src/MarkdownEditorField.test.tsx +124 -0
  133. package/src/MarkdownView.test.tsx +55 -11
  134. package/src/MarkdownView.tsx +149 -150
  135. package/src/MediaQuery.ts +30 -34
  136. package/src/OpenAPIContext.tsx +36 -29
  137. package/src/OpenAPIRenderRegression.test.tsx +200 -0
  138. package/src/P0RenderRegression.test.tsx +214 -0
  139. package/src/P1RenderRegression.test.tsx +141 -0
  140. package/src/P2ButtonRenderRegression.test.tsx +158 -0
  141. package/src/Page.test.tsx +13 -0
  142. package/src/Page.tsx +25 -5
  143. package/src/PickerSelect.test.tsx +38 -0
  144. package/src/PickerSelect.tsx +7 -0
  145. package/src/Popover.test.tsx +151 -0
  146. package/src/Popover.tsx +211 -0
  147. package/src/PortalHost.tsx +12 -6
  148. package/src/ResponsiveBreakpoint.test.tsx +184 -0
  149. package/src/ResponsiveBreakpoint.tsx +195 -0
  150. package/src/RootImportRegression.test.tsx +62 -0
  151. package/src/SplitPage.native.tsx +5 -9
  152. package/src/SplitPage.tsx +16 -19
  153. package/src/TapToEdit.test.tsx +45 -0
  154. package/src/TapToEdit.tsx +23 -18
  155. package/src/TerrenoFontProvider.test.tsx +38 -0
  156. package/src/TerrenoFontProvider.tsx +50 -0
  157. package/src/TerrenoProvider.tsx +6 -1
  158. package/src/Text.tsx +8 -21
  159. package/src/TextFieldNumberActionSheet.test.tsx +100 -0
  160. package/src/TextFieldNumberActionSheet.tsx +11 -2
  161. package/src/Theme.test.tsx +27 -0
  162. package/src/Theme.tsx +15 -10
  163. package/src/Toast.tsx +1 -1
  164. package/src/ToastNotifications.tsx +4 -4
  165. package/src/Tooltip.test.tsx +64 -0
  166. package/src/Tooltip.tsx +18 -4
  167. package/src/Unifier.ts +26 -3
  168. package/src/WebAddressAutocomplete.tsx +6 -2
  169. package/src/__snapshots__/ActionSheet.test.tsx.snap +0 -36
  170. package/src/__snapshots__/AddressField.test.tsx.snap +1 -0
  171. package/src/__snapshots__/AttachmentPreview.test.tsx.snap +225 -0
  172. package/src/__snapshots__/CustomSelectField.test.tsx.snap +7 -0
  173. package/src/__snapshots__/DataTable.test.tsx.snap +793 -250
  174. package/src/__snapshots__/DecimalRangeActionSheet.test.tsx.snap +0 -8
  175. package/src/__snapshots__/EmojiSelector.test.tsx.snap +35555 -30
  176. package/src/__snapshots__/Field.test.tsx.snap +7 -0
  177. package/src/__snapshots__/FilterSelectMenu.test.tsx.snap +1 -0
  178. package/src/__snapshots__/HeightActionSheet.test.tsx.snap +0 -8
  179. package/src/__snapshots__/HeightField.test.tsx.snap +0 -20
  180. package/src/__snapshots__/NumberPickerActionSheet.test.tsx.snap +0 -8
  181. package/src/__snapshots__/Page.test.tsx.snap +13 -1
  182. package/src/__snapshots__/PickerSelect.test.tsx.snap +7 -0
  183. package/src/__snapshots__/SelectField.test.tsx.snap +6 -0
  184. package/src/__snapshots__/TimezonePicker.test.tsx.snap +6 -0
  185. package/src/benchmarks/importGraph.test.ts +71 -0
  186. package/src/benchmarks/importGraph.ts +136 -0
  187. package/src/benchmarks/importTiming.test.ts +42 -0
  188. package/src/benchmarks/importTiming.ts +86 -0
  189. package/src/bunSetup.ts +174 -32
  190. package/src/emojiCategories.test.ts +23 -0
  191. package/src/emojiCategories.ts +46 -0
  192. package/src/index.tsx +27 -13
  193. package/src/lazyBoundaries/createLazyComponentExport.test.tsx +104 -0
  194. package/src/lazyBoundaries/createLazyComponentExport.tsx +63 -0
  195. package/src/lazyBoundaries/heavyOptionalExports.test.tsx +33 -0
  196. package/src/lazyBoundaries/heavyOptionalExports.tsx +106 -0
  197. package/src/login/LoginScreen.test.tsx +9 -2
  198. package/src/login/LoginScreen.tsx +6 -2
  199. package/src/login/loginTypes.ts +2 -0
  200. package/src/table/TableDate.test.tsx +35 -1
  201. package/src/table/__snapshots__/TableBadge.test.tsx.snap +1 -0
package/src/Common.ts CHANGED
@@ -637,15 +637,14 @@ export interface BoxPropsBase extends WithTestID {
637
637
  lgColumn?: UnsignedUpTo12;
638
638
  dangerouslySetInlineStyle?: {
639
639
  __style: {
640
- // noExplicitAny: escape hatch for arbitrary inline style values that users may need to set
641
- // biome-ignore lint/suspicious/noExplicitAny: escape hatch for arbitrary inline style values that users may need to set
642
- [key: string]: any;
640
+ [key: string]: unknown;
643
641
  };
644
642
  };
645
643
  direction?: "row" | "column";
646
644
  smDirection?: "row" | "column";
647
645
  mdDirection?: "row" | "column";
648
646
  lgDirection?: "row" | "column";
647
+ xlDirection?: "row" | "column";
649
648
  display?: "none" | "flex" | "block" | "inlineBlock" | "visuallyHidden";
650
649
  smDisplay?: "none" | "flex" | "block" | "inlineBlock" | "visuallyHidden";
651
650
  mdDisplay?: "none" | "flex" | "block" | "inlineBlock" | "visuallyHidden";
@@ -1121,7 +1120,11 @@ export interface LayoutChangeEvent {
1121
1120
  };
1122
1121
  }
1123
1122
 
1124
- export interface SplitPageProps {
1123
+ export interface SplitPageListItem {
1124
+ id: string;
1125
+ }
1126
+
1127
+ export interface SplitPageProps<TItem extends SplitPageListItem = SplitPageListItem> {
1125
1128
  /**
1126
1129
  * can accept either one React Child or any array of ReactChild. If this is not provided,
1127
1130
  * renderContent must return one or many ReactChild.
@@ -1141,21 +1144,15 @@ export interface SplitPageProps {
1141
1144
  loading?: boolean;
1142
1145
  color?: SurfaceColor;
1143
1146
  keyboardOffset?: number;
1144
- // noExplicitAny: ListRenderItemInfo generic type depends on the consumer's data shape
1145
- // biome-ignore lint/suspicious/noExplicitAny: ListRenderItemInfo generic type depends on the consumer's data shape
1146
- renderListViewItem: (itemInfo: ListRenderItemInfo<any>) => ReactElement | null;
1147
+ renderListViewItem: (itemInfo: ListRenderItemInfo<TItem>) => ReactElement | null;
1147
1148
  renderListViewHeader?: () => ReactElement | null;
1148
1149
  renderContent?: (index?: number) => ReactElement | ReactElement[] | null;
1149
- // noExplicitAny: list data type varies by consumer's data model
1150
- // biome-ignore lint/suspicious/noExplicitAny: list data type varies by consumer's data model
1151
- listViewData: any[];
1150
+ listViewData: TItem[];
1152
1151
  listViewExtraData?: unknown;
1153
1152
  listViewWidth?: number;
1154
1153
  listViewMaxWidth?: number;
1155
1154
  renderChild?: () => ReactChild;
1156
- // noExplicitAny: callback value type varies by consumer's data model
1157
- // biome-ignore lint/suspicious/noExplicitAny: callback value type varies by consumer's data model
1158
- onSelectionChange?: (value?: any) => void | Promise<void>;
1155
+ onSelectionChange?: (value?: ListRenderItemInfo<TItem>) => void | Promise<void>;
1159
1156
  }
1160
1157
 
1161
1158
  export type PermissionKind =
@@ -1708,6 +1705,91 @@ export interface ThumbsUpDownFeedbackProps extends WithTestID {
1708
1705
  value?: ThumbsUpDownFeedbackValue;
1709
1706
  }
1710
1707
 
1708
+ export type PopoverStatus = "loading" | "loaded" | "error";
1709
+
1710
+ export interface PopoverProps extends WithTestID {
1711
+ /**
1712
+ * The body of the document, rendered under the header when status is "loaded". Use this for
1713
+ * rich content; prefer `text` for a plain summary.
1714
+ */
1715
+ children?: React.ReactNode;
1716
+ /**
1717
+ * Supporting copy shown under the error title.
1718
+ * @default "Something went wrong while loading this document. Check your connection and try again."
1719
+ */
1720
+ errorText?: string;
1721
+ /**
1722
+ * Title shown in the error state.
1723
+ * @default "Couldn't load this document"
1724
+ */
1725
+ errorTitle?: string;
1726
+ /**
1727
+ * The currently selected feedback on the document. Only shown when `onFeedbackChange` is set.
1728
+ */
1729
+ feedback?: ThumbsUpDownFeedbackValue;
1730
+ /**
1731
+ * Height of the popover. The popover is the same height in every status: the body scrolls when
1732
+ * it overflows, and the spinner and error message are centered in the remaining space.
1733
+ * @default 480
1734
+ */
1735
+ height?: NumberOrPercentage;
1736
+ /**
1737
+ * Header text shown while the document is loading.
1738
+ * @default "Loading document..."
1739
+ */
1740
+ loadingText?: string;
1741
+ /**
1742
+ * Called when the close button is pressed.
1743
+ */
1744
+ onClose: () => void | Promise<void>;
1745
+ /**
1746
+ * Called with the newly selected feedback, or undefined when the current value is deselected.
1747
+ * When omitted, the thumbs up/down controls are hidden.
1748
+ */
1749
+ onFeedbackChange?: (value?: ThumbsUpDownFeedbackValue) => void | Promise<void>;
1750
+ /**
1751
+ * Called when the "Open" action is pressed. When omitted, the action is hidden.
1752
+ */
1753
+ onOpen?: () => void | Promise<void>;
1754
+ /**
1755
+ * Called when the "Try again" button is pressed in the error state. When omitted, the button
1756
+ * is hidden.
1757
+ */
1758
+ onRetry?: () => void | Promise<void>;
1759
+ /**
1760
+ * Text of the action that opens the full document.
1761
+ * @default "Open"
1762
+ */
1763
+ openText?: string;
1764
+ /**
1765
+ * Text of the button that retries loading in the error state.
1766
+ * @default "Try again"
1767
+ */
1768
+ retryText?: string;
1769
+ /**
1770
+ * The state of the document being previewed.
1771
+ * @default "loaded"
1772
+ */
1773
+ status?: PopoverStatus;
1774
+ /**
1775
+ * Secondary header line, usually the document's date.
1776
+ */
1777
+ subtitle?: string;
1778
+ /**
1779
+ * A plain text summary of the document, rendered when no `children` are provided.
1780
+ */
1781
+ text?: string;
1782
+ /**
1783
+ * The document's title, shown in the header when status is "loaded".
1784
+ */
1785
+ title?: string;
1786
+ /**
1787
+ * Width of the popover.
1788
+ * @default 480
1789
+ */
1790
+ width?: NumberOrPercentage;
1791
+ }
1792
+
1711
1793
  export interface SelectBadgeProps {
1712
1794
  /**
1713
1795
  * When status is "custom", determines the badge's background color.
@@ -2077,24 +2159,31 @@ export interface HeightActionSheetProps {
2077
2159
  title?: string;
2078
2160
  }
2079
2161
 
2162
+ export interface LinkifyMatch {
2163
+ index: number;
2164
+ lastIndex: number;
2165
+ raw: string;
2166
+ schema: string;
2167
+ text: string;
2168
+ url: string;
2169
+ }
2170
+
2171
+ export interface LinkifyItLike {
2172
+ pretest: (text: string) => boolean;
2173
+ test: (text: string) => boolean;
2174
+ match: (text: string) => LinkifyMatch[] | null;
2175
+ }
2176
+
2080
2177
  export interface HyperlinkProps {
2081
2178
  linkDefault?: boolean;
2082
- // noExplicitAny: linkify-it library's main export lacks a TypeScript type definition
2083
- // biome-ignore lint/suspicious/noExplicitAny: linkify-it library's main export lacks a TypeScript type definition
2084
- linkify?: any;
2085
- // noExplicitAny: StyleProp's generic is heterogeneous (TextStyle | ViewStyle) for link contexts
2086
- // biome-ignore lint/suspicious/noExplicitAny: StyleProp's generic is heterogeneous (TextStyle | ViewStyle) for link contexts
2087
- linkStyle?: StyleProp<any>;
2179
+ linkify?: LinkifyItLike;
2180
+ linkStyle?: StyleProp<TextStyle>;
2088
2181
  linkText?: string | ((url: string) => string);
2089
2182
  onPress?: (url: string) => void;
2090
2183
  onLongPress?: (url: string, text: string) => void;
2091
- // noExplicitAny: returned view props are spread onto a heterogeneous View; consumers pass arbitrary props
2092
- // biome-ignore lint/suspicious/noExplicitAny: returned view props are spread onto a heterogeneous View; consumers pass arbitrary props
2093
- injectViewProps?: (url: string) => any;
2184
+ injectViewProps?: (url: string) => Record<string, unknown>;
2094
2185
  children?: React.ReactNode;
2095
- // noExplicitAny: StyleProp's generic is heterogeneous for the container which holds mixed Text/View children
2096
- // biome-ignore lint/suspicious/noExplicitAny: StyleProp's generic is heterogeneous for the container which holds mixed Text/View children
2097
- style?: StyleProp<any>;
2186
+ style?: StyleProp<ViewStyle | TextStyle>;
2098
2187
  }
2099
2188
 
2100
2189
  export interface IconButtonProps extends WithTestID {
@@ -2283,6 +2372,8 @@ export interface PageProps extends WithTestID {
2283
2372
  display?: "flex" | "none" | "block" | "inlineBlock";
2284
2373
  title?: string;
2285
2374
  backButton?: boolean;
2375
+ /** When set, invoked instead of `router.back()` for the header back arrow. */
2376
+ onBack?: () => void;
2286
2377
  closeButton?: boolean;
2287
2378
  direction?: "row" | "column";
2288
2379
  padding?: UnsignedUpTo12;
@@ -2836,6 +2927,14 @@ export type TapToEditProps =
2836
2927
  });
2837
2928
 
2838
2929
  export interface BaseTapToEditProps extends Omit<FieldProps, "onChange" | "value"> {
2930
+ /**
2931
+ * Root test id. Forwards to the Field input and suffixes action controls for e2e:
2932
+ * `{testID}.edit-clickable`, `{testID}.cancel`, `{testID}.clear`, `{testID}.save`.
2933
+ * The edit control is a pressable Box (`-clickable` is appended by Box).
2934
+ * Cancel/Clear/Save only render when the user opened edit from inside the
2935
+ * component, not when `isEditing` is true.
2936
+ */
2937
+ testID?: string;
2839
2938
  title: string;
2840
2939
  // noExplicitAny: value type varies across TapToEdit field types (text, number, date, etc.)
2841
2940
  // biome-ignore lint/suspicious/noExplicitAny: value type varies across TapToEdit field types (text, number, date, etc.)
@@ -0,0 +1,129 @@
1
+ import {describe, it, mock} from "bun:test";
2
+ import {join} from "node:path";
3
+ import {act, fireEvent} from "@testing-library/react-native";
4
+ import {assert} from "chai";
5
+ import type React from "react";
6
+
7
+ const ISOLATED_RUN_ENV = "TERRENO_CONSENT_MARKDOWN_GATE_ISOLATED";
8
+ const isIsolatedRun = process.env[ISOLATED_RUN_ENV] === "true";
9
+
10
+ const form = {
11
+ active: true,
12
+ agreeButtonText: "I agree",
13
+ allowDecline: false,
14
+ captureSignature: false,
15
+ checkboxes: [],
16
+ content: {en: "Consent body"},
17
+ declineButtonText: "Decline",
18
+ defaultLocale: "en",
19
+ id: "consent-1",
20
+ order: 0,
21
+ required: true,
22
+ requireScrollToBottom: true,
23
+ slug: "consent",
24
+ title: "Consent",
25
+ type: "tos" as const,
26
+ version: 1,
27
+ };
28
+
29
+ if (isIsolatedRun) {
30
+ let markdownOnLoad: (() => void) | undefined;
31
+ let markdownRenderCount = 0;
32
+
33
+ mock.module("./MarkdownView", () => ({
34
+ MarkdownView: ({children, onLoad}: {children?: React.ReactNode; onLoad?: () => void}) => {
35
+ markdownRenderCount += 1;
36
+ markdownOnLoad = onLoad;
37
+ return <>{children}</>;
38
+ },
39
+ }));
40
+
41
+ const [{ConsentFormScreen}, {renderWithTheme}] = await Promise.all([
42
+ import("./ConsentFormScreen"),
43
+ import("./test-utils"),
44
+ ]);
45
+
46
+ describe("ConsentFormScreen markdown load gate isolated behavior", () => {
47
+ it("ignores layout, content-size, and scroll events until markdown loads", () => {
48
+ const {getByTestId, queryByTestId} = renderWithTheme(
49
+ <ConsentFormScreen form={form} locale="en" onAgree={() => {}} />
50
+ );
51
+ const scroll = getByTestId("consent-form-scroll-view");
52
+
53
+ assert.equal(markdownRenderCount, 1);
54
+ assert.isFunction(markdownOnLoad);
55
+
56
+ act(() => {
57
+ fireEvent(scroll, "contentSizeChange", 0, 400);
58
+ });
59
+ assert.isOk(getByTestId("consent-form-scroll-hint"));
60
+
61
+ act(() => {
62
+ fireEvent(scroll, "layout", {nativeEvent: {layout: {height: 500}}});
63
+ });
64
+ assert.isOk(getByTestId("consent-form-scroll-hint"));
65
+
66
+ act(() => {
67
+ fireEvent(scroll, "contentSizeChange", 0, 400);
68
+ });
69
+ assert.isOk(getByTestId("consent-form-scroll-hint"));
70
+
71
+ act(() => {
72
+ fireEvent(scroll, "scroll", {
73
+ nativeEvent: {
74
+ contentOffset: {y: 0},
75
+ contentSize: {height: 100},
76
+ layoutMeasurement: {height: 500},
77
+ },
78
+ });
79
+ });
80
+ assert.isOk(getByTestId("consent-form-scroll-hint"));
81
+
82
+ act(() => {
83
+ markdownOnLoad?.();
84
+ });
85
+
86
+ act(() => {
87
+ fireEvent(scroll, "contentSizeChange", 0, 400);
88
+ });
89
+ assert.isNull(queryByTestId("consent-form-scroll-hint"));
90
+
91
+ act(() => {
92
+ fireEvent(scroll, "contentSizeChange", 0, 2000);
93
+ });
94
+ assert.isOk(getByTestId("consent-form-scroll-hint"));
95
+ });
96
+ });
97
+ } else {
98
+ const {MarkdownView: RealMarkdownViewBefore} = await import("./MarkdownView");
99
+
100
+ describe("ConsentFormScreen markdown load gate", () => {
101
+ it("runs deterministic pre-load checks without leaking its MarkdownView mock", async () => {
102
+ const child = Bun.spawn(
103
+ [
104
+ process.execPath,
105
+ "test",
106
+ "--preload",
107
+ join(import.meta.dir, "bunSetup.ts"),
108
+ import.meta.path,
109
+ ],
110
+ {
111
+ cwd: join(import.meta.dir, ".."),
112
+ env: {...process.env, [ISOLATED_RUN_ENV]: "true"},
113
+ stderr: "pipe",
114
+ stdout: "pipe",
115
+ }
116
+ );
117
+ const [exitCode, stdout, stderr] = await Promise.all([
118
+ child.exited,
119
+ new Response(child.stdout).text(),
120
+ new Response(child.stderr).text(),
121
+ ]);
122
+
123
+ assert.equal(exitCode, 0, `${stdout}\n${stderr}`);
124
+
125
+ const {MarkdownView: RealMarkdownViewAfter} = await import("./MarkdownView");
126
+ assert.strictEqual(RealMarkdownViewAfter, RealMarkdownViewBefore);
127
+ });
128
+ });
129
+ }
@@ -1,8 +1,11 @@
1
- import {describe, expect, it, mock} from "bun:test";
2
- import {act, fireEvent} from "@testing-library/react-native";
1
+ import {afterEach, describe, expect, it, mock} from "bun:test";
2
+ import {act, fireEvent, render, waitFor} from "@testing-library/react-native";
3
+ import {assert} from "chai";
4
+ import {Platform} from "react-native";
3
5
 
4
6
  import {ConsentFormScreen} from "./ConsentFormScreen";
5
7
  import {SignatureField} from "./SignatureField";
8
+ import {ThemeProvider} from "./Theme";
6
9
  import {renderWithTheme} from "./test-utils";
7
10
  import type {ConsentFormPublic} from "./useConsentForms";
8
11
 
@@ -25,6 +28,12 @@ const baseForm: ConsentFormPublic = {
25
28
  version: 1,
26
29
  };
27
30
 
31
+ const waitForConsentMarkdown = async (getByText: (text: string) => unknown): Promise<void> => {
32
+ await waitFor(() => {
33
+ expect(getByText("Consent body")).toBeTruthy();
34
+ });
35
+ };
36
+
28
37
  describe("ConsentFormScreen", () => {
29
38
  it("renders with default state and a locale fallback", () => {
30
39
  const onAgree = mock(() => {});
@@ -274,13 +283,13 @@ describe("ConsentFormScreen", () => {
274
283
  });
275
284
  });
276
285
 
277
- it("auto-satisfies scroll requirement when content fits the viewport via contentSizeChange", () => {
286
+ it("auto-satisfies scroll requirement when content fits the viewport via contentSizeChange", async () => {
278
287
  const form = {...baseForm, requireScrollToBottom: true};
279
- const {getByTestId, queryByTestId} = renderWithTheme(
288
+ const {getByTestId, getByText, queryByTestId} = renderWithTheme(
280
289
  <ConsentFormScreen form={form} locale="en" onAgree={() => {}} />
281
290
  );
291
+ await waitForConsentMarkdown(getByText);
282
292
  const scroll = getByTestId("consent-form-scroll-view");
283
- // First set the layout height, then content size smaller than layout
284
293
  act(() => {
285
294
  fireEvent(scroll, "layout", {nativeEvent: {layout: {height: 500}}});
286
295
  });
@@ -290,13 +299,13 @@ describe("ConsentFormScreen", () => {
290
299
  expect(queryByTestId("consent-form-scroll-hint")).toBeNull();
291
300
  });
292
301
 
293
- it("auto-satisfies scroll requirement when content fits the viewport via layout", () => {
302
+ it("auto-satisfies scroll requirement when content fits the viewport via layout", async () => {
294
303
  const form = {...baseForm, requireScrollToBottom: true};
295
- const {getByTestId, queryByTestId} = renderWithTheme(
304
+ const {getByTestId, getByText, queryByTestId} = renderWithTheme(
296
305
  <ConsentFormScreen form={form} locale="en" onAgree={() => {}} />
297
306
  );
307
+ await waitForConsentMarkdown(getByText);
298
308
  const scroll = getByTestId("consent-form-scroll-view");
299
- // First set the content size, then layout height larger than content
300
309
  act(() => {
301
310
  fireEvent(scroll, "contentSizeChange", 0, 300);
302
311
  });
@@ -306,6 +315,57 @@ describe("ConsentFormScreen", () => {
306
315
  expect(queryByTestId("consent-form-scroll-hint")).toBeNull();
307
316
  });
308
317
 
318
+ it("re-requires scroll when lazy content grows past the viewport", async () => {
319
+ const form = {...baseForm, requireScrollToBottom: true};
320
+ const {getByTestId, getByText, queryByTestId} = renderWithTheme(
321
+ <ConsentFormScreen form={form} locale="en" onAgree={() => {}} />
322
+ );
323
+ await waitForConsentMarkdown(getByText);
324
+ const scroll = getByTestId("consent-form-scroll-view");
325
+ act(() => {
326
+ fireEvent(scroll, "layout", {nativeEvent: {layout: {height: 500}}});
327
+ });
328
+ act(() => {
329
+ fireEvent(scroll, "contentSizeChange", 0, 80);
330
+ });
331
+ expect(queryByTestId("consent-form-scroll-hint")).toBeNull();
332
+ act(() => {
333
+ fireEvent(scroll, "contentSizeChange", 0, 2000);
334
+ });
335
+ expect(getByTestId("consent-form-scroll-hint")).toBeTruthy();
336
+ });
337
+
338
+ it("keeps a completed scroll when content shrinks after the in-list hint unmounts", async () => {
339
+ const form = {...baseForm, requireScrollToBottom: true};
340
+ const {getByTestId, getByText, queryByTestId} = renderWithTheme(
341
+ <ConsentFormScreen form={form} locale="en" onAgree={() => {}} />
342
+ );
343
+ await waitForConsentMarkdown(getByText);
344
+ const scroll = getByTestId("consent-form-scroll-view");
345
+ act(() => {
346
+ fireEvent(scroll, "layout", {nativeEvent: {layout: {height: 500}}});
347
+ });
348
+ act(() => {
349
+ fireEvent(scroll, "contentSizeChange", 0, 2000);
350
+ });
351
+ expect(getByTestId("consent-form-scroll-hint")).toBeTruthy();
352
+ act(() => {
353
+ fireEvent(scroll, "scroll", {
354
+ nativeEvent: {
355
+ contentOffset: {y: 1480},
356
+ contentSize: {height: 2000},
357
+ layoutMeasurement: {height: 500},
358
+ },
359
+ });
360
+ });
361
+ expect(queryByTestId("consent-form-scroll-hint")).toBeNull();
362
+ act(() => {
363
+ fireEvent(scroll, "contentSizeChange", 0, 1900);
364
+ });
365
+ expect(queryByTestId("consent-form-scroll-hint")).toBeNull();
366
+ expect(getByTestId("consent-form-agree-button")).toBeTruthy();
367
+ });
368
+
309
369
  it("handleScroll returns early when already scrolled to bottom", () => {
310
370
  const form = {...baseForm, requireScrollToBottom: false};
311
371
  const {getByTestId} = renderWithTheme(
@@ -394,3 +454,80 @@ describe("ConsentFormScreen", () => {
394
454
  expect(sig).toBeTruthy();
395
455
  });
396
456
  });
457
+
458
+ describe("ConsentFormScreen web scroll measurement", () => {
459
+ const originalOS = Platform.OS;
460
+ const originalRequestAnimationFrame = globalThis.requestAnimationFrame;
461
+ let frames: FrameRequestCallback[] = [];
462
+
463
+ const renderOnWeb = (scrollNode: {clientHeight?: number; scrollHeight?: number} | null) => {
464
+ Platform.OS = "web";
465
+ frames = [];
466
+ globalThis.requestAnimationFrame = ((callback: FrameRequestCallback): number => {
467
+ frames.push(callback);
468
+ return frames.length;
469
+ }) as typeof globalThis.requestAnimationFrame;
470
+
471
+ return render(
472
+ <ConsentFormScreen
473
+ form={{...baseForm, requireScrollToBottom: true}}
474
+ locale="en"
475
+ onAgree={() => {}}
476
+ />,
477
+ {
478
+ createNodeMock: () => ({getScrollableNode: () => scrollNode}),
479
+ wrapper: ThemeProvider,
480
+ }
481
+ );
482
+ };
483
+
484
+ const flushFrames = (): void => {
485
+ act(() => {
486
+ for (const frame of frames.splice(0)) {
487
+ frame(0);
488
+ }
489
+ });
490
+ };
491
+
492
+ afterEach(() => {
493
+ Platform.OS = originalOS;
494
+ globalThis.requestAnimationFrame = originalRequestAnimationFrame;
495
+ });
496
+
497
+ it("unlocks the gate when the loaded content fits the viewport", async () => {
498
+ const {getByText, queryByTestId} = renderOnWeb({clientHeight: 500, scrollHeight: 200});
499
+ await waitForConsentMarkdown(getByText);
500
+
501
+ flushFrames();
502
+
503
+ assert.isNull(queryByTestId("consent-form-scroll-hint"));
504
+ assert.isNull(queryByTestId("consent-footer-scroll-hint"));
505
+ });
506
+
507
+ it("keeps the gate when the loaded content overflows the viewport", async () => {
508
+ const {getByTestId, getByText} = renderOnWeb({clientHeight: 200, scrollHeight: 900});
509
+ await waitForConsentMarkdown(getByText);
510
+
511
+ flushFrames();
512
+
513
+ assert.isNotNull(getByTestId("consent-form-scroll-hint"));
514
+ });
515
+
516
+ it("keeps the gate when the scroll node has no measurements", async () => {
517
+ const {getByTestId, getByText} = renderOnWeb({});
518
+ await waitForConsentMarkdown(getByText);
519
+
520
+ flushFrames();
521
+
522
+ assert.isNotNull(getByTestId("consent-form-scroll-hint"));
523
+ });
524
+
525
+ it("keeps the gate when the scroll view has no node", async () => {
526
+ const {getByTestId, getByText} = renderOnWeb(null);
527
+ await waitForConsentMarkdown(getByText);
528
+
529
+ flushFrames();
530
+
531
+ assert.isNotNull(getByTestId("consent-form-scroll-hint"));
532
+ });
533
+ });
@@ -1,4 +1,4 @@
1
- import React, {useState} from "react";
1
+ import React, {useCallback, useRef, useState} from "react";
2
2
  import {
3
3
  type LayoutChangeEvent,
4
4
  type NativeScrollEvent,
@@ -44,6 +44,9 @@ export const ConsentFormScreen: React.FC<ConsentFormScreenProps> = ({
44
44
  const [scrollEnabled, setScrollEnabled] = useState(true);
45
45
  const [contentHeight, setContentHeight] = useState(0);
46
46
  const [layoutHeight, setLayoutHeight] = useState(0);
47
+ const [isMarkdownLoaded, setIsMarkdownLoaded] = useState(false);
48
+ const lastContentHeightRef = useRef(0);
49
+ const scrollViewRef = useRef<ScrollView>(null);
47
50
 
48
51
  const rawContent = form.content[locale] ?? form.content[form.defaultLocale] ?? "";
49
52
  const content = variables
@@ -64,32 +67,77 @@ export const ConsentFormScreen: React.FC<ConsentFormScreenProps> = ({
64
67
  const canAgree = hasScrolledToBottom && allRequiredCheckboxesChecked && signatureProvided;
65
68
  const actionColumnStyle = {flexBasis: 0, minWidth: 0};
66
69
 
67
- // Auto-satisfy scroll requirement when content fits within the viewport
68
- const handleContentSizeChange = (_w: number, h: number) => {
69
- setContentHeight(h);
70
- if (!hasScrolledToBottom && h > 0 && layoutHeight > 0 && h <= layoutHeight) {
71
- setHasScrolledToBottom(true);
70
+ const handleMarkdownLoad = useCallback((): void => {
71
+ lastContentHeightRef.current = 0;
72
+ setContentHeight(0);
73
+ setHasScrolledToBottom(!form.requireScrollToBottom);
74
+ setIsMarkdownLoaded(true);
75
+ if (!form.requireScrollToBottom || Platform.OS !== "web") {
76
+ return;
72
77
  }
73
- };
78
+ requestAnimationFrame(() => {
79
+ const scrollNode = scrollViewRef.current?.getScrollableNode() as unknown as {
80
+ clientHeight?: number;
81
+ scrollHeight?: number;
82
+ };
83
+ if (
84
+ typeof scrollNode?.clientHeight !== "number" ||
85
+ typeof scrollNode.scrollHeight !== "number"
86
+ ) {
87
+ return;
88
+ }
89
+ setHasScrolledToBottom(scrollNode.scrollHeight <= scrollNode.clientHeight);
90
+ });
91
+ }, [form.requireScrollToBottom]);
74
92
 
75
- const handleLayout = (event: LayoutChangeEvent) => {
76
- const h = event.nativeEvent.layout.height;
77
- setLayoutHeight(h);
78
- if (!hasScrolledToBottom && contentHeight > 0 && h > 0 && contentHeight <= h) {
79
- setHasScrolledToBottom(true);
80
- }
81
- };
93
+ // Auto-satisfy only after markdown exists. Empty Spinner fallback (300ms delay) must not
94
+ // unlock Agree. Reset only when content grows past the viewport, not when the hint unmounts.
95
+ const handleContentSizeChange = useCallback(
96
+ (_w: number, h: number): void => {
97
+ const previousContentH = lastContentHeightRef.current;
98
+ lastContentHeightRef.current = h;
99
+ setContentHeight(h);
100
+ if (!form.requireScrollToBottom || !isMarkdownLoaded || layoutHeight <= 0 || h <= 0) {
101
+ return;
102
+ }
103
+ if (h <= layoutHeight) {
104
+ setHasScrolledToBottom(true);
105
+ return;
106
+ }
107
+ if (previousContentH > 0 && h > previousContentH) {
108
+ setHasScrolledToBottom(false);
109
+ }
110
+ },
111
+ [form.requireScrollToBottom, isMarkdownLoaded, layoutHeight]
112
+ );
82
113
 
83
- const handleScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
84
- if (hasScrolledToBottom) {
85
- return;
86
- }
87
- const {contentOffset, contentSize, layoutMeasurement} = event.nativeEvent;
88
- const distanceFromBottom = contentSize.height - layoutMeasurement.height - contentOffset.y;
89
- if (distanceFromBottom <= 20) {
90
- setHasScrolledToBottom(true);
91
- }
92
- };
114
+ const handleLayout = useCallback(
115
+ (event: LayoutChangeEvent): void => {
116
+ const h = event.nativeEvent.layout.height;
117
+ setLayoutHeight(h);
118
+ if (!form.requireScrollToBottom || !isMarkdownLoaded || contentHeight <= 0 || h <= 0) {
119
+ return;
120
+ }
121
+ if (contentHeight <= h) {
122
+ setHasScrolledToBottom(true);
123
+ }
124
+ },
125
+ [contentHeight, form.requireScrollToBottom, isMarkdownLoaded]
126
+ );
127
+
128
+ const handleScroll = useCallback(
129
+ (event: NativeSyntheticEvent<NativeScrollEvent>): void => {
130
+ if (!isMarkdownLoaded || hasScrolledToBottom) {
131
+ return;
132
+ }
133
+ const {contentOffset, contentSize, layoutMeasurement} = event.nativeEvent;
134
+ const distanceFromBottom = contentSize.height - layoutMeasurement.height - contentOffset.y;
135
+ if (distanceFromBottom <= 20) {
136
+ setHasScrolledToBottom(true);
137
+ }
138
+ },
139
+ [hasScrolledToBottom, isMarkdownLoaded]
140
+ );
93
141
 
94
142
  const handleCheckboxPress = (index: number) => {
95
143
  const checkbox = form.checkboxes[index];
@@ -189,13 +237,14 @@ export const ConsentFormScreen: React.FC<ConsentFormScreenProps> = ({
189
237
  onContentSizeChange={handleContentSizeChange}
190
238
  onLayout={handleLayout}
191
239
  onScroll={handleScroll}
240
+ ref={scrollViewRef}
192
241
  scrollEnabled={scrollEnabled}
193
242
  scrollEventThrottle={16}
194
243
  style={{alignSelf: "center", flex: 1, maxWidth: 800, width: "100%"}}
195
244
  testID="consent-form-scroll-view"
196
245
  >
197
246
  <Box direction="column" gap={3} paddingY={2}>
198
- <MarkdownView>{content}</MarkdownView>
247
+ <MarkdownView onLoad={handleMarkdownLoad}>{content}</MarkdownView>
199
248
 
200
249
  {form.checkboxes.length > 0 && (
201
250
  <Box direction="column" gap={2} testID="consent-form-checkboxes">