@terreno/ui 0.25.0 → 0.27.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 (130) hide show
  1. package/.ai/guidelines/core.md +1 -0
  2. package/dist/ActionSheet.js.map +1 -1
  3. package/dist/AiSuggestionBox.js +1 -1
  4. package/dist/AiSuggestionBox.js.map +1 -1
  5. package/dist/Avatar.js +4 -1
  6. package/dist/Avatar.js.map +1 -1
  7. package/dist/BooleanField.js +2 -1
  8. package/dist/BooleanField.js.map +1 -1
  9. package/dist/Box.js +2 -0
  10. package/dist/Box.js.map +1 -1
  11. package/dist/Common.d.ts +7 -1
  12. package/dist/Common.js +1 -1
  13. package/dist/Common.js.map +1 -1
  14. package/dist/ConsentNavigator.js.map +1 -1
  15. package/dist/CustomSelectField.js +1 -1
  16. package/dist/CustomSelectField.js.map +1 -1
  17. package/dist/DateTimeField.js +4 -1
  18. package/dist/DateTimeField.js.map +1 -1
  19. package/dist/EmailField.js +1 -1
  20. package/dist/EmailField.js.map +1 -1
  21. package/dist/HeightField.js +3 -1
  22. package/dist/HeightField.js.map +1 -1
  23. package/dist/IconButton.js +10 -1
  24. package/dist/IconButton.js.map +1 -1
  25. package/dist/MarkdownEditorField.js +3 -1
  26. package/dist/MarkdownEditorField.js.map +1 -1
  27. package/dist/Modal.js +7 -2
  28. package/dist/Modal.js.map +1 -1
  29. package/dist/MultiselectField.js +2 -1
  30. package/dist/MultiselectField.js.map +1 -1
  31. package/dist/Page.js +1 -0
  32. package/dist/Page.js.map +1 -1
  33. package/dist/Permissions.d.ts +1 -1
  34. package/dist/Permissions.js +2 -2
  35. package/dist/Permissions.js.map +1 -1
  36. package/dist/SelectField.js +3 -1
  37. package/dist/SelectField.js.map +1 -1
  38. package/dist/SplitPage.js +3 -0
  39. package/dist/SplitPage.js.map +1 -1
  40. package/dist/SplitPage.native.js +2 -0
  41. package/dist/SplitPage.native.js.map +1 -1
  42. package/dist/TapToEdit.js +1 -0
  43. package/dist/TapToEdit.js.map +1 -1
  44. package/dist/TextField.js +3 -1
  45. package/dist/TextField.js.map +1 -1
  46. package/dist/ToastNotifications.js.map +1 -1
  47. package/dist/Unifier.js.map +1 -1
  48. package/dist/index.d.ts +8 -2
  49. package/dist/index.js +6 -2
  50. package/dist/index.js.map +1 -1
  51. package/dist/useSubmitConsent.d.ts +1 -1
  52. package/dist/useSubmitConsent.js +1 -1
  53. package/dist/useSubmitConsent.js.map +1 -1
  54. package/package.json +2 -2
  55. package/src/ActionSheet.test.tsx +1 -0
  56. package/src/ActionSheet.tsx +2 -0
  57. package/src/AiSuggestionBox.tsx +1 -1
  58. package/src/Avatar.tsx +4 -1
  59. package/src/Badge.test.tsx +1 -2
  60. package/src/BooleanField.tsx +2 -1
  61. package/src/Box.test.tsx +56 -0
  62. package/src/Box.tsx +4 -0
  63. package/src/Button.test.tsx +34 -0
  64. package/src/Common.ts +31 -1
  65. package/src/ConsentNavigator.test.tsx +1 -0
  66. package/src/ConsentNavigator.tsx +1 -0
  67. package/src/CustomSelectField.tsx +1 -1
  68. package/src/DataTable.test.tsx +1 -0
  69. package/src/DateTimeField.test.tsx +1 -0
  70. package/src/DateTimeField.tsx +4 -1
  71. package/src/EmailField.tsx +1 -1
  72. package/src/HeightField.tsx +3 -1
  73. package/src/IconButton.test.tsx +26 -0
  74. package/src/IconButton.tsx +10 -0
  75. package/src/MarkdownEditorField.tsx +3 -1
  76. package/src/Modal.test.tsx +261 -66
  77. package/src/Modal.tsx +7 -2
  78. package/src/ModalSheet.test.tsx +7 -6
  79. package/src/MultiselectField.tsx +2 -1
  80. package/src/Page.tsx +1 -0
  81. package/src/Permissions.ts +2 -2
  82. package/src/PickerSelect.test.tsx +1 -0
  83. package/src/SelectBadge.test.tsx +1 -2
  84. package/src/SelectField.tsx +3 -1
  85. package/src/Signature.test.tsx +52 -0
  86. package/src/SplitPage.native.tsx +2 -0
  87. package/src/SplitPage.test.tsx +6 -4
  88. package/src/SplitPage.tsx +3 -0
  89. package/src/TapToEdit.test.tsx +1 -0
  90. package/src/TapToEdit.tsx +2 -0
  91. package/src/Text.test.tsx +29 -0
  92. package/src/TextField.test.tsx +57 -1
  93. package/src/TextField.tsx +3 -1
  94. package/src/ToastNotifications.test.tsx +1 -0
  95. package/src/ToastNotifications.tsx +1 -0
  96. package/src/Tooltip.test.tsx +1 -1
  97. package/src/Unifier.ts +1 -0
  98. package/src/UpgradeRequiredScreen.test.tsx +40 -0
  99. package/src/UserInactivity.test.tsx +44 -1
  100. package/src/WebDropdownMenu.test.tsx +116 -1
  101. package/src/__snapshots__/DataTable.test.tsx.snap +0 -148
  102. package/src/__snapshots__/IconButton.test.tsx.snap +4 -0
  103. package/src/__snapshots__/InfoModalIcon.test.tsx.snap +255 -1088
  104. package/src/__snapshots__/Modal.test.tsx.snap +950 -1108
  105. package/src/bunSetup.ts +24 -0
  106. package/src/createWebPortal.test.tsx +17 -0
  107. package/src/index.tsx +18 -2
  108. package/src/types/react-native-swiper-flatlist.d.ts +1 -0
  109. package/src/useSubmitConsent.test.ts +2 -1
  110. package/src/useSubmitConsent.ts +2 -2
  111. package/dist/fieldElements/index.d.ts +0 -3
  112. package/dist/fieldElements/index.js +0 -4
  113. package/dist/fieldElements/index.js.map +0 -1
  114. package/dist/icons/index.d.ts +0 -5
  115. package/dist/icons/index.js +0 -6
  116. package/dist/icons/index.js.map +0 -1
  117. package/dist/login/index.d.ts +0 -2
  118. package/dist/login/index.js +0 -2
  119. package/dist/login/index.js.map +0 -1
  120. package/dist/signUp/index.d.ts +0 -6
  121. package/dist/signUp/index.js +0 -6
  122. package/dist/signUp/index.js.map +0 -1
  123. package/dist/testing/index.d.ts +0 -2
  124. package/dist/testing/index.js +0 -3
  125. package/dist/testing/index.js.map +0 -1
  126. package/src/fieldElements/index.tsx +0 -3
  127. package/src/icons/index.ts +0 -5
  128. package/src/login/index.ts +0 -2
  129. package/src/signUp/index.ts +0 -13
  130. package/src/testing/index.ts +0 -2
