@multiplatform.one/components 7.47.3 → 7.47.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multiplatform.one/components",
3
- "version": "7.47.3",
3
+ "version": "7.47.4",
4
4
  "description": "multiplatform.one ui components",
5
5
  "keywords": [
6
6
  "components",
@@ -58,11 +58,11 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "@floating-ui/react": "^0.27.20",
61
- "@multiplatform.one/forms": "^7.47.3",
62
- "@multiplatform.one/i18n": "^7.47.3",
63
- "@multiplatform.one/platform": "^7.47.3",
64
- "@multiplatform.one/router": "^7.47.3",
65
- "@multiplatform.one/theme": "^7.47.3",
61
+ "@multiplatform.one/forms": "^7.47.4",
62
+ "@multiplatform.one/i18n": "^7.47.4",
63
+ "@multiplatform.one/platform": "^7.47.4",
64
+ "@multiplatform.one/router": "^7.47.4",
65
+ "@multiplatform.one/theme": "^7.47.4",
66
66
  "@phosphor-icons/react": "^2.1.10",
67
67
  "@shopify/flash-list": "^2.3.1",
68
68
  "@tamagui/colors": "2.7.6",
@@ -89,9 +89,9 @@
89
89
  "tamagui": "2.7.6"
90
90
  },
91
91
  "devDependencies": {
92
- "@multiplatform.one/config": "7.47.3",
93
- "@multiplatform.one/storybook": "7.47.3",
94
- "@multiplatform.one/test-utils": "7.47.3",
92
+ "@multiplatform.one/config": "7.47.4",
93
+ "@multiplatform.one/storybook": "7.47.4",
94
+ "@multiplatform.one/test-utils": "7.47.4",
95
95
  "@tamagui/build": "2.7.6",
96
96
  "@testing-library/jest-dom": "^7.0.1",
97
97
  "@testing-library/react": "^16.3.3",
@@ -0,0 +1,189 @@
1
+ /**
2
+ * FZ-7858 / FZ-7859, under tamagui's NATIVE build (vitest.native.config.mjs)
3
+ * with the React Native animation driver every MPO app runs on a phone.
4
+ *
5
+ * A press ends the platform way on every MPO pressable: a finger that slides
6
+ * past the press rect (the element's box plus hitSlop plus the retention
7
+ * offset) clears the pressed look and a lift there does not press; sliding
8
+ * back in presses again; a scroll or any other responder terminate clears it.
9
+ * Both halves live in tamagui (patches/@tamagui__web@2.7.6.patch and
10
+ * patches/@tamagui__animations-react-native@2.7.6.patch); this spec pins them
11
+ * on the MPO components, so a tamagui upgrade that drops either fails here.
12
+ */
13
+ import { cleanup, fireEvent, screen } from "@testing-library/react";
14
+ import { renderWithProviders } from "@multiplatform.one/test-utils";
15
+ import { nativeAnimationConfig } from "@multiplatform.one/theme";
16
+ import { createAnimations } from "@tamagui/animations-react-native";
17
+ import { configWithoutAnimations } from "@tamagui/config";
18
+ import type { ReactElement, ReactNode } from "react";
19
+ import { TamaguiProvider, Text, createTamagui, isWeb } from "tamagui";
20
+ import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest";
21
+ import { Accordion } from "./Accordion";
22
+ import { Button } from "./Button";
23
+ import { Chip } from "./Chip";
24
+ import { ListItem } from "./tamagui";
25
+
26
+ const nativeConfig = createTamagui({
27
+ ...configWithoutAnimations,
28
+ animations: createAnimations(nativeAnimationConfig),
29
+ });
30
+
31
+ function Native({ children }: { children: ReactNode }) {
32
+ return (
33
+ <TamaguiProvider config={nativeConfig} defaultTheme="light" disableInjectCSS>
34
+ {children}
35
+ </TamaguiProvider>
36
+ );
37
+ }
38
+
39
+ const mount = (ui: ReactElement) => renderWithProviders(<Native>{ui}</Native>, { tamagui: false });
40
+
41
+ // Every pressable measures 200x40 at the page origin; the retention region is
42
+ // that box plus 20 on the sides and top and 30 below (React Native's default).
43
+ const box = { x: 0, y: 0, left: 0, top: 0, width: 200, height: 40, right: 200, bottom: 40 };
44
+ const inside = { x: 100, y: 20 };
45
+ const beside = { x: 300, y: 20 };
46
+
47
+ const realRect = HTMLElement.prototype.getBoundingClientRect;
48
+ beforeAll(() => {
49
+ HTMLElement.prototype.getBoundingClientRect = () => ({ ...box, toJSON: () => box }) as DOMRect;
50
+ });
51
+ afterAll(() => {
52
+ HTMLElement.prototype.getBoundingClientRect = realRect;
53
+ });
54
+
55
+ const settle = () => new Promise((done) => setTimeout(done, 450));
56
+ type Point = { x: number; y: number };
57
+
58
+ // The responder reads the touch's page position; happy-dom's MouseEvent drops
59
+ // pageX/pageY from its init, so they are set on the event itself.
60
+ function pointer(el: Element, type: string, point: Point, buttons: number) {
61
+ const event = new MouseEvent(type, {
62
+ bubbles: true,
63
+ cancelable: true,
64
+ button: 0,
65
+ buttons,
66
+ clientX: point.x,
67
+ clientY: point.y,
68
+ });
69
+ Object.defineProperty(event, "pageX", { value: point.x });
70
+ Object.defineProperty(event, "pageY", { value: point.y });
71
+ fireEvent(el, event);
72
+ }
73
+
74
+ afterEach(() => {
75
+ // a failed step can leave the finger down; lift it so the next case starts clean
76
+ pointer(document.body, "mouseup", beside, 0);
77
+ cleanup();
78
+ });
79
+ const press = (el: Element) => pointer(el, "mousedown", inside, 1);
80
+ const slide = (el: Element, point: Point) => pointer(el, "mousemove", point, 1);
81
+ const lift = (el: Element, point: Point) => pointer(el, "mouseup", point, 0);
82
+ const terminate = (el: Element) => fireEvent.dragStart(el);
83
+
84
+ // The fills of the label and its nearest ancestors: whichever of them carries
85
+ // the pressStyle, a pressed element reads differently from its rest.
86
+ function look(label: Element) {
87
+ const fills: string[] = [];
88
+ let node = label as HTMLElement | null;
89
+ for (let depth = 0; depth < 5 && node; depth++) {
90
+ fills.push(node.style?.backgroundColor ?? "");
91
+ node = node.parentElement;
92
+ }
93
+ return fills.join("|");
94
+ }
95
+
96
+ interface Case {
97
+ name: string;
98
+ render: (onPress: () => void) => ReactElement;
99
+ label: string;
100
+ }
101
+
102
+ const accordion = (variant: "card" | "plain", open: boolean) => (onPress: () => void) => (
103
+ <Accordion variant={variant} type="multiple" defaultValue={open ? ["a"] : []}>
104
+ <Accordion.Item value="a">
105
+ <Accordion.Trigger onPress={onPress}>Section A</Accordion.Trigger>
106
+ <Accordion.Content>
107
+ <Text>Content A</Text>
108
+ </Accordion.Content>
109
+ </Accordion.Item>
110
+ </Accordion>
111
+ );
112
+
113
+ const pressables: Case[] = [
114
+ {
115
+ name: "an Accordion card trigger (closed)",
116
+ render: accordion("card", false),
117
+ label: "Section A",
118
+ },
119
+ { name: "an Accordion card trigger (open)", render: accordion("card", true), label: "Section A" },
120
+ { name: "an Accordion plain trigger", render: accordion("plain", false), label: "Section A" },
121
+ {
122
+ name: "a ListItem row",
123
+ render: (onPress) => <ListItem onPress={onPress} title="Row A" />,
124
+ label: "Row A",
125
+ },
126
+ { name: "a Button", render: (onPress) => <Button onPress={onPress}>Hold</Button>, label: "Hold" },
127
+ { name: "a Chip", render: (onPress) => <Chip onPress={onPress}>Tag</Chip>, label: "Tag" },
128
+ ];
129
+
130
+ describe("the native harness", () => {
131
+ it("runs tamagui's native build", () => {
132
+ expect(isWeb).toBe(false);
133
+ });
134
+ });
135
+
136
+ describe.each(pressables)("$name on native", ({ render, label: text }) => {
137
+ async function pressed() {
138
+ const onPress = vi.fn();
139
+ mount(render(onPress));
140
+ const label = screen.getByText(text);
141
+ await settle();
142
+ const rest = look(label);
143
+ press(label);
144
+ await settle();
145
+ const down = look(label);
146
+ expect(down).not.toBe(rest);
147
+ return { label, onPress, rest, down };
148
+ }
149
+
150
+ it("clears the pressed look when the finger slides off, and a lift there does not press", async () => {
151
+ const { label, onPress, rest } = await pressed();
152
+ slide(label, beside);
153
+ await settle();
154
+ expect(look(label)).toBe(rest);
155
+ lift(label, beside);
156
+ await settle();
157
+ expect(onPress).not.toHaveBeenCalled();
158
+ expect(look(label)).toBe(rest);
159
+ });
160
+
161
+ it("presses again when the finger slides back in, and a lift there presses", async () => {
162
+ const { label, onPress, rest, down } = await pressed();
163
+ slide(label, beside);
164
+ await settle();
165
+ expect(look(label)).toBe(rest);
166
+ slide(label, inside);
167
+ await settle();
168
+ expect(look(label)).toBe(down);
169
+ lift(label, inside);
170
+ expect(onPress).toHaveBeenCalledTimes(1);
171
+ });
172
+
173
+ it("keeps the press while the finger stays inside the retention offset", async () => {
174
+ const { label, onPress, down } = await pressed();
175
+ slide(label, { x: 215, y: 20 });
176
+ await settle();
177
+ expect(look(label)).toBe(down);
178
+ lift(label, { x: 215, y: 20 });
179
+ expect(onPress).toHaveBeenCalledTimes(1);
180
+ });
181
+
182
+ it("returns to rest when a scroll or another responder terminates the press", async () => {
183
+ const { label, onPress, rest } = await pressed();
184
+ terminate(label);
185
+ await settle();
186
+ expect(look(label)).toBe(rest);
187
+ expect(onPress).not.toHaveBeenCalled();
188
+ });
189
+ });