@multiplatform.one/components 7.41.0 → 7.43.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.
- package/dist/cjs/Alert/index.cjs +2 -1
- package/dist/cjs/Alert/index.native.js +2 -1
- package/dist/cjs/Alert/index.native.js.map +1 -1
- package/dist/cjs/ScrollView/index.native.js +14 -1
- package/dist/cjs/ScrollView/index.native.js.map +1 -1
- package/dist/cjs/ScrollView/revealFocusedField.cjs +36 -0
- package/dist/cjs/ScrollView/revealFocusedField.native.js +39 -0
- package/dist/cjs/ScrollView/revealFocusedField.native.js.map +1 -0
- package/dist/cjs/ScrollView/useRevealFocusedField.cjs +28 -0
- package/dist/cjs/ScrollView/useRevealFocusedField.native.js +75 -0
- package/dist/cjs/ScrollView/useRevealFocusedField.native.js.map +1 -0
- package/dist/cjs/Toast/index.cjs +6 -2
- package/dist/cjs/Toast/index.native.js +6 -2
- package/dist/cjs/Toast/index.native.js.map +1 -1
- package/dist/cjs/appShell/TabBar.cjs +134 -0
- package/dist/cjs/appShell/TabBar.native.js +145 -0
- package/dist/cjs/appShell/TabBar.native.js.map +1 -0
- package/dist/cjs/appShell/index.cjs +1 -0
- package/dist/cjs/appShell/index.native.js +1 -0
- package/dist/cjs/appShell/index.native.js.map +1 -1
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.native.js +2 -0
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/layouts/KeyboardAvoidingWrapper/index.native.js +16 -7
- package/dist/cjs/layouts/KeyboardAvoidingWrapper/index.native.js.map +1 -1
- package/dist/cjs/layouts/page.cjs +9 -4
- package/dist/cjs/layouts/page.native.js +11 -4
- package/dist/cjs/layouts/page.native.js.map +1 -1
- package/dist/cjs/layouts/tags.cjs +5 -2
- package/dist/cjs/layouts/tags.native.js +2 -1
- package/dist/cjs/layouts/tags.native.js.map +1 -1
- package/dist/esm/Alert/index.mjs +2 -1
- package/dist/esm/Alert/index.mjs.map +1 -1
- package/dist/esm/Alert/index.native.js +2 -1
- package/dist/esm/Alert/index.native.js.map +1 -1
- package/dist/esm/ScrollView/index.native.js +16 -3
- package/dist/esm/ScrollView/index.native.js.map +1 -1
- package/dist/esm/ScrollView/revealFocusedField.mjs +11 -0
- package/dist/esm/ScrollView/revealFocusedField.mjs.map +1 -0
- package/dist/esm/ScrollView/revealFocusedField.native.js +11 -0
- package/dist/esm/ScrollView/revealFocusedField.native.js.map +1 -0
- package/dist/esm/ScrollView/useRevealFocusedField.mjs +3 -0
- package/dist/esm/ScrollView/useRevealFocusedField.mjs.map +1 -0
- package/dist/esm/ScrollView/useRevealFocusedField.native.js +47 -0
- package/dist/esm/ScrollView/useRevealFocusedField.native.js.map +1 -0
- package/dist/esm/Toast/index.mjs +6 -2
- package/dist/esm/Toast/index.mjs.map +1 -1
- package/dist/esm/Toast/index.native.js +6 -2
- package/dist/esm/Toast/index.native.js.map +1 -1
- package/dist/esm/appShell/TabBar.mjs +104 -0
- package/dist/esm/appShell/TabBar.mjs.map +1 -0
- package/dist/esm/appShell/TabBar.native.js +112 -0
- package/dist/esm/appShell/TabBar.native.js.map +1 -0
- package/dist/esm/appShell/index.mjs +1 -0
- package/dist/esm/appShell/index.mjs.map +1 -1
- package/dist/esm/appShell/index.native.js +1 -0
- package/dist/esm/appShell/index.native.js.map +1 -1
- package/dist/esm/index.mjs +2 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +2 -1
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/layouts/KeyboardAvoidingWrapper/index.native.js +17 -8
- package/dist/esm/layouts/KeyboardAvoidingWrapper/index.native.js.map +1 -1
- package/dist/esm/layouts/page.mjs +10 -5
- package/dist/esm/layouts/page.mjs.map +1 -1
- package/dist/esm/layouts/page.native.js +12 -5
- package/dist/esm/layouts/page.native.js.map +1 -1
- package/dist/esm/layouts/tags.mjs +5 -2
- package/dist/esm/layouts/tags.mjs.map +1 -1
- package/dist/esm/layouts/tags.native.js +2 -1
- package/dist/esm/layouts/tags.native.js.map +1 -1
- package/dist/jsx/Alert/index.mjs +2 -1
- package/dist/jsx/Alert/index.mjs.map +1 -1
- package/dist/jsx/Alert/index.native.js +2 -1
- package/dist/jsx/Alert/index.native.js.map +1 -1
- package/dist/jsx/ScrollView/index.native.js +14 -1
- package/dist/jsx/ScrollView/index.native.js.map +1 -1
- package/dist/jsx/ScrollView/revealFocusedField.mjs +11 -0
- package/dist/jsx/ScrollView/revealFocusedField.mjs.map +1 -0
- package/dist/jsx/ScrollView/revealFocusedField.native.js +39 -0
- package/dist/jsx/ScrollView/revealFocusedField.native.js.map +1 -0
- package/dist/jsx/ScrollView/useRevealFocusedField.mjs +3 -0
- package/dist/jsx/ScrollView/useRevealFocusedField.mjs.map +1 -0
- package/dist/jsx/ScrollView/useRevealFocusedField.native.js +75 -0
- package/dist/jsx/ScrollView/useRevealFocusedField.native.js.map +1 -0
- package/dist/jsx/Toast/index.mjs +6 -2
- package/dist/jsx/Toast/index.mjs.map +1 -1
- package/dist/jsx/Toast/index.native.js +6 -2
- package/dist/jsx/Toast/index.native.js.map +1 -1
- package/dist/jsx/appShell/TabBar.mjs +104 -0
- package/dist/jsx/appShell/TabBar.mjs.map +1 -0
- package/dist/jsx/appShell/TabBar.native.js +145 -0
- package/dist/jsx/appShell/TabBar.native.js.map +1 -0
- package/dist/jsx/appShell/index.mjs +1 -0
- package/dist/jsx/appShell/index.mjs.map +1 -1
- package/dist/jsx/appShell/index.native.js +1 -0
- package/dist/jsx/appShell/index.native.js.map +1 -1
- package/dist/jsx/index.js +2 -1
- package/dist/jsx/index.js.map +1 -1
- package/dist/jsx/index.mjs +2 -1
- package/dist/jsx/index.mjs.map +1 -1
- package/dist/jsx/index.native.js +2 -0
- package/dist/jsx/index.native.js.map +1 -1
- package/dist/jsx/layouts/KeyboardAvoidingWrapper/index.native.js +16 -7
- package/dist/jsx/layouts/KeyboardAvoidingWrapper/index.native.js.map +1 -1
- package/dist/jsx/layouts/page.mjs +10 -5
- package/dist/jsx/layouts/page.mjs.map +1 -1
- package/dist/jsx/layouts/page.native.js +11 -4
- package/dist/jsx/layouts/page.native.js.map +1 -1
- package/dist/jsx/layouts/tags.mjs +5 -2
- package/dist/jsx/layouts/tags.mjs.map +1 -1
- package/dist/jsx/layouts/tags.native.js +2 -1
- package/dist/jsx/layouts/tags.native.js.map +1 -1
- package/package.json +11 -10
- package/src/Alert/Alert.native-press.spec.tsx +123 -0
- package/src/Alert/index.tsx +6 -1
- package/src/ScrollView/ScrollView.native.spec.tsx +13 -0
- package/src/ScrollView/index.native.tsx +21 -2
- package/src/ScrollView/revealFocusedField.spec.ts +26 -0
- package/src/ScrollView/revealFocusedField.ts +24 -0
- package/src/ScrollView/useRevealFocusedField.native.ts +65 -0
- package/src/ScrollView/useRevealFocusedField.ts +4 -0
- package/src/Toast/index.tsx +6 -2
- package/src/appShell/TabBar.native.spec.tsx +63 -0
- package/src/appShell/TabBar.spec.tsx +185 -0
- package/src/appShell/TabBar.tsx +171 -0
- package/src/appShell/index.ts +1 -0
- package/src/index.ts +3 -1
- package/src/layouts/KeyboardAvoidingWrapper/index.native.tsx +17 -10
- package/src/layouts/page.tsx +16 -5
- package/src/layouts/tags.tsx +4 -1
- package/types/Alert/index.d.ts.map +1 -1
- package/types/ScrollView/index.native.d.ts.map +1 -1
- package/types/ScrollView/revealFocusedField.d.ts +15 -0
- package/types/ScrollView/revealFocusedField.d.ts.map +1 -0
- package/types/ScrollView/useRevealFocusedField.d.ts +4 -0
- package/types/ScrollView/useRevealFocusedField.d.ts.map +1 -0
- package/types/ScrollView/useRevealFocusedField.native.d.ts +12 -0
- package/types/ScrollView/useRevealFocusedField.native.d.ts.map +1 -0
- package/types/Toast/index.d.ts.map +1 -1
- package/types/appShell/TabBar.d.ts +36 -0
- package/types/appShell/TabBar.d.ts.map +1 -0
- package/types/appShell/index.d.ts +1 -0
- package/types/appShell/index.d.ts.map +1 -1
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
- package/types/layouts/KeyboardAvoidingWrapper/index.native.d.ts +2 -0
- package/types/layouts/KeyboardAvoidingWrapper/index.native.d.ts.map +1 -1
- package/types/layouts/page.d.ts +7 -1
- package/types/layouts/page.d.ts.map +1 -1
- package/types/layouts/tags.d.ts.map +1 -1
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FZ-7792, under tamagui's NATIVE build (vitest.native.config.mjs): press
|
|
3
|
+
* events run through the responder system, which hands a touch to the deepest
|
|
4
|
+
* view whose onStartShouldSetResponder says yes. A pressStyle-only pill inside
|
|
5
|
+
* the action said yes, so Alert's actionLabel/onAction never fired on a
|
|
6
|
+
* simulator while every web spec passed (a DOM click bubbles to the target).
|
|
7
|
+
*/
|
|
8
|
+
import { cleanup, fireEvent, screen } from "@testing-library/react";
|
|
9
|
+
import { renderWithProviders } from "@multiplatform.one/test-utils";
|
|
10
|
+
import type { ReactElement } from "react";
|
|
11
|
+
import { SizableText, View, isWeb, styled } from "tamagui";
|
|
12
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
13
|
+
import { Alert } from "./index";
|
|
14
|
+
|
|
15
|
+
afterEach(cleanup);
|
|
16
|
+
|
|
17
|
+
const press = (el: Element) => fireEvent.mouseDown(el, { button: 0, buttons: 1 });
|
|
18
|
+
const release = (el: Element) => fireEvent.mouseUp(el, { button: 0, buttons: 0 });
|
|
19
|
+
const tap = (el: Element) => {
|
|
20
|
+
press(el);
|
|
21
|
+
release(el);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const mount = (ui: ReactElement) => renderWithProviders(ui);
|
|
25
|
+
|
|
26
|
+
describe("the native harness", () => {
|
|
27
|
+
const Claimant = styled(View, { name: "ProbeClaimant", pressStyle: { opacity: 0.5 } });
|
|
28
|
+
|
|
29
|
+
it("runs tamagui's native build", () => {
|
|
30
|
+
expect(isWeb).toBe(false);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// The control: if this stops failing the old way, the harness no longer
|
|
34
|
+
// models the native responder and every pass below proves nothing.
|
|
35
|
+
it("reproduces the bug class: a pressStyle-only child takes the parent's tap", () => {
|
|
36
|
+
const onPress = vi.fn();
|
|
37
|
+
mount(
|
|
38
|
+
<View onPress={onPress}>
|
|
39
|
+
<Claimant>
|
|
40
|
+
<SizableText>inside</SizableText>
|
|
41
|
+
</Claimant>
|
|
42
|
+
</View>,
|
|
43
|
+
);
|
|
44
|
+
tap(screen.getByText("inside"));
|
|
45
|
+
expect(onPress).not.toHaveBeenCalled();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("lets the parent own a tap that lands on a plain child", () => {
|
|
49
|
+
const onPress = vi.fn();
|
|
50
|
+
mount(
|
|
51
|
+
<View onPress={onPress}>
|
|
52
|
+
<View>
|
|
53
|
+
<SizableText>inside</SizableText>
|
|
54
|
+
</View>
|
|
55
|
+
</View>,
|
|
56
|
+
);
|
|
57
|
+
tap(screen.getByText("inside"));
|
|
58
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe("Alert convenience actions on native", () => {
|
|
63
|
+
it("runs onAction and onSecondaryAction when their labels are tapped (stacked)", () => {
|
|
64
|
+
const onAction = vi.fn();
|
|
65
|
+
const onSecondaryAction = vi.fn();
|
|
66
|
+
mount(
|
|
67
|
+
<Alert
|
|
68
|
+
intent="warning"
|
|
69
|
+
title="Order changed"
|
|
70
|
+
actionLabel="Save order"
|
|
71
|
+
onAction={onAction}
|
|
72
|
+
secondaryActionLabel="Discard"
|
|
73
|
+
onSecondaryAction={onSecondaryAction}
|
|
74
|
+
>
|
|
75
|
+
Two environments moved.
|
|
76
|
+
</Alert>,
|
|
77
|
+
);
|
|
78
|
+
tap(screen.getByText("Save order"));
|
|
79
|
+
expect(onAction).toHaveBeenCalledTimes(1);
|
|
80
|
+
expect(onSecondaryAction).not.toHaveBeenCalled();
|
|
81
|
+
tap(screen.getByText("Discard"));
|
|
82
|
+
expect(onSecondaryAction).toHaveBeenCalledTimes(1);
|
|
83
|
+
expect(onAction).toHaveBeenCalledTimes(1);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("runs onAction for an inline action beside the dismiss X", () => {
|
|
87
|
+
const onAction = vi.fn();
|
|
88
|
+
const onDismiss = vi.fn();
|
|
89
|
+
mount(
|
|
90
|
+
<Alert actionLabel="Retry" onAction={onAction} dismissible onDismiss={onDismiss}>
|
|
91
|
+
Sync failed.
|
|
92
|
+
</Alert>,
|
|
93
|
+
);
|
|
94
|
+
tap(screen.getByText("Retry"));
|
|
95
|
+
expect(onAction).toHaveBeenCalledTimes(1);
|
|
96
|
+
expect(onDismiss).not.toHaveBeenCalled();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("still paints the pill's press colour while the target holds the touch", () => {
|
|
100
|
+
mount(<Alert actionLabel="Retry" onAction={() => {}} />);
|
|
101
|
+
const label = screen.getByText("Retry");
|
|
102
|
+
const pill = label.parentElement as HTMLElement;
|
|
103
|
+
const idle = pill.style.backgroundColor;
|
|
104
|
+
press(label);
|
|
105
|
+
const pressed = pill.style.backgroundColor;
|
|
106
|
+
release(label);
|
|
107
|
+
expect(pressed).not.toBe("");
|
|
108
|
+
expect(pressed).not.toBe(idle);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("runs onDismiss when the X glyph itself is tapped", () => {
|
|
112
|
+
const onDismiss = vi.fn();
|
|
113
|
+
const { container } = mount(
|
|
114
|
+
<Alert icon={null} dismissible onDismiss={onDismiss}>
|
|
115
|
+
Saved.
|
|
116
|
+
</Alert>,
|
|
117
|
+
);
|
|
118
|
+
const glyphs = container.querySelectorAll("svg");
|
|
119
|
+
expect(glyphs).toHaveLength(1);
|
|
120
|
+
tap(glyphs[0]);
|
|
121
|
+
expect(onDismiss).toHaveBeenCalledTimes(1);
|
|
122
|
+
});
|
|
123
|
+
});
|
package/src/Alert/index.tsx
CHANGED
|
@@ -174,6 +174,10 @@ const AlertActionTarget = styled(View, {
|
|
|
174
174
|
focusVisibleStyle: { opacity: 1, outlineWidth: 0 },
|
|
175
175
|
});
|
|
176
176
|
|
|
177
|
+
// FZ-7792: the press colour rides the target's group state, never the pill's
|
|
178
|
+
// own pressStyle. On native without RNGH a pressStyle view claims the
|
|
179
|
+
// responder, and RN hands the touch to the deepest claimant, so the pill
|
|
180
|
+
// took every tap and the target's onPress never ran.
|
|
177
181
|
const AlertActionPill = styled(View, {
|
|
178
182
|
name: "AlertActionPill",
|
|
179
183
|
paddingHorizontal: "$2",
|
|
@@ -181,7 +185,7 @@ const AlertActionPill = styled(View, {
|
|
|
181
185
|
alignItems: "center",
|
|
182
186
|
justifyContent: "center",
|
|
183
187
|
hoverStyle: { backgroundColor: "$color5" },
|
|
184
|
-
|
|
188
|
+
"$group-alertAction-press": { backgroundColor: "$color6" },
|
|
185
189
|
});
|
|
186
190
|
|
|
187
191
|
const activateOnEnterSpace = (onPress?: () => void) =>
|
|
@@ -238,6 +242,7 @@ function AlertAction({
|
|
|
238
242
|
const hOutset = besideAdjacent ? Math.min(outset, DISMISS_ADJACENT_OUTSET) : outset;
|
|
239
243
|
return (
|
|
240
244
|
<AlertActionTarget
|
|
245
|
+
group={"alertAction" as unknown as undefined}
|
|
241
246
|
className="mp-chip-dismiss"
|
|
242
247
|
aria-label={label}
|
|
243
248
|
{...pressTargetStyle()}
|
|
@@ -86,6 +86,18 @@ describe("tamagui native ScrollView (upstream control)", () => {
|
|
|
86
86
|
});
|
|
87
87
|
|
|
88
88
|
describe("components ScrollView keyboard taps on native (MPO-457)", () => {
|
|
89
|
+
it("dismisses the iOS keyboard interactively while dragging", () => {
|
|
90
|
+
const host = render(createElement(ScrollView as unknown as AnyScrollView, {}));
|
|
91
|
+
expect(host.keyboardDismissMode).toBe("interactive");
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("preserves an explicit keyboard dismissal policy", () => {
|
|
95
|
+
const host = render(
|
|
96
|
+
createElement(ScrollView as unknown as AnyScrollView, { keyboardDismissMode: "none" }),
|
|
97
|
+
);
|
|
98
|
+
expect(host.keyboardDismissMode).toBe("none");
|
|
99
|
+
});
|
|
100
|
+
|
|
89
101
|
it("hands keyboardShouldPersistTaps=handled to the RN ScrollView by default", () => {
|
|
90
102
|
const host = render(createElement(ScrollView as unknown as AnyScrollView, { testID: "probe" }));
|
|
91
103
|
expect(host.keyboardShouldPersistTaps).toBe("handled");
|
|
@@ -127,6 +139,7 @@ describe("components ScrollView on native", () => {
|
|
|
127
139
|
horizontal: true,
|
|
128
140
|
contentContainerStyle: { paddingVertical: 4 },
|
|
129
141
|
keyboardShouldPersistTaps: "handled",
|
|
142
|
+
keyboardDismissMode: "interactive",
|
|
130
143
|
};
|
|
131
144
|
const raw = { ...render(createElement(runtime.RawScrollView as AnyScrollView, shared)) };
|
|
132
145
|
act(() => root.unmount());
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { forwardRef } from "react";
|
|
1
|
+
import { forwardRef, useCallback, useRef, type Ref } from "react";
|
|
2
2
|
import {
|
|
3
|
+
Platform,
|
|
3
4
|
ScrollView as RNScrollView,
|
|
4
5
|
type ScrollViewProps as RNScrollViewProps,
|
|
5
6
|
} from "react-native";
|
|
6
7
|
import { styled, type ScrollView as TamaguiScrollView } from "tamagui";
|
|
8
|
+
import { useRevealFocusedField } from "./useRevealFocusedField";
|
|
7
9
|
|
|
8
10
|
export type { ScrollViewProps } from "tamagui";
|
|
9
11
|
|
|
@@ -18,10 +20,24 @@ type ScrollHandler = RNScrollViewProps["onScroll"];
|
|
|
18
20
|
|
|
19
21
|
const ScrollHost = forwardRef<RNScrollView, RNScrollViewProps & { scrollHandler?: ScrollHandler }>(
|
|
20
22
|
function ScrollHost({ scrollHandler, ...props }, ref) {
|
|
21
|
-
|
|
23
|
+
const local = useRef<RNScrollView | null>(null);
|
|
24
|
+
const setRef = useCallback(
|
|
25
|
+
(node: RNScrollView | null) => {
|
|
26
|
+
local.current = node;
|
|
27
|
+
assignRef(ref, node);
|
|
28
|
+
},
|
|
29
|
+
[ref],
|
|
30
|
+
);
|
|
31
|
+
useRevealFocusedField(local, !props.horizontal);
|
|
32
|
+
return <RNScrollView ref={setRef} {...props} onScroll={scrollHandler} />;
|
|
22
33
|
},
|
|
23
34
|
);
|
|
24
35
|
|
|
36
|
+
function assignRef<T>(ref: Ref<T> | undefined, value: T | null) {
|
|
37
|
+
if (typeof ref === "function") ref(value);
|
|
38
|
+
else if (ref) (ref as { current: T | null }).current = value;
|
|
39
|
+
}
|
|
40
|
+
|
|
25
41
|
const ScrollFrame = styled(
|
|
26
42
|
ScrollHost,
|
|
27
43
|
{
|
|
@@ -31,6 +47,9 @@ const ScrollFrame = styled(
|
|
|
31
47
|
// first tap on any descendant while the keyboard is up, and a native
|
|
32
48
|
// sheet's rows are React descendants of the screen that opened it.
|
|
33
49
|
keyboardShouldPersistTaps: "handled",
|
|
50
|
+
// FZ-7718: dragging the content down pulls the keyboard closed with the
|
|
51
|
+
// finger on iOS. Android has no interactive mode, so a drag dismisses it.
|
|
52
|
+
keyboardDismissMode: Platform.OS === "ios" ? "interactive" : "on-drag",
|
|
34
53
|
variants: {
|
|
35
54
|
fullscreen: {
|
|
36
55
|
true: { position: "absolute", inset: 0 },
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { revealOffset } from "./revealFocusedField";
|
|
3
|
+
|
|
4
|
+
const viewport = { offset: 100, height: 300 };
|
|
5
|
+
|
|
6
|
+
describe("revealOffset (FZ-7718)", () => {
|
|
7
|
+
it("leaves a field that is already in view", () => {
|
|
8
|
+
expect(revealOffset({ top: 150, bottom: 190 }, viewport, 16)).toBeUndefined();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("scrolls down until a field below the fold clears it by the margin", () => {
|
|
12
|
+
expect(revealOffset({ top: 420, bottom: 460 }, viewport, 16)).toBe(176);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("scrolls up to a field above the viewport", () => {
|
|
16
|
+
expect(revealOffset({ top: 40, bottom: 80 }, viewport, 16)).toBe(24);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("keeps the top of a field taller than the viewport in view", () => {
|
|
20
|
+
expect(revealOffset({ top: 500, bottom: 1000 }, viewport, 16)).toBe(484);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("never scrolls past the top", () => {
|
|
24
|
+
expect(revealOffset({ top: 4, bottom: 44 }, viewport, 16)).toBe(0);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface Span {
|
|
2
|
+
top: number;
|
|
3
|
+
bottom: number;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface Viewport {
|
|
7
|
+
offset: number;
|
|
8
|
+
height: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The scroll offset that brings a focused field into view with `margin` to
|
|
13
|
+
* spare, or undefined when it is already in view. A field taller than the
|
|
14
|
+
* viewport keeps its top edge visible.
|
|
15
|
+
*/
|
|
16
|
+
export function revealOffset(field: Span, viewport: Viewport, margin: number): number | undefined {
|
|
17
|
+
const top = field.top - margin;
|
|
18
|
+
const bottom = field.bottom + margin;
|
|
19
|
+
if (top < viewport.offset) return Math.max(0, top);
|
|
20
|
+
if (bottom > viewport.offset + viewport.height) {
|
|
21
|
+
return Math.max(0, Math.min(top, bottom - viewport.height));
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { type RefObject, useEffect } from "react";
|
|
2
|
+
import { Keyboard, TextInput, type ScrollView } from "react-native";
|
|
3
|
+
import { getTokenValue } from "tamagui";
|
|
4
|
+
import { revealOffset } from "./revealFocusedField";
|
|
5
|
+
|
|
6
|
+
type Measured = (x: number, y: number, width: number, height: number) => void;
|
|
7
|
+
|
|
8
|
+
interface HostNode {
|
|
9
|
+
measureInWindow: (done: Measured) => void;
|
|
10
|
+
measureLayout: (relativeTo: HostNode, done: Measured, fail?: () => void) => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface ScrollInstance {
|
|
14
|
+
getInnerViewRef?: () => HostNode | null;
|
|
15
|
+
getNativeScrollRef?: () => HostNode | null;
|
|
16
|
+
scrollTo: (options: { y: number; animated: boolean }) => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* FZ-7718: once the keyboard is up, scroll the focused field into the part of
|
|
21
|
+
* this ScrollView that is still visible. iOS posts keyboardDidShow again each
|
|
22
|
+
* time focus moves to another field, so Return-to-next lands here too. The
|
|
23
|
+
* native automaticallyAdjustKeyboardInsets only measures against the
|
|
24
|
+
* keyboard's top edge, which misses a field hidden behind a panel the page
|
|
25
|
+
* keeps above the keyboard.
|
|
26
|
+
*/
|
|
27
|
+
export function useRevealFocusedField(ref: RefObject<ScrollView | null>, enabled: boolean) {
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!enabled) return;
|
|
30
|
+
let frame = 0;
|
|
31
|
+
const subscription = Keyboard.addListener("keyboardDidShow", () => {
|
|
32
|
+
cancelAnimationFrame(frame);
|
|
33
|
+
frame = requestAnimationFrame(() => reveal(ref.current as unknown as ScrollInstance | null));
|
|
34
|
+
});
|
|
35
|
+
return () => {
|
|
36
|
+
cancelAnimationFrame(frame);
|
|
37
|
+
subscription.remove();
|
|
38
|
+
};
|
|
39
|
+
}, [enabled, ref]);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function reveal(scroll: ScrollInstance | null) {
|
|
43
|
+
const input = TextInput.State.currentlyFocusedInput?.() as unknown as HostNode | null;
|
|
44
|
+
const inner = scroll?.getInnerViewRef?.();
|
|
45
|
+
const frame = scroll?.getNativeScrollRef?.();
|
|
46
|
+
if (!scroll || !input || !inner || !frame) return;
|
|
47
|
+
const margin = Number(getTokenValue("$4" as Parameters<typeof getTokenValue>[0], "space")) || 0;
|
|
48
|
+
// A field outside this ScrollView fails measureLayout and is left alone.
|
|
49
|
+
input.measureLayout(
|
|
50
|
+
inner,
|
|
51
|
+
(_x, top, _width, height) => {
|
|
52
|
+
frame.measureInWindow((_fx, frameY, _fw, frameHeight) => {
|
|
53
|
+
inner.measureInWindow((_ix, innerY) => {
|
|
54
|
+
const y = revealOffset(
|
|
55
|
+
{ top, bottom: top + height },
|
|
56
|
+
{ offset: frameY - innerY, height: frameHeight },
|
|
57
|
+
margin,
|
|
58
|
+
);
|
|
59
|
+
if (y !== undefined) scroll.scrollTo({ y, animated: true });
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
() => {},
|
|
64
|
+
);
|
|
65
|
+
}
|
package/src/Toast/index.tsx
CHANGED
|
@@ -305,7 +305,7 @@ const ToastActionPill = styled(View, {
|
|
|
305
305
|
alignItems: "center",
|
|
306
306
|
justifyContent: "center",
|
|
307
307
|
hoverStyle: { backgroundColor: "$color4" },
|
|
308
|
-
|
|
308
|
+
"$group-toastAction-press": { backgroundColor: "$color5" },
|
|
309
309
|
});
|
|
310
310
|
|
|
311
311
|
const ToastCloseTarget = styled(View, {
|
|
@@ -337,7 +337,7 @@ const ToastCloseRing = styled(View, {
|
|
|
337
337
|
// button's ≤44px box and survives the style compiler.
|
|
338
338
|
borderRadius: "$12",
|
|
339
339
|
hoverStyle: { backgroundColor: "$color4" },
|
|
340
|
-
|
|
340
|
+
"$group-toastClose-press": { backgroundColor: "$color5" },
|
|
341
341
|
});
|
|
342
342
|
|
|
343
343
|
// ── Intent wrap ───────────────────────────────────────────────
|
|
@@ -610,6 +610,7 @@ function ToastInner({
|
|
|
610
610
|
/>
|
|
611
611
|
{action && (
|
|
612
612
|
<ToastActionTarget
|
|
613
|
+
group={"toastAction" as unknown as undefined}
|
|
613
614
|
{...nativeToastControlA11y()}
|
|
614
615
|
className="mp-chip-dismiss"
|
|
615
616
|
{...toastActionPressProps(nestedPx)}
|
|
@@ -632,6 +633,7 @@ function ToastInner({
|
|
|
632
633
|
)}
|
|
633
634
|
{showClose && (
|
|
634
635
|
<ToastCloseTarget
|
|
636
|
+
group={"toastClose" as unknown as undefined}
|
|
635
637
|
{...nativeToastControlA11y()}
|
|
636
638
|
className="mp-chip-dismiss"
|
|
637
639
|
aria-label={t("Dismiss notification")}
|
|
@@ -733,6 +735,7 @@ function ToastItemInner({ entry, isTop }: ToastItemProps) {
|
|
|
733
735
|
{entry.action && (
|
|
734
736
|
<TamaguiToast.Action altText={entry.action.altText ?? entry.action.label} asChild>
|
|
735
737
|
<ToastActionTarget
|
|
738
|
+
group={"toastAction" as unknown as undefined}
|
|
736
739
|
{...nativeToastControlA11y()}
|
|
737
740
|
className="mp-chip-dismiss"
|
|
738
741
|
{...toastActionPressProps(nestedPx)}
|
|
@@ -758,6 +761,7 @@ function ToastItemInner({ entry, isTop }: ToastItemProps) {
|
|
|
758
761
|
{entry.dismissible && (
|
|
759
762
|
<TamaguiToast.Close asChild>
|
|
760
763
|
<ToastCloseTarget
|
|
764
|
+
group={"toastClose" as unknown as undefined}
|
|
761
765
|
{...nativeToastControlA11y()}
|
|
762
766
|
className="mp-chip-dismiss"
|
|
763
767
|
aria-label={t("Dismiss notification")}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LC-150 TAB-BAR-ANATOMY, NATIVE arm: the label is one line that shrinks at
|
|
3
|
+
* most to the minimum caption step, clips rather than ellipsizes, and keeps
|
|
4
|
+
* its size under Dynamic Type (UITabBar parity). The house Text is replaced
|
|
5
|
+
* by a recorder so the props the bar hands the native text node are read
|
|
6
|
+
* directly; this is not device-render evidence.
|
|
7
|
+
*/
|
|
8
|
+
import { NATIVE_TYPE_SHAPE } from "@multiplatform.one/theme";
|
|
9
|
+
import { renderWithProviders } from "@multiplatform.one/test-utils";
|
|
10
|
+
import { cleanup } from "@testing-library/react";
|
|
11
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
12
|
+
import { TabBar, tabBarLabelMinSize, tabBarLabelSize } from "./TabBar";
|
|
13
|
+
|
|
14
|
+
vi.mock("@multiplatform.one/platform", async (importOriginal) => ({
|
|
15
|
+
...(await importOriginal<typeof import("@multiplatform.one/platform")>()),
|
|
16
|
+
isWeb: false,
|
|
17
|
+
isNative: true,
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
const textProps: Record<string, unknown>[] = [];
|
|
21
|
+
vi.mock("../Text", () => ({
|
|
22
|
+
Text: (props: Record<string, unknown>) => {
|
|
23
|
+
textProps.push(props);
|
|
24
|
+
return <span>{props.children as string}</span>;
|
|
25
|
+
},
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
cleanup();
|
|
30
|
+
textProps.length = 0;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const Glyph = () => null;
|
|
34
|
+
|
|
35
|
+
describe("TabBar native label (LC-150)", () => {
|
|
36
|
+
it("is one line on the caption step, shrinking at most one step, clipped, unscaled", () => {
|
|
37
|
+
renderWithProviders(
|
|
38
|
+
<TabBar
|
|
39
|
+
items={[
|
|
40
|
+
{ key: "home", label: "Home", icon: Glyph },
|
|
41
|
+
{ key: "backoffice", label: "Backoffice", icon: Glyph },
|
|
42
|
+
]}
|
|
43
|
+
activeKey="home"
|
|
44
|
+
/>,
|
|
45
|
+
);
|
|
46
|
+
expect(textProps).toHaveLength(2);
|
|
47
|
+
const floor =
|
|
48
|
+
NATIVE_TYPE_SHAPE[tabBarLabelMinSize.slice(1) as "1"] /
|
|
49
|
+
NATIVE_TYPE_SHAPE[tabBarLabelSize.slice(1) as "2"];
|
|
50
|
+
for (const props of textProps) {
|
|
51
|
+
expect(props).toMatchObject({
|
|
52
|
+
fontSize: tabBarLabelSize,
|
|
53
|
+
lineHeight: tabBarLabelSize,
|
|
54
|
+
numberOfLines: 1,
|
|
55
|
+
ellipsizeMode: "clip",
|
|
56
|
+
adjustsFontSizeToFit: true,
|
|
57
|
+
minimumFontScale: floor,
|
|
58
|
+
allowFontScaling: false,
|
|
59
|
+
});
|
|
60
|
+
expect(props.minimumFontScale).toBeLessThan(1);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LC-150 TAB-BAR-ANATOMY (FZ-7754). The bar owns every item's icon box, label
|
|
3
|
+
* step and ink; an app passes an icon component and a label only. Icons are
|
|
4
|
+
* probes that record what the bar handed them, so the anatomy is asserted on
|
|
5
|
+
* the values the bar decides, never on hashed classes.
|
|
6
|
+
*/
|
|
7
|
+
import { renderWithProviders } from "@multiplatform.one/test-utils";
|
|
8
|
+
import {
|
|
9
|
+
Preset,
|
|
10
|
+
getActiveScaleTokens,
|
|
11
|
+
normalizeToHex,
|
|
12
|
+
useGlyphColor,
|
|
13
|
+
useIdentityInkOnSurface,
|
|
14
|
+
} from "@multiplatform.one/theme";
|
|
15
|
+
import { cleanup, fireEvent, screen } from "@testing-library/react";
|
|
16
|
+
import fs from "node:fs";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
import type { ReactElement } from "react";
|
|
19
|
+
import { Theme } from "tamagui";
|
|
20
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
21
|
+
import {
|
|
22
|
+
TabBar,
|
|
23
|
+
type TabBarIcon,
|
|
24
|
+
type TabBarItem,
|
|
25
|
+
tabBarIconBox,
|
|
26
|
+
tabBarInactiveInk,
|
|
27
|
+
tabBarLabelSize,
|
|
28
|
+
tabBarRowHeight,
|
|
29
|
+
} from "./TabBar";
|
|
30
|
+
|
|
31
|
+
afterEach(cleanup);
|
|
32
|
+
|
|
33
|
+
function rgbOf(color: string): [number, number, number] {
|
|
34
|
+
const hex = normalizeToHex(color) ?? "#000000";
|
|
35
|
+
return [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16)) as [number, number, number];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Orange: red leads, blue trails, and the step is clearly chromatic. */
|
|
39
|
+
function isOrange(color: string): boolean {
|
|
40
|
+
const [r, g, b] = rgbOf(color);
|
|
41
|
+
return r > g && g > b && r - b > 80;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type GlyphProps = { size?: number; color?: string; weight?: string };
|
|
45
|
+
|
|
46
|
+
function probeItems(seen: Record<string, GlyphProps>): TabBarItem[] {
|
|
47
|
+
const probe =
|
|
48
|
+
(key: string): TabBarIcon =>
|
|
49
|
+
(props) => {
|
|
50
|
+
seen[key] = props;
|
|
51
|
+
return null;
|
|
52
|
+
};
|
|
53
|
+
return [
|
|
54
|
+
{ key: "/", label: "Home", icon: probe("/") },
|
|
55
|
+
{ key: "/pokemon", label: "Pokemon", icon: probe("/pokemon") },
|
|
56
|
+
{ key: "/moves", label: "Moves", icon: probe("/moves") },
|
|
57
|
+
{ key: "/backoffice", label: "Backoffice", icon: probe("/backoffice") },
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const expected: { accent?: string; secondary?: string; primary?: string } = {};
|
|
62
|
+
function InkProbe() {
|
|
63
|
+
expected.accent = useIdentityInkOnSurface();
|
|
64
|
+
expected.secondary = useGlyphColor(tabBarInactiveInk);
|
|
65
|
+
expected.primary = useGlyphColor("$color");
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type Scheme = "light" | "dark";
|
|
70
|
+
function inScheme(scheme: Scheme, node: ReactElement): ReactElement {
|
|
71
|
+
return scheme === "dark" ? <Theme name="dark">{node}</Theme> : node;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function renderBar(scheme: Scheme, activeKey: string, preset?: "default" | "bold") {
|
|
75
|
+
const seen: Record<string, GlyphProps> = {};
|
|
76
|
+
const tree = (
|
|
77
|
+
<>
|
|
78
|
+
<InkProbe />
|
|
79
|
+
<TabBar items={probeItems(seen)} activeKey={activeKey} />
|
|
80
|
+
</>
|
|
81
|
+
);
|
|
82
|
+
renderWithProviders(
|
|
83
|
+
inScheme(
|
|
84
|
+
scheme,
|
|
85
|
+
preset ? (
|
|
86
|
+
<Preset preset={preset} theme="orange">
|
|
87
|
+
{tree}
|
|
88
|
+
</Preset>
|
|
89
|
+
) : (
|
|
90
|
+
tree
|
|
91
|
+
),
|
|
92
|
+
),
|
|
93
|
+
);
|
|
94
|
+
return seen;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
describe("TabBar (LC-150 TAB-BAR-ANATOMY)", () => {
|
|
98
|
+
it("is a named tab list with one equal tab per item, the active one selected", () => {
|
|
99
|
+
renderBar("light", "/moves");
|
|
100
|
+
const list = screen.getByRole("tablist", { name: "Tabs" });
|
|
101
|
+
const tabs = screen.getAllByRole("tab");
|
|
102
|
+
expect(tabs).toHaveLength(4);
|
|
103
|
+
for (const tab of tabs) expect(list.contains(tab)).toBe(true);
|
|
104
|
+
expect(tabs.map((tab) => tab.getAttribute("aria-selected"))).toEqual([
|
|
105
|
+
"false",
|
|
106
|
+
"false",
|
|
107
|
+
"true",
|
|
108
|
+
"false",
|
|
109
|
+
]);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("calls onTabPress with the pressed item's key", () => {
|
|
113
|
+
const onTabPress = vi.fn();
|
|
114
|
+
renderWithProviders(<TabBar items={probeItems({})} activeKey="/" onTabPress={onTabPress} />);
|
|
115
|
+
fireEvent.click(screen.getByRole("tab", { name: "Backoffice" }));
|
|
116
|
+
expect(onTabPress).toHaveBeenCalledWith("/backoffice");
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
for (const scheme of ["light", "dark"] as const) {
|
|
120
|
+
for (const preset of ["default", "bold"] as const) {
|
|
121
|
+
const cell = `${scheme}, ${preset}, orange`;
|
|
122
|
+
|
|
123
|
+
it(`${cell}: every icon gets the same box, sized from the scale token`, () => {
|
|
124
|
+
const seen = renderBar(scheme, "/", preset);
|
|
125
|
+
const sizes = new Set(Object.values(seen).map((props) => props.size));
|
|
126
|
+
expect(sizes).toEqual(new Set([getActiveScaleTokens().size[tabBarIconBox]]));
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it(`${cell}: active is the accent, inactive the secondary ink, never the accent`, () => {
|
|
130
|
+
const seen = renderBar(scheme, "/", preset);
|
|
131
|
+
expect(expected.accent).toBeTruthy();
|
|
132
|
+
expect(expected.secondary).toBeTruthy();
|
|
133
|
+
expect(expected.accent).not.toBe(expected.secondary);
|
|
134
|
+
// Both presets set textAccent "high"; the inactive tab still reads
|
|
135
|
+
// quieter than body text.
|
|
136
|
+
expect(expected.secondary).not.toBe(expected.primary);
|
|
137
|
+
// Clay's iPhone: the orange theme's active tab must read orange.
|
|
138
|
+
expect(isOrange(expected.accent as string)).toBe(true);
|
|
139
|
+
expect(seen["/"]).toMatchObject({ color: expected.accent, weight: "fill" });
|
|
140
|
+
for (const key of ["/pokemon", "/moves", "/backoffice"]) {
|
|
141
|
+
expect(seen[key]).toMatchObject({ color: expected.secondary, weight: "regular" });
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
it(`${scheme}, no hue: the active tab is the primary ink, never quieter than inactive`, () => {
|
|
147
|
+
const seen = renderBar(scheme, "/");
|
|
148
|
+
expect(expected.accent).toBe(expected.primary);
|
|
149
|
+
expect(seen["/"]).toMatchObject({ color: expected.primary, weight: "fill" });
|
|
150
|
+
expect(seen["/moves"]).toMatchObject({ color: expected.secondary, weight: "regular" });
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
it("labels keep the whole word and share one caption step", () => {
|
|
155
|
+
renderBar("light", "/");
|
|
156
|
+
const labels = ["Home", "Pokemon", "Moves", "Backoffice"].map((label) =>
|
|
157
|
+
screen.getByTestId(`tab-bar-item-${label === "Home" ? "root" : label.toLowerCase()}-label`),
|
|
158
|
+
);
|
|
159
|
+
expect(labels.map((label) => label.textContent)).toEqual([
|
|
160
|
+
"Home",
|
|
161
|
+
"Pokemon",
|
|
162
|
+
"Moves",
|
|
163
|
+
"Backoffice",
|
|
164
|
+
]);
|
|
165
|
+
const sizeAtoms = (el: Element) =>
|
|
166
|
+
String((el as HTMLElement).className)
|
|
167
|
+
.split(" ")
|
|
168
|
+
.filter((c) => c.startsWith("_fos-") || c.startsWith("_lh-"))
|
|
169
|
+
.sort()
|
|
170
|
+
.join(" ");
|
|
171
|
+
expect(sizeAtoms(labels[0])).not.toBe("");
|
|
172
|
+
expect(new Set(labels.map(sizeAtoms)).size).toBe(1);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("pins the anatomy to tokens and builds on no Button, so fillStyle never paints a tab", () => {
|
|
176
|
+
expect(tabBarLabelSize).toBe("$2");
|
|
177
|
+
expect(tabBarIconBox).toMatch(/^\$/);
|
|
178
|
+
expect(tabBarRowHeight).toMatch(/^\$/);
|
|
179
|
+
const source = fs.readFileSync(path.resolve(__dirname, "TabBar.tsx"), "utf-8");
|
|
180
|
+
expect(source).not.toMatch(/\bButton\b/);
|
|
181
|
+
expect(source).toMatch(/edges=\{\["bottom"\]\}/);
|
|
182
|
+
expect(source).toMatch(/\{\.\.\.hairline\.top\}/);
|
|
183
|
+
expect(source).toMatch(/overflow="hidden"/);
|
|
184
|
+
});
|
|
185
|
+
});
|