@@ -157,6 +157,32 @@ describe("IconButton", () => {
157
157
  expect(toJSON()).toMatchSnapshot();
158
158
  });
159
159
 
160
+ it("renders primary variant in active state", () => {
161
+ const {toJSON} = renderWithTheme(
162
+ <IconButton
163
+ accessibilityLabel="Test"
164
+ iconName="check"
165
+ onClick={() => {}}
166
+ state="active"
167
+ variant="primary"
168
+ />
169
+ );
170
+ expect(toJSON()).toMatchSnapshot();
171
+ });
172
+
173
+ it("renders ghost variant in active state", () => {
174
+ const {toJSON} = renderWithTheme(
175
+ <IconButton
176
+ accessibilityLabel="Test"
177
+ iconName="check"
178
+ onClick={() => {}}
179
+ state="active"
180
+ variant="ghost"
181
+ />
182
+ );
183
+ expect(toJSON()).toMatchSnapshot();
184
+ });
185
+
160
186
  describe("custom icons", () => {
161
187
  // IconButton renders `null` under the bun/react-test-renderer harness (all of
162
188
  // its snapshots are null), so we verify the custom-icon code path renders
@@ -57,6 +57,7 @@ const IconButtonComponent: FC<IconButtonProps> = ({
57
57
  indicatorText,
58
58
  loading: propsLoading = false,
59
59
  size = "default",
60
+ state = "default",
60
61
  testID,
61
62
  variant = "primary",
62
63
  withConfirmation = false,
@@ -99,6 +100,15 @@ const IconButtonComponent: FC<IconButtonProps> = ({
99
100
  color = theme.surface.secondaryDark;
100
101
  }
101
102
 
103
+ if (!disabled && state === "active") {
104
+ if (variant === "primary") {
105
+ backgroundColor = theme.primitives.primary600;
106
+ } else {
107
+ backgroundColor = theme.surface.primary;
108
+ color = theme.text.inverted;
109
+ }
110
+ }
111
+
102
112
  const indicatorColor = indicator ? theme.surface[indicator] : undefined;
103
113
 
104
114
  return (
@@ -4,7 +4,9 @@ import {Platform, Pressable, Text as RNText, ScrollView, TextInput, View} from "
4
4
 
5
5
  import {Box} from "./Box";
6
6
  import type {ErrorTextProps, HelperTextProps} from "./Common";
7
- import {FieldError, FieldHelperText, FieldTitle} from "./fieldElements";
7
+ import {FieldError} from "./fieldElements/FieldError";
8
+ import {FieldHelperText} from "./fieldElements/FieldHelperText";
9
+ import {FieldTitle} from "./fieldElements/FieldTitle";
8
10
  import {MarkdownView} from "./MarkdownView";
9
11
  import {Text} from "./Text";
10
12
  import {useTheme} from "./Theme";
@@ -1,10 +1,15 @@
1
- import {afterEach, describe, expect, it, mock} from "bun:test";
1
+ import {afterEach, beforeEach, describe, expect, it, mock, spyOn} from "bun:test";
2
2
  import {fireEvent} from "@testing-library/react-native";
3
+ import {assert} from "chai";
4
+ // Import Platform the same way the source modules do (ESM named import) so the web blur effect
5
+ // (which reads Platform.OS directly in Modal.tsx) observes the value the test sets.
6
+ import {Platform as ImportedPlatform} from "react-native";
7
+ import {Gesture} from "react-native-gesture-handler";
3
8
 
4
- import {isMobileDevice} from "./MediaQuery";
5
9
  import {Modal} from "./Modal";
6
10
  import {Text} from "./Text";
7
11
  import {renderWithTheme} from "./test-utils";
12
+ import * as Utilities from "./Utilities";
8
13
 
9
14
  // Minimal shape of a test instance returned by UNSAFE_getAllByType that we rely on here.
10
15
  interface PressableTestInstance {
@@ -16,7 +21,135 @@ interface PressableTestInstance {
16
21
  };
17
22
  }
18
23
 
24
+ /**
25
+ * Finds the web-only translucent backdrop Pressable in a rendered Modal tree.
26
+ *
27
+ * The web branch renders a full-screen Pressable whose style sets a semi-transparent
28
+ * `rgba(...)` backgroundColor; the native ActionSheet branch has no such element. Tests use
29
+ * its presence/absence to assert which presentation branch rendered.
30
+ *
31
+ * @param pressables - All Pressable test instances found in the rendered tree.
32
+ * @returns The backdrop Pressable if present, otherwise undefined.
33
+ */
34
+ const findBackdropPressable = (
35
+ pressables: PressableTestInstance[]
36
+ ): PressableTestInstance | undefined => {
37
+ return pressables.find((node) => {
38
+ const style = node.props.style;
39
+ if (Array.isArray(style)) {
40
+ return style.some((s) => s?.backgroundColor?.includes?.("rgba"));
41
+ }
42
+ return style?.backgroundColor?.includes?.("rgba");
43
+ });
44
+ };
45
+
46
+ /**
47
+ * Collects every reachable react-native `Platform` mock object.
48
+ *
49
+ * `Platform.OS` is read through `import {Platform} from "react-native"` in more than one source
50
+ * module (`Modal.tsx` directly, and `Utilities.tsx#isNative`). Depending on module resolution
51
+ * those bindings can map to either the top-level react-native mock or the internal
52
+ * `Libraries/Utilities/Platform` mock, and CI has shown them diverging (mutating one left the
53
+ * other untouched). Gathering all of them lets a single setter drive the platform branch
54
+ * deterministically regardless of which object a given module captured.
55
+ */
56
+ const collectPlatformObjects = (): {OS: string}[] => {
57
+ const objects: {OS: string}[] = [];
58
+ const push = (candidate: unknown): void => {
59
+ if (
60
+ candidate &&
61
+ typeof candidate === "object" &&
62
+ "OS" in (candidate as Record<string, unknown>) &&
63
+ !objects.includes(candidate as {OS: string})
64
+ ) {
65
+ objects.push(candidate as {OS: string});
66
+ }
67
+ };
68
+ // The ESM binding the source files use must come first.
69
+ push(ImportedPlatform);
70
+ const rn = require("react-native") as {Platform?: unknown; default?: {Platform?: unknown}};
71
+ push(rn.Platform);
72
+ push(rn.default?.Platform);
73
+ try {
74
+ // Only the module's `default` object is mutable; the namespace's own `OS` binding is a
75
+ // readonly ES module export and must not be pushed.
76
+ const libPlatform = require("react-native/Libraries/Utilities/Platform") as {
77
+ default?: unknown;
78
+ };
79
+ push(libPlatform.default);
80
+ } catch {
81
+ // The internal Platform module may not be resolvable; the top-level mock still covers it.
82
+ }
83
+ return objects;
84
+ };
85
+
86
+ const platformObjects = collectPlatformObjects();
87
+ const originalPlatformOS = platformObjects.map((platform) => platform.OS);
88
+
89
+ /**
90
+ * Sets `Platform.OS` on every reachable Platform mock so both `Modal` and `isNative` observe it.
91
+ *
92
+ * @param os - The platform value to apply (e.g. "web", "ios", "android").
93
+ */
94
+ const setPlatformOS = (os: string): void => {
95
+ for (const platform of platformObjects) {
96
+ try {
97
+ platform.OS = os;
98
+ } catch {
99
+ // Skip any binding that is not writable; other bindings still drive the branch.
100
+ }
101
+ }
102
+ };
103
+
104
+ /**
105
+ * Restores `Platform.OS` on every reachable Platform mock to the value captured at load time.
106
+ */
107
+ const restorePlatformOS = (): void => {
108
+ platformObjects.forEach((platform, index) => {
109
+ try {
110
+ platform.OS = originalPlatformOS[index] ?? "ios";
111
+ } catch {
112
+ // Skip any binding that is not writable.
113
+ }
114
+ });
115
+ };
116
+
117
+ let isNativeSpy: ReturnType<typeof spyOn> | undefined;
118
+
119
+ /**
120
+ * Forces `isNative()` to a fixed value so the Modal's platform branch is deterministic.
121
+ *
122
+ * Spying on the `Utilities.isNative` export drives the exact live binding `Modal.tsx` calls,
123
+ * which is reliable across environments (unlike mutating react-native's Platform.OS, whose mock
124
+ * object identity can diverge per module on CI).
125
+ *
126
+ * @param value - true to render the native ActionSheet branch, false for the web dialog branch.
127
+ */
128
+ const forceIsNative = (value: boolean): void => {
129
+ isNativeSpy = spyOn(Utilities, "isNative").mockReturnValue(value);
130
+ };
131
+
132
+ /**
133
+ * Restores the real `isNative()` implementation after a forced value.
134
+ */
135
+ const restoreIsNative = (): void => {
136
+ isNativeSpy?.mockRestore();
137
+ isNativeSpy = undefined;
138
+ };
139
+
19
140
  describe("Modal", () => {
141
+ // These tests exercise the default native (ActionSheet) presentation; pin the platform and
142
+ // force isNative() so the branch is deterministic and not left to ambient Platform.OS state.
143
+ beforeEach(() => {
144
+ setPlatformOS("ios");
145
+ forceIsNative(true);
146
+ });
147
+
148
+ afterEach(() => {
149
+ restorePlatformOS();
150
+ restoreIsNative();
151
+ });
152
+
20
153
  it("renders correctly when visible", () => {
21
154
  const {toJSON} = renderWithTheme(
22
155
  <Modal onDismiss={() => {}} title="Test Modal" visible>
@@ -302,6 +435,44 @@ describe("Modal", () => {
302
435
 
303
436
  expect(handleSecondary).toHaveBeenCalled();
304
437
  });
438
+ });
439
+
440
+ describe("Modal web platform", () => {
441
+ const globalScope = globalThis as {document?: unknown; HTMLElement?: unknown};
442
+ const originalDocument = globalScope.document;
443
+ const originalHTMLElement = globalScope.HTMLElement;
444
+
445
+ class FakeHTMLElement {
446
+ blur = mock(() => {});
447
+ }
448
+
449
+ // The web branch runs a blur useEffect that reads `document.activeElement` and checks
450
+ // `instanceof HTMLElement`, so every web test needs Platform.OS === "web" (across every
451
+ // Platform binding, see setPlatformOS) plus a document and HTMLElement stub before rendering.
452
+ beforeEach(() => {
453
+ setPlatformOS("web");
454
+ forceIsNative(false);
455
+ globalScope.HTMLElement = FakeHTMLElement;
456
+ globalScope.document = {activeElement: null};
457
+ });
458
+
459
+ afterEach(() => {
460
+ restorePlatformOS();
461
+ restoreIsNative();
462
+ globalScope.document = originalDocument;
463
+ globalScope.HTMLElement = originalHTMLElement;
464
+ });
465
+
466
+ it("renders the web RNModal backdrop on web", () => {
467
+ const {UNSAFE_getAllByType} = renderWithTheme(
468
+ <Modal onDismiss={() => {}} title="Web Modal" visible>
469
+ <Text>Content</Text>
470
+ </Modal>
471
+ );
472
+ const {Pressable} = require("react-native");
473
+ const pressables: PressableTestInstance[] = UNSAFE_getAllByType(Pressable);
474
+ expect(findBackdropPressable(pressables)).toBeTruthy();
475
+ });
305
476
 
306
477
  it("dismisses when the backdrop is pressed and persistOnBackgroundClick is false", () => {
307
478
  const handleDismiss = mock(() => {});
@@ -313,13 +484,7 @@ describe("Modal", () => {
313
484
  // Find the backdrop Pressable (first Pressable in tree with a style that includes backgroundColor).
314
485
  const {Pressable} = require("react-native");
315
486
  const pressables: PressableTestInstance[] = UNSAFE_getAllByType(Pressable);
316
- const backdrop = pressables.find((node) => {
317
- const style = node.props.style;
318
- if (Array.isArray(style)) {
319
- return style.some((s) => s?.backgroundColor?.includes?.("rgba"));
320
- }
321
- return style?.backgroundColor?.includes?.("rgba");
322
- });
487
+ const backdrop = findBackdropPressable(pressables);
323
488
  expect(backdrop).toBeTruthy();
324
489
  backdrop?.props.onPress?.();
325
490
  expect(handleDismiss).toHaveBeenCalled();
@@ -355,28 +520,8 @@ describe("Modal", () => {
355
520
  inner?.props.onPress?.({stopPropagation});
356
521
  expect(stopPropagation).not.toHaveBeenCalled();
357
522
  });
358
- });
359
-
360
- describe("Modal web platform", () => {
361
- const RN = require("react-native") as {Platform: {OS: string}};
362
- const originalOS = RN.Platform.OS;
363
- const globalScope = globalThis as {document?: unknown; HTMLElement?: unknown};
364
- const originalDocument = globalScope.document;
365
- const originalHTMLElement = globalScope.HTMLElement;
366
-
367
- class FakeHTMLElement {
368
- blur = mock(() => {});
369
- }
370
-
371
- afterEach(() => {
372
- RN.Platform.OS = originalOS;
373
- globalScope.document = originalDocument;
374
- globalScope.HTMLElement = originalHTMLElement;
375
- });
376
523
 
377
524
  it("blurs the focused element when opened on web", () => {
378
- RN.Platform.OS = "web";
379
- globalScope.HTMLElement = FakeHTMLElement;
380
525
  const active = new FakeHTMLElement();
381
526
  globalScope.document = {activeElement: active};
382
527
 
@@ -390,8 +535,6 @@ describe("Modal web platform", () => {
390
535
  });
391
536
 
392
537
  it("does not blur when the active element is not an HTMLElement", () => {
393
- RN.Platform.OS = "web";
394
- globalScope.HTMLElement = FakeHTMLElement;
395
538
  globalScope.document = {activeElement: {}};
396
539
 
397
540
  const {toJSON} = renderWithTheme(
@@ -404,46 +547,98 @@ describe("Modal web platform", () => {
404
547
  });
405
548
  });
406
549
 
407
- describe("Modal mobile branch", () => {
550
+ // The Modal selects its presentation via isNative() (Platform.OS in ios/android), NOT screen
551
+ // size, so these run the native branch explicitly for each native platform. Android is the
552
+ // platform where the original tablet bug occurred, so it must be covered directly rather than
553
+ // relying on the default "ios" test platform.
554
+ describe("Modal native presentation", () => {
408
555
  afterEach(() => {
409
- (isMobileDevice as ReturnType<typeof mock>).mockImplementation(() => false);
410
- });
556
+ restorePlatformOS();
557
+ restoreIsNative();
558
+ });
559
+
560
+ for (const platform of ["ios", "android"] as const) {
561
+ it(`uses the ActionSheet (no web backdrop) on ${platform}`, () => {
562
+ setPlatformOS(platform);
563
+ forceIsNative(true);
564
+ const {UNSAFE_getAllByType, getByText} = renderWithTheme(
565
+ <Modal
566
+ onDismiss={() => {}}
567
+ primaryButtonOnClick={() => {}}
568
+ primaryButtonText="Save"
569
+ title="Native Modal"
570
+ visible
571
+ >
572
+ <Text>Native Content</Text>
573
+ </Modal>
574
+ );
575
+ // Content mounts via the ActionSheet branch...
576
+ expect(getByText("Native Modal")).toBeTruthy();
577
+ // ...and the web-only translucent backdrop Pressable must NOT be present.
578
+ const {Pressable} = require("react-native");
579
+ const pressables: PressableTestInstance[] = UNSAFE_getAllByType(Pressable);
580
+ expect(findBackdropPressable(pressables)).toBeUndefined();
581
+ });
411
582
 
412
- it("renders ActionSheet when isMobileDevice is true", () => {
413
- (isMobileDevice as ReturnType<typeof mock>).mockImplementation(() => true);
414
- const {toJSON} = renderWithTheme(
415
- <Modal onDismiss={() => {}} title="Mobile Modal" visible>
416
- <Text>Mobile Content</Text>
417
- </Modal>
418
- );
419
- expect(toJSON()).toBeTruthy();
583
+ it(`renders nothing when not visible on ${platform}`, () => {
584
+ setPlatformOS(platform);
585
+ forceIsNative(true);
586
+ const {queryByText} = renderWithTheme(
587
+ <Modal onDismiss={() => {}} title="Hidden Native Modal" visible={false}>
588
+ <Text>Native Content</Text>
589
+ </Modal>
590
+ );
591
+ // The ActionSheet stays closed (mock tracks setModalVisible), so no content is shown.
592
+ expect(queryByText("Hidden Native Modal")).toBeNull();
593
+ expect(queryByText("Native Content")).toBeNull();
594
+ });
595
+ }
596
+ });
597
+
598
+ interface CapturedGesture {
599
+ onEnd: {mock: {calls: [(event: {translationY: number}) => void][]}};
600
+ }
601
+
602
+ describe("Modal drag-to-close gesture", () => {
603
+ // The drag handle only renders in the native ActionSheet branch, so force native.
604
+ beforeEach(() => {
605
+ setPlatformOS("ios");
606
+ forceIsNative(true);
420
607
  });
421
608
 
422
- it("renders ActionSheet with title and buttons on mobile", () => {
423
- (isMobileDevice as ReturnType<typeof mock>).mockImplementation(() => true);
424
- const {toJSON} = renderWithTheme(
425
- <Modal
426
- onDismiss={() => {}}
427
- primaryButtonOnClick={() => {}}
428
- primaryButtonText="Save"
429
- secondaryButtonOnClick={() => {}}
430
- secondaryButtonText="Cancel"
431
- title="Mobile Actions"
432
- visible
433
- >
434
- <Text>Content</Text>
435
- </Modal>
436
- );
437
- expect(toJSON()).toBeTruthy();
609
+ afterEach(() => {
610
+ restorePlatformOS();
611
+ restoreIsNative();
438
612
  });
439
613
 
440
- it("renders ActionSheet with persistOnBackgroundClick enabled", () => {
441
- (isMobileDevice as ReturnType<typeof mock>).mockImplementation(() => true);
442
- const {toJSON} = renderWithTheme(
443
- <Modal onDismiss={() => {}} persistOnBackgroundClick title="Persistent Mobile" visible>
444
- <Text>Content</Text>
445
- </Modal>
446
- );
447
- expect(toJSON()).toBeTruthy();
614
+ it("dismisses only when dragged down past the threshold", () => {
615
+ const handleDismiss = mock(() => {});
616
+ let capturedGesture: CapturedGesture | undefined;
617
+ const originalPan = Gesture.Pan;
618
+ (Gesture as {Pan: () => unknown}).Pan = () => {
619
+ capturedGesture = originalPan() as unknown as CapturedGesture;
620
+ return capturedGesture;
621
+ };
622
+
623
+ try {
624
+ renderWithTheme(
625
+ <Modal onDismiss={handleDismiss} title="Draggable" visible>
626
+ <Text>Body</Text>
627
+ </Modal>
628
+ );
629
+
630
+ const onEnd = capturedGesture?.onEnd.mock.calls[0][0];
631
+ assert.isDefined(onEnd);
632
+
633
+ // A small drag stays below the threshold and should not dismiss.
634
+ onEnd?.({translationY: 5});
635
+ assert.lengthOf(handleDismiss.mock.calls, 0);
636
+
637
+ // A drag past the threshold dismisses via runOnJS(handleDismiss).
638
+ onEnd?.({translationY: 40});
639
+ assert.lengthOf(handleDismiss.mock.calls, 1);
640
+ } finally {
641
+ (Gesture as {Pan: () => unknown}).Pan = originalPan;
642
+ }
448
643
  });
449
644
  });
package/src/Modal.tsx CHANGED
@@ -15,7 +15,6 @@ import {Button} from "./Button";
15
15
  import type {ModalProps, TerrenoTheme} from "./Common";
16
16
  import {Heading} from "./Heading";
17
17
  import {Icon} from "./Icon";
18
- import {isMobileDevice} from "./MediaQuery";
19
18
  import {Text} from "./Text";
20
19
  import {useTheme} from "./Theme";
21
20
  import {resolveModalTestIDsFromProps, toTestProps} from "./testing/resolveTestId";
@@ -247,7 +246,13 @@ export const Modal: FC<ModalProps> = ({
247
246
  }
248
247
  }, [visible]);
249
248
 
250
- const isMobile = isMobileDevice() && isNative();
249
+ // Choose the presentation by platform, not by screen size. The web branch below relies on DOM
250
+ // semantics (nested Pressables using `e.stopPropagation()` and a `cursor` style) that native
251
+ // platforms do not implement, so it must only run on web. Keying this off screen size instead
252
+ // sent native *tablets* (width >= "sm") down the web branch: on Android the nested Pressables
253
+ // fight over the touch responder, producing repeated press animations and a Confirm button that
254
+ // never fires. All native devices (phones and tablets) use the ActionSheet presentation.
255
+ const isMobile = isNative();
251
256
  const sizePx = getModalSize(size);
252
257
 
253
258
  const modalContentProps = {
@@ -1,4 +1,3 @@
1
- // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
2
1
  import {describe, expect, it, mock} from "bun:test";
3
2
  import {forwardRef, useRef} from "react";
4
3
  import {Text, View} from "react-native";
@@ -8,11 +7,13 @@ import {renderWithTheme} from "./test-utils";
8
7
 
9
8
  // Mock react-native-modalize
10
9
  mock.module("react-native-modalize", () => ({
11
- Modalize: forwardRef(({children}: {children: React.ReactNode}, ref) => (
12
- <View ref={ref as any} testID="modalize">
13
- {children}
14
- </View>
15
- )),
10
+ Modalize: forwardRef<React.ElementRef<typeof View>, {children: React.ReactNode}>(
11
+ ({children}, ref) => (
12
+ <View ref={ref} testID="modalize">
13
+ {children}
14
+ </View>
15
+ )
16
+ ),
16
17
  }));
17
18
 
18
19
  describe("ModalSheet", () => {
@@ -3,7 +3,8 @@ import {TouchableOpacity, View} from "react-native";
3
3
 
4
4
  import {CheckBox} from "./CheckBox";
5
5
  import type {MultiselectFieldProps} from "./Common";
6
- import {FieldError, FieldHelperText} from "./fieldElements";
6
+ import {FieldError} from "./fieldElements/FieldError";
7
+ import {FieldHelperText} from "./fieldElements/FieldHelperText";
7
8
  import {Heading} from "./Heading";
8
9
  import {isMobileDevice} from "./MediaQuery";
9
10
  import {Text} from "./Text";
package/src/Page.tsx CHANGED
@@ -12,6 +12,7 @@ import {Spinner} from "./Spinner";
12
12
  import {Text} from "./Text";
13
13
 
14
14
  export class Page extends React.Component<PageProps, {}> {
15
+ // noExplicitAny: ActionSheet class is defined in ActionSheet.tsx which imports from Common.ts indirectly; using its type here would create a circular dependency
15
16
  // biome-ignore lint/suspicious/noExplicitAny: ActionSheet class is defined in ActionSheet.tsx which imports from Common.ts indirectly; using its type here would create a circular dependency
16
17
  actionSheetRef: React.RefObject<any> = React.createRef();
17
18
 
@@ -3,7 +3,7 @@
3
3
  // import Permissions from "react-native-permissions";
4
4
  import type {PermissionKind, PermissionStatus} from "./Common";
5
5
 
6
- export async function requestPermissions(_kind: PermissionKind): Promise<PermissionStatus> {
6
+ export const requestPermissions = async (_kind: PermissionKind): Promise<PermissionStatus> => {
7
7
  return new Promise((_resolve, _reject) => {
8
8
  return "denied";
9
9
  });
@@ -43,4 +43,4 @@ export async function requestPermissions(_kind: PermissionKind): Promise<Permiss
43
43
  // return reject(MAP_RESULTS[response]);
44
44
  // }
45
45
  // });
46
- }
46
+ };
@@ -1,3 +1,4 @@
1
+ // noExplicitAny: test mock typing
1
2
  // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
2
3
  import {describe, expect, it, mock} from "bun:test";
3
4
  import {act, fireEvent} from "@testing-library/react-native";
@@ -1,4 +1,3 @@
1
- // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
2
1
  import {describe, expect, it, mock} from "bun:test";
3
2
  import {act, fireEvent} from "@testing-library/react-native";
4
3
 
@@ -28,7 +27,7 @@ describe("SelectBadge", () => {
28
27
 
29
28
  it("displays placeholder when no value", () => {
30
29
  const {getByText} = renderWithTheme(
31
- <SelectBadge onChange={() => {}} options={defaultOptions} value={undefined as any} />
30
+ <SelectBadge onChange={() => {}} options={defaultOptions} value={undefined} />
32
31
  );
33
32
  expect(getByText("---")).toBeTruthy();
34
33
  });
@@ -2,7 +2,9 @@ import type {FC} from "react";
2
2
  import {View} from "react-native";
3
3
 
4
4
  import type {SelectFieldProps} from "./Common";
5
- import {FieldError, FieldHelperText, FieldTitle} from "./fieldElements";
5
+ import {FieldError} from "./fieldElements/FieldError";
6
+ import {FieldHelperText} from "./fieldElements/FieldHelperText";
7
+ import {FieldTitle} from "./fieldElements/FieldTitle";
6
8
  import {RNPickerSelect} from "./PickerSelect";
7
9
  import {resolveFieldTestIDsFromProps} from "./testing/resolveTestId";
8
10
 
@@ -362,4 +362,56 @@ describe("Signature", () => {
362
362
  expect(mockOnChange).toHaveBeenCalledWith("");
363
363
  expect(ctx.fillRect).toHaveBeenCalled();
364
364
  });
365
+
366
+ it("ignores pointer down when the canvas ref is missing", () => {
367
+ const mockOnChange = mock(() => {});
368
+ const mockOnStart = mock(() => {});
369
+ const {UNSAFE_getByType} = renderWithTheme(
370
+ <Signature onChange={mockOnChange} onStart={mockOnStart} />
371
+ );
372
+ const canvas = UNSAFE_getByType("canvas");
373
+ canvas.props.ref.current = null;
374
+
375
+ act(() => {
376
+ canvas.props.onPointerDown({
377
+ nativeEvent: {offsetX: 10, offsetY: 20},
378
+ pointerId: 1,
379
+ });
380
+ });
381
+
382
+ expect(mockOnStart).not.toHaveBeenCalled();
383
+ });
384
+
385
+ it("falls back to raw offsets when the canvas has no measurable size", () => {
386
+ const mockOnChange = mock(() => {});
387
+ const moveTo = mock(() => {});
388
+ const {UNSAFE_getByType} = renderWithTheme(<Signature onChange={mockOnChange} />);
389
+ const canvas = UNSAFE_getByType("canvas");
390
+ canvas.props.ref.current = {
391
+ clientHeight: 0,
392
+ clientWidth: 0,
393
+ getBoundingClientRect: () => ({height: 0, width: 0}),
394
+ getContext: () => ({
395
+ beginPath: mock(() => {}),
396
+ fillRect: mock(() => {}),
397
+ lineCap: "round",
398
+ lineJoin: "round",
399
+ lineTo: mock(() => {}),
400
+ moveTo,
401
+ stroke: mock(() => {}),
402
+ }),
403
+ height: 0,
404
+ setPointerCapture: mock(() => {}),
405
+ width: 0,
406
+ } as unknown as HTMLCanvasElement;
407
+
408
+ act(() => {
409
+ canvas.props.onPointerDown({
410
+ nativeEvent: {offsetX: 42, offsetY: 24},
411
+ pointerId: 1,
412
+ });
413
+ });
414
+
415
+ expect(moveTo).toHaveBeenCalledWith(42, 24);
416
+ });
365
417
  });
@@ -34,6 +34,7 @@ export const SplitPage = ({
34
34
  const {width} = Dimensions.get("window");
35
35
 
36
36
  const onItemSelect = useCallback(
37
+ // noExplicitAny: SplitPage accepts heterogeneous list item shapes from consumers; the generic propagates from listViewData
37
38
  // biome-ignore lint/suspicious/noExplicitAny: SplitPage accepts heterogeneous list item shapes from consumers; the generic propagates from listViewData
38
39
  async (item: ListRenderItemInfo<any>) => {
39
40
  setSelectedId(item.index);
@@ -59,6 +60,7 @@ export const SplitPage = ({
59
60
  return null;
60
61
  }
61
62
 
63
+ // noExplicitAny: SplitPage accepts heterogeneous list item shapes from consumers; the generic propagates from listViewData
62
64
  // biome-ignore lint/suspicious/noExplicitAny: SplitPage accepts heterogeneous list item shapes from consumers; the generic propagates from listViewData
63
65
  const renderItem = (itemInfo: ListRenderItemInfo<any>) => {
64
66
  return (