@marktiderman/genesis-ui-native 3.5.0 → 3.6.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/README.md +71 -7
- package/dist/{chunk-LBVD7XXL.js → chunk-2Z72MYHB.js} +627 -20
- package/dist/chunk-2Z72MYHB.js.map +1 -0
- package/dist/chunk-4OQOJ2OC.js +80 -0
- package/dist/chunk-4OQOJ2OC.js.map +1 -0
- package/dist/{chunk-6KWEAGRD.js → chunk-6PGLX6ET.js} +101 -6
- package/dist/chunk-6PGLX6ET.js.map +1 -0
- package/dist/{chunk-ONH2PCGH.js → chunk-AGTBABAH.js} +9 -15
- package/dist/chunk-AGTBABAH.js.map +1 -0
- package/dist/{chunk-ABVSSJNT.js → chunk-FUMSL7VZ.js} +198 -168
- package/dist/chunk-FUMSL7VZ.js.map +1 -0
- package/dist/{chunk-GHYUNNNU.js → chunk-NDXNSSM6.js} +175 -93
- package/dist/chunk-NDXNSSM6.js.map +1 -0
- package/dist/chunk-SEJ6RBP7.js +361 -0
- package/dist/chunk-SEJ6RBP7.js.map +1 -0
- package/dist/{chunk-D5RKSPMH.js → chunk-ZRQAFFTN.js} +4 -3
- package/dist/chunk-ZRQAFFTN.js.map +1 -0
- package/dist/components/index.d.ts +331 -4
- package/dist/components/index.js +5 -5
- package/dist/data/index.d.ts +68 -4
- package/dist/data/index.js +235 -31
- package/dist/data/index.js.map +1 -1
- package/dist/hooks/index.d.ts +60 -1
- package/dist/hooks/index.js +2 -3
- package/dist/icons/lucide.d.ts +1 -1
- package/dist/icons/lucide.js +7 -1
- package/dist/icons/lucide.js.map +1 -1
- package/dist/{inbox-page-BEarNEIP.d.ts → inbox-page-B7_Oi2fS.d.ts} +2 -44
- package/dist/index.d.ts +8 -5
- package/dist/index.js +8 -8
- package/dist/layouts/index.d.ts +40 -51
- package/dist/layouts/index.js +5 -4
- package/dist/{native-modules-PwnGltOU.d.ts → native-modules-Cl3zw3kh.d.ts} +27 -1
- package/package.json +78 -4
- package/src/__tests__/doctor-rules.test.ts +60 -0
- package/src/__tests__/native-modules-lists.test.tsx +1 -0
- package/src/components/__tests__/composer-bar.test.tsx +55 -0
- package/src/components/__tests__/gallery-card.test.tsx +59 -0
- package/src/components/__tests__/gallery-grid.test.tsx +160 -0
- package/src/components/__tests__/lightbox-resnap.test.tsx +50 -0
- package/src/components/__tests__/lightbox-zoom.test.ts +33 -0
- package/src/components/__tests__/lightbox.test.tsx +141 -0
- package/src/components/__tests__/live-indicator.test.tsx +72 -0
- package/src/components/__tests__/rating.test.tsx +82 -0
- package/src/components/__tests__/thread-list.test.tsx +156 -0
- package/src/components/composer-bar.tsx +198 -0
- package/src/components/drawer.tsx +15 -9
- package/src/components/gallery-card.tsx +109 -0
- package/src/components/gallery-grid.tsx +285 -0
- package/src/components/gallery-layout.ts +2 -0
- package/src/components/gallery-types.ts +2 -0
- package/src/components/index.ts +44 -0
- package/src/components/lightbox-zoom.tsx +282 -0
- package/src/components/lightbox.tsx +342 -0
- package/src/components/live-indicator.tsx +139 -0
- package/src/components/rating.tsx +128 -0
- package/src/components/skeleton.tsx +9 -4
- package/src/components/thread-list.tsx +427 -0
- package/src/components/toast.tsx +7 -4
- package/src/data/NativeConflictSheet.tsx +181 -0
- package/src/data/NativeResourceForm.tsx +15 -1
- package/src/data/index.ts +2 -0
- package/src/data/resource-view/NativeLinkPicker.tsx +1 -1
- package/src/data/resource-view/NativeRecordView.tsx +85 -8
- package/src/data/resource-view/NativeResourceView.tsx +79 -32
- package/src/data/resource-view/__tests__/native-link-picker.test.tsx +16 -0
- package/src/data/resource-view/__tests__/native-record-view.test.tsx +95 -1
- package/src/data/resource-view/__tests__/native-resource-gallery.test.tsx +125 -0
- package/src/data/resource-view/mapping.ts +3 -0
- package/src/hooks/__tests__/use-motion.test.tsx +106 -0
- package/src/hooks/__tests__/use-thread-jump.test.tsx +88 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/use-motion.ts +128 -0
- package/src/hooks/use-thread-jump.ts +110 -0
- package/src/icon-names.ts +6 -0
- package/src/icons/lucide.ts +12 -0
- package/src/layouts/__tests__/inbox-page.test.tsx +6 -0
- package/src/layouts/__tests__/thread-page.test.tsx +114 -14
- package/src/layouts/inbox-page.tsx +6 -55
- package/src/layouts/index.ts +2 -0
- package/src/layouts/thread-page.tsx +326 -262
- package/src/native-modules.tsx +16 -2
- package/dist/chunk-6KWEAGRD.js.map +0 -1
- package/dist/chunk-7PCWEY6R.js +0 -27
- package/dist/chunk-7PCWEY6R.js.map +0 -1
- package/dist/chunk-ABVSSJNT.js.map +0 -1
- package/dist/chunk-D5RKSPMH.js.map +0 -1
- package/dist/chunk-GHYUNNNU.js.map +0 -1
- package/dist/chunk-LBVD7XXL.js.map +0 -1
- package/dist/chunk-ONH2PCGH.js.map +0 -1
- package/dist/chunk-Z3AQYVUA.js +0 -36
- package/dist/chunk-Z3AQYVUA.js.map +0 -1
|
@@ -266,6 +266,9 @@ function heldTo(link: ResolvedLink, keys: readonly (string | number)[] | undefin
|
|
|
266
266
|
get labelField() {
|
|
267
267
|
return link.labelField;
|
|
268
268
|
},
|
|
269
|
+
get orderBy() {
|
|
270
|
+
return link.orderBy;
|
|
271
|
+
},
|
|
269
272
|
...(link.searchFields ? { searchFields: link.searchFields } : {}),
|
|
270
273
|
filters: (scope?: Parameters<ResolvedLink["filters"]>[0], values?: Parameters<ResolvedLink["filters"]>[1]) => [...link.filters(scope, values), held],
|
|
271
274
|
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { act, renderHook, waitFor } from "@testing-library/react";
|
|
3
|
+
import { AccessibilityInfo } from "react-native";
|
|
4
|
+
import { MOTION_DURATIONS, MOTION_SPRINGS, resolveMotion } from "@marktiderman/genesis-design-system/tokens/motion";
|
|
5
|
+
import { animateMotion, motionSpring, motionTiming, useMotion } from "../use-motion";
|
|
6
|
+
import { __resetReducedMotion } from "../use-reduced-motion";
|
|
7
|
+
import { fakeReanimated } from "../../__tests__/fake-modules";
|
|
8
|
+
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
vi.restoreAllMocks();
|
|
11
|
+
__resetReducedMotion();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
describe("useMotion", () => {
|
|
15
|
+
it("gives the shared tokens at calm by default, once the OS has answered", async () => {
|
|
16
|
+
const asked = vi.spyOn(AccessibilityInfo, "isReduceMotionEnabled").mockResolvedValue(false);
|
|
17
|
+
const { result } = renderHook(() => useMotion());
|
|
18
|
+
await waitFor(() => expect(asked).toHaveBeenCalled());
|
|
19
|
+
await act(async () => {});
|
|
20
|
+
expect(result.current.level).toBe("calm");
|
|
21
|
+
expect(result.current.reduced).toBe(false);
|
|
22
|
+
expect(result.current.duration).toEqual(MOTION_DURATIONS);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("holds still when the OS asks for reduced motion", async () => {
|
|
26
|
+
vi.spyOn(AccessibilityInfo, "isReduceMotionEnabled").mockResolvedValue(true);
|
|
27
|
+
const { result } = renderHook(() => useMotion({ level: "bold" }));
|
|
28
|
+
await waitFor(() => expect(result.current.reduced).toBe(true));
|
|
29
|
+
expect(result.current.duration.ui).toBe(0);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("holds still at level none", () => {
|
|
33
|
+
vi.spyOn(AccessibilityInfo, "isReduceMotionEnabled").mockResolvedValue(false);
|
|
34
|
+
const { result } = renderHook(() => useMotion({ level: "none" }));
|
|
35
|
+
expect(result.current.reduced).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe("animateMotion", () => {
|
|
40
|
+
it("springs with the named spring and the gesture's velocity", () => {
|
|
41
|
+
const R = { ...fakeReanimated(), withSpring: vi.fn((to: number) => to) };
|
|
42
|
+
animateMotion(R, resolveMotion("calm"), 0, { spring: "snappy", velocity: 800 });
|
|
43
|
+
expect(R.withSpring).toHaveBeenCalledWith(0, { ...MOTION_SPRINGS.snappy, velocity: 800 });
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("times with the named duration and the token's curve", () => {
|
|
47
|
+
const bezier = vi.fn(() => "curve");
|
|
48
|
+
const fake = fakeReanimated();
|
|
49
|
+
const R = { ...fake, Easing: { ...fake.Easing, bezier } };
|
|
50
|
+
animateMotion(R, resolveMotion("calm"), 1, { duration: "fast", easing: "decelerate" });
|
|
51
|
+
expect(bezier).toHaveBeenCalledWith(0.33, 1, 0.68, 1);
|
|
52
|
+
expect(R.withTiming).toHaveBeenCalledWith(1, { duration: MOTION_DURATIONS.fast, easing: "curve" });
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("falls back to timing at base when the module has no withSpring", () => {
|
|
56
|
+
const R = fakeReanimated();
|
|
57
|
+
animateMotion(R, resolveMotion("calm"), 0, { spring: "smooth" });
|
|
58
|
+
expect(R.withTiming).toHaveBeenCalledWith(0, expect.objectContaining({ duration: MOTION_DURATIONS.base }));
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("returns the final value, without animating, under reduced motion", () => {
|
|
62
|
+
const R = { ...fakeReanimated(), withSpring: vi.fn((to: number) => to) };
|
|
63
|
+
expect(animateMotion(R, resolveMotion("calm", { reducedMotion: true }), 42, { spring: "bouncy" })).toBe(42);
|
|
64
|
+
expect(R.withSpring).not.toHaveBeenCalled();
|
|
65
|
+
expect(R.withTiming).not.toHaveBeenCalled();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("leaves velocity out when the gesture gave none", () => {
|
|
69
|
+
const R = { ...fakeReanimated(), withSpring: vi.fn((to: number) => to) };
|
|
70
|
+
animateMotion(R, resolveMotion("calm"), 0, { spring: "smooth" });
|
|
71
|
+
expect((R.withSpring.mock.calls[0] as unknown[] | undefined)?.[1]).not.toHaveProperty("velocity");
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe("worklet-safe configs", () => {
|
|
76
|
+
it("are marked as worklets, so Reanimated's Babel plugin moves them to the UI thread", () => {
|
|
77
|
+
// The directive must survive in the shipped source (ui-native's react-native entry is ./src).
|
|
78
|
+
for (const fn of [motionSpring, motionTiming]) expect(fn.toString()).toMatch(/["']worklet["']/);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("builds a spring config, with velocity only when given", () => {
|
|
82
|
+
const m = resolveMotion("calm");
|
|
83
|
+
expect(motionSpring(m, "snappy")).toEqual(MOTION_SPRINGS.snappy);
|
|
84
|
+
expect(motionSpring(m, "snappy", -300)).toEqual({ ...MOTION_SPRINGS.snappy, velocity: -300 });
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("settles at once, without the gesture's velocity, under reduced motion", () => {
|
|
88
|
+
const still = motionSpring(resolveMotion("calm", { reducedMotion: true }), "bouncy", 900);
|
|
89
|
+
expect(still).not.toHaveProperty("velocity");
|
|
90
|
+
// Critically damped (no overshoot) and far stiffer than any named spring.
|
|
91
|
+
expect(still.damping).toBeGreaterThanOrEqual(2 * Math.sqrt(still.stiffness * still.mass));
|
|
92
|
+
expect(still.stiffness).toBeGreaterThan(MOTION_SPRINGS.snappy.stiffness * 10);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("builds a timing config with the token's curve", () => {
|
|
96
|
+
const m = resolveMotion("calm");
|
|
97
|
+
const bezier = vi.fn(() => "curve");
|
|
98
|
+
expect(motionTiming(m, "ui", { bezier }, "inOut")).toEqual({ duration: MOTION_DURATIONS.ui, easing: "curve" });
|
|
99
|
+
expect(bezier).toHaveBeenCalledWith(0.65, 0, 0.35, 1);
|
|
100
|
+
expect(motionTiming(m, "ui", undefined)).toEqual({ duration: MOTION_DURATIONS.ui });
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("zeroes durations under reduced motion", () => {
|
|
104
|
+
expect(motionTiming(resolveMotion("none"), "ui", undefined)).toEqual({ duration: 0 });
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// @feat:inbox-thread
|
|
2
|
+
import { act, renderHook } from "@testing-library/react";
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { JUMP_SETTLE_MS, useThreadJump } from "../use-thread-jump";
|
|
5
|
+
|
|
6
|
+
beforeEach(() => vi.useFakeTimers());
|
|
7
|
+
afterEach(() => vi.useRealTimers());
|
|
8
|
+
|
|
9
|
+
const setup = (initial: { target: string | null; ids: string[]; loading?: boolean; loadUntil?: (id: string) => Promise<boolean> }) => {
|
|
10
|
+
const scrollTo = vi.fn();
|
|
11
|
+
const onGone = vi.fn();
|
|
12
|
+
const onLanded = vi.fn();
|
|
13
|
+
const hook = renderHook(
|
|
14
|
+
(p: typeof initial) => useThreadJump({ target: p.target, has: (id) => p.ids.includes(id), loading: p.loading, loadUntil: p.loadUntil, scrollTo, onGone, onLanded }),
|
|
15
|
+
{ initialProps: initial },
|
|
16
|
+
);
|
|
17
|
+
return { ...hook, scrollTo, onGone, onLanded };
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
describe("useThreadJump", () => {
|
|
21
|
+
it("goes to a held row and highlights it for two seconds", () => {
|
|
22
|
+
const { result, scrollTo, onLanded } = setup({ target: "b", ids: ["a", "b"] });
|
|
23
|
+
expect(scrollTo).toHaveBeenCalledWith("b");
|
|
24
|
+
expect(onLanded).toHaveBeenCalledWith("b");
|
|
25
|
+
expect(result.current.highlightedId).toBe("b");
|
|
26
|
+
act(() => vi.advanceTimersByTime(2000));
|
|
27
|
+
expect(result.current.highlightedId).toBeNull();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("waits for the first page before deciding", () => {
|
|
31
|
+
const { rerender, scrollTo, onGone } = setup({ target: "b", ids: [], loading: true });
|
|
32
|
+
act(() => vi.advanceTimersByTime(1000));
|
|
33
|
+
expect(onGone).not.toHaveBeenCalled();
|
|
34
|
+
rerender({ target: "b", ids: ["a", "b"], loading: false });
|
|
35
|
+
expect(scrollTo).toHaveBeenCalledWith("b");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("finds a row that arrives a moment after loadUntil resolves", async () => {
|
|
39
|
+
const loadUntil = vi.fn(async () => true);
|
|
40
|
+
const { rerender, scrollTo, onGone } = setup({ target: "old", ids: ["a"], loadUntil });
|
|
41
|
+
await act(async () => {});
|
|
42
|
+
expect(loadUntil).toHaveBeenCalledWith("old");
|
|
43
|
+
act(() => vi.advanceTimersByTime(JUMP_SETTLE_MS / 2));
|
|
44
|
+
rerender({ target: "old", ids: ["old", "a"], loadUntil });
|
|
45
|
+
expect(scrollTo).toHaveBeenCalledWith("old");
|
|
46
|
+
act(() => vi.advanceTimersByTime(JUMP_SETTLE_MS));
|
|
47
|
+
expect(onGone).not.toHaveBeenCalled();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("says a row is gone once the rows have had their moment", async () => {
|
|
51
|
+
const loadUntil = vi.fn(async () => false);
|
|
52
|
+
const { scrollTo, onGone } = setup({ target: "gone", ids: ["a"], loadUntil });
|
|
53
|
+
await act(async () => {});
|
|
54
|
+
act(() => vi.advanceTimersByTime(JUMP_SETTLE_MS));
|
|
55
|
+
expect(onGone).toHaveBeenCalledWith("gone");
|
|
56
|
+
expect(scrollTo).not.toHaveBeenCalled();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("goes again to the same row after the target was cleared", () => {
|
|
60
|
+
const { rerender, scrollTo } = setup({ target: "b", ids: ["a", "b"] });
|
|
61
|
+
rerender({ target: null, ids: ["a", "b"] });
|
|
62
|
+
rerender({ target: "b", ids: ["a", "b"] });
|
|
63
|
+
expect(scrollTo).toHaveBeenCalledTimes(2);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("cancels a jump in progress when the target becomes null", async () => {
|
|
67
|
+
let resolve: (v: boolean) => void = () => {};
|
|
68
|
+
const loadUntil = vi.fn(() => new Promise<boolean>((r) => (resolve = r)));
|
|
69
|
+
const { result, rerender, onGone } = setup({ target: "old", ids: ["a"], loadUntil });
|
|
70
|
+
expect(result.current.jumping).toBe(true);
|
|
71
|
+
rerender({ target: null, ids: ["a"], loadUntil });
|
|
72
|
+
expect(result.current.jumping).toBe(false);
|
|
73
|
+
await act(async () => resolve(false));
|
|
74
|
+
act(() => vi.advanceTimersByTime(JUMP_SETTLE_MS * 2));
|
|
75
|
+
expect(onGone).not.toHaveBeenCalled();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("gives up on time in a busy thread, whatever rows keep arriving", async () => {
|
|
79
|
+
const loadUntil = vi.fn(async () => false);
|
|
80
|
+
const { rerender, onGone } = setup({ target: "old", ids: ["a"], loadUntil });
|
|
81
|
+
await act(async () => {});
|
|
82
|
+
for (let i = 0; i < 5; i++) {
|
|
83
|
+
act(() => vi.advanceTimersByTime(JUMP_SETTLE_MS / 4));
|
|
84
|
+
rerender({ target: "old", ids: ["a", `n${i}`], loadUntil });
|
|
85
|
+
}
|
|
86
|
+
expect(onGone).toHaveBeenCalledWith("old");
|
|
87
|
+
});
|
|
88
|
+
});
|
package/src/hooks/index.ts
CHANGED
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
export { useReducedMotion } from "./use-reduced-motion";
|
|
10
|
+
// The jump is the shared conversation contract's (genesis-core), re-exported here.
|
|
11
|
+
export { useThreadJump, JUMP_SETTLE_MS, type UseThreadJumpOptions } from "@marktiderman/genesis-core/conversation";
|
|
12
|
+
export { useMotion, animateMotion, motionSpring, motionTiming, type UseMotionOptions, type MotionHow, type MotionSpringConfig, type MotionTimingConfig } from "./use-motion";
|
|
10
13
|
export { useThemeMode, type ThemeMode } from "./use-theme-mode";
|
|
11
14
|
export { useThemeRoles, type ThemeRoleColors, type UseThemeRolesOptions } from "./use-theme-roles";
|
|
12
15
|
export {
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useMotion — the shared motion tokens (genesis-design-system's
|
|
3
|
+
* `resolveMotion`), with the OS's reduce-motion setting applied.
|
|
4
|
+
*
|
|
5
|
+
* Every Genesis primitive that moves reads its durations, easings and springs
|
|
6
|
+
* from here instead of its own constants, so motion is defined once for web
|
|
7
|
+
* and native. Under Reduce Motion every duration is 0 and `animateMotion`
|
|
8
|
+
* returns the final value, so a component lands without moving.
|
|
9
|
+
*
|
|
10
|
+
* The brand's motion level isn't read from a provider yet: pass `level` (a
|
|
11
|
+
* brand whose design system chose `none` passes `"none"`). Without it,
|
|
12
|
+
* `calm`.
|
|
13
|
+
*
|
|
14
|
+
* On the JS thread (an effect, a PanResponder), `animateMotion`:
|
|
15
|
+
*
|
|
16
|
+
* ```tsx
|
|
17
|
+
* const motion = useMotion();
|
|
18
|
+
* const { reanimated: R } = useGenesisModules();
|
|
19
|
+
* opacity.value = animateMotion(R, motion, 1, { duration: "fast", easing: "decelerate" });
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Inside a worklet (a gesture's `onEnd`, an animated scroll handler), build
|
|
23
|
+
* the config with the worklet-safe `motionSpring` / `motionTiming` and call
|
|
24
|
+
* Reanimated yourself:
|
|
25
|
+
*
|
|
26
|
+
* ```tsx
|
|
27
|
+
* .onEnd((e) => { x.value = withSpring(0, motionSpring(motion, "snappy", e.velocityX)); })
|
|
28
|
+
* opacity.value = withTiming(1, motionTiming(motion, "fast", Easing, "decelerate"));
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* A repeating animation checks `motion.reduced` first: a zero-length repeat
|
|
32
|
+
* would flash every frame.
|
|
33
|
+
*
|
|
34
|
+
* @stability Beta
|
|
35
|
+
*/
|
|
36
|
+
import { useMemo } from "react";
|
|
37
|
+
import {
|
|
38
|
+
resolveMotion,
|
|
39
|
+
type MotionDurations,
|
|
40
|
+
type MotionEasings,
|
|
41
|
+
type MotionLevel,
|
|
42
|
+
type MotionSprings,
|
|
43
|
+
type MotionTokens,
|
|
44
|
+
} from "@marktiderman/genesis-design-system/tokens/motion";
|
|
45
|
+
import type { GenesisReanimatedModule } from "../native-modules";
|
|
46
|
+
import { useReducedMotion } from "./use-reduced-motion";
|
|
47
|
+
|
|
48
|
+
export interface UseMotionOptions {
|
|
49
|
+
/** The brand's motion level. Default `calm`; `none` holds everything still, like Reduce Motion. */
|
|
50
|
+
level?: MotionLevel;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function useMotion(options: UseMotionOptions = {}): MotionTokens {
|
|
54
|
+
const reducedMotion = useReducedMotion();
|
|
55
|
+
const level = options.level ?? "calm";
|
|
56
|
+
return useMemo(() => resolveMotion(level, { reducedMotion }), [level, reducedMotion]);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** How to get there: a named spring (keeps a gesture's velocity), or a named duration and easing. */
|
|
60
|
+
export type MotionHow =
|
|
61
|
+
| { spring: keyof MotionSprings; velocity?: number; duration?: never; easing?: never }
|
|
62
|
+
| { duration: keyof MotionDurations; easing?: keyof MotionEasings; spring?: never; velocity?: never };
|
|
63
|
+
|
|
64
|
+
/** What `motionSpring` gives `withSpring`. */
|
|
65
|
+
export interface MotionSpringConfig {
|
|
66
|
+
damping: number;
|
|
67
|
+
stiffness: number;
|
|
68
|
+
mass: number;
|
|
69
|
+
velocity?: number;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** What `motionTiming` gives `withTiming`. */
|
|
73
|
+
export interface MotionTimingConfig {
|
|
74
|
+
duration: number;
|
|
75
|
+
easing?: unknown;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* A `withSpring` config from a named spring. Worklet-safe (plain data in,
|
|
80
|
+
* plain data out). Under reduced motion it's the stiff, critically damped
|
|
81
|
+
* spring that settles in a few frames; to not move at all, check
|
|
82
|
+
* `motion.reduced` and assign the value.
|
|
83
|
+
*/
|
|
84
|
+
export function motionSpring(motion: MotionTokens, name: keyof MotionSprings, velocity?: number): MotionSpringConfig {
|
|
85
|
+
"worklet";
|
|
86
|
+
const s = motion.spring[name];
|
|
87
|
+
return typeof velocity === "number" && !motion.reduced
|
|
88
|
+
? { damping: s.damping, stiffness: s.stiffness, mass: s.mass, velocity }
|
|
89
|
+
: { damping: s.damping, stiffness: s.stiffness, mass: s.mass };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* A `withTiming` config from a named duration and easing. Pass Reanimated's
|
|
94
|
+
* `Easing` (`R.Easing`, or `Easing` imported in a worklet) so the token's
|
|
95
|
+
* curve is used; a module without `Easing.bezier` gets Reanimated's default
|
|
96
|
+
* curve. Worklet-safe.
|
|
97
|
+
*/
|
|
98
|
+
export function motionTiming(
|
|
99
|
+
motion: MotionTokens,
|
|
100
|
+
duration: keyof MotionDurations,
|
|
101
|
+
Easing: Pick<GenesisReanimatedModule["Easing"], "bezier"> | undefined,
|
|
102
|
+
easing: keyof MotionEasings = "out",
|
|
103
|
+
): MotionTimingConfig {
|
|
104
|
+
"worklet";
|
|
105
|
+
const [x1, y1, x2, y2] = motion.easing[easing];
|
|
106
|
+
const curve = Easing?.bezier ? Easing.bezier(x1, y1, x2, y2) : undefined;
|
|
107
|
+
return curve === undefined ? { duration: motion.duration[duration] } : { duration: motion.duration[duration], easing: curve };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* A Reanimated animation to `toValue` with the motion tokens, for a shared
|
|
112
|
+
* value on the JS thread: `x.value = animateMotion(R, motion, 0, { spring: "smooth" })`.
|
|
113
|
+
* Under reduced motion it returns `toValue` itself, so nothing moves.
|
|
114
|
+
*
|
|
115
|
+
* It takes no completion callback: Reanimated runs one on the UI thread, so
|
|
116
|
+
* it must be a worklet, and the reduced path couldn't keep that promise. To
|
|
117
|
+
* act when an animation ends, call `withSpring` / `withTiming` yourself with
|
|
118
|
+
* `motionSpring` / `motionTiming` and a worklet callback. A module without
|
|
119
|
+
* `withSpring` (an older one, a test fake) gets a `withTiming` at `base`.
|
|
120
|
+
*/
|
|
121
|
+
export function animateMotion(R: GenesisReanimatedModule, motion: MotionTokens, toValue: number, how: MotionHow): number {
|
|
122
|
+
if (motion.reduced) return toValue;
|
|
123
|
+
if (how.spring !== undefined) {
|
|
124
|
+
if (R.withSpring) return R.withSpring(toValue, motionSpring(motion, how.spring, how.velocity));
|
|
125
|
+
return R.withTiming(toValue, motionTiming(motion, "base", R.Easing));
|
|
126
|
+
}
|
|
127
|
+
return R.withTiming(toValue, motionTiming(motion, how.duration, R.Easing, how.easing));
|
|
128
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useThreadJump — going to one row of a thread (a search result, a pinned
|
|
3
|
+
* message, the first unread): load earlier pages until the row is held, then
|
|
4
|
+
* scroll to it and highlight it for two seconds. A row that can't be found
|
|
5
|
+
* says so.
|
|
6
|
+
*
|
|
7
|
+
* Promoted from genesis-chat's `useJumpToMessage` (G4), generalised from
|
|
8
|
+
* chat's sequence numbers to row ids. It's a state machine driven by the
|
|
9
|
+
* rows, not a one-shot: a target set before the first page has loaded waits
|
|
10
|
+
* for `loading` to end, a row that arrives a render or two after `loadUntil`
|
|
11
|
+
* resolves is still found, and going to the same id again (after `null`)
|
|
12
|
+
* goes again.
|
|
13
|
+
*
|
|
14
|
+
* @stability Beta
|
|
15
|
+
*/
|
|
16
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
17
|
+
|
|
18
|
+
export interface UseThreadJumpOptions {
|
|
19
|
+
/** The row to go to; `null` clears it, and a new id (or the same one after `null`) starts again. */
|
|
20
|
+
target: string | null | undefined;
|
|
21
|
+
/** Whether the row is held now. */
|
|
22
|
+
has: (id: string) => boolean;
|
|
23
|
+
/** The first page is still loading: don't start until it's in. */
|
|
24
|
+
loading?: boolean;
|
|
25
|
+
/** Load earlier pages until the row is held; resolve false when it can't be. Without it, a row not held is gone. */
|
|
26
|
+
loadUntil?: (id: string) => Promise<boolean>;
|
|
27
|
+
/** Scroll to the row. */
|
|
28
|
+
scrollTo: (id: string) => void;
|
|
29
|
+
/** Before loading or scrolling (stop following the bottom). */
|
|
30
|
+
onStart?: () => void;
|
|
31
|
+
/** Scrolled to it (say so to VoiceOver). */
|
|
32
|
+
onLanded?: (id: string) => void;
|
|
33
|
+
/** It isn't there (go back to where the thread was). */
|
|
34
|
+
onGone?: (id: string) => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type Pending = { id: string; phase: "new" | "loading" | "loaded" };
|
|
38
|
+
|
|
39
|
+
/** After `loadUntil` resolves, how long the rows have to arrive before the row counts as gone. */
|
|
40
|
+
export const JUMP_SETTLE_MS = 400;
|
|
41
|
+
|
|
42
|
+
export function useThreadJump({ target, has, loading = false, loadUntil, scrollTo, onStart, onLanded, onGone }: UseThreadJumpOptions) {
|
|
43
|
+
const [pending, setPending] = useState<Pending | null>(target ? { id: target, phase: "new" } : null);
|
|
44
|
+
const [highlightedId, setHighlightedId] = useState<string | null>(null);
|
|
45
|
+
const armed = useRef<Pending | null>(null);
|
|
46
|
+
const goneTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (target) setPending({ id: target, phase: "new" });
|
|
49
|
+
else {
|
|
50
|
+
// null cancels a jump in progress.
|
|
51
|
+
if (goneTimerRef.current) clearTimeout(goneTimerRef.current);
|
|
52
|
+
armed.current = null;
|
|
53
|
+
setPending(null);
|
|
54
|
+
}
|
|
55
|
+
}, [target]);
|
|
56
|
+
|
|
57
|
+
const latest = useRef({ scrollTo, onStart, onLanded, onGone, loadUntil });
|
|
58
|
+
latest.current = { scrollTo, onStart, onLanded, onGone, loadUntil };
|
|
59
|
+
const highlightTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
60
|
+
const goneTimer = goneTimerRef;
|
|
61
|
+
useEffect(
|
|
62
|
+
() => () => {
|
|
63
|
+
if (highlightTimer.current) clearTimeout(highlightTimer.current);
|
|
64
|
+
if (goneTimer.current) clearTimeout(goneTimer.current);
|
|
65
|
+
},
|
|
66
|
+
[],
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const go = useCallback((id: string) => {
|
|
70
|
+
latest.current.onStart?.();
|
|
71
|
+
latest.current.scrollTo(id);
|
|
72
|
+
latest.current.onLanded?.(id);
|
|
73
|
+
setHighlightedId(id);
|
|
74
|
+
if (highlightTimer.current) clearTimeout(highlightTimer.current);
|
|
75
|
+
highlightTimer.current = setTimeout(() => setHighlightedId((h) => (h === id ? null : h)), 2000);
|
|
76
|
+
}, []);
|
|
77
|
+
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (!pending || loading) return;
|
|
80
|
+
const { id, phase } = pending;
|
|
81
|
+
if (has(id)) {
|
|
82
|
+
if (goneTimer.current) clearTimeout(goneTimer.current);
|
|
83
|
+
setPending(null);
|
|
84
|
+
go(id);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (phase === "loading") return;
|
|
88
|
+
if (phase === "loaded" || !latest.current.loadUntil) {
|
|
89
|
+
// The rows may reach the list a render or two after the load resolved: give them a moment,
|
|
90
|
+
// once per pending jump (new rows arriving in a busy thread don't restart it).
|
|
91
|
+
if (armed.current === pending) return;
|
|
92
|
+
armed.current = pending;
|
|
93
|
+
if (goneTimer.current) clearTimeout(goneTimer.current);
|
|
94
|
+
goneTimer.current = setTimeout(
|
|
95
|
+
() => {
|
|
96
|
+
setPending((p) => (p && p.id === id ? null : p));
|
|
97
|
+
latest.current.onGone?.(id);
|
|
98
|
+
},
|
|
99
|
+
phase === "loaded" ? JUMP_SETTLE_MS : 0,
|
|
100
|
+
);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
latest.current.onStart?.();
|
|
104
|
+
setPending({ id, phase: "loading" });
|
|
105
|
+
const settle = () => setPending((p) => (p && p.id === id ? { ...p, phase: "loaded" } : p));
|
|
106
|
+
void latest.current.loadUntil(id).then(settle, settle);
|
|
107
|
+
}, [pending, loading, has, go]);
|
|
108
|
+
|
|
109
|
+
return { highlightedId, jumping: pending !== null };
|
|
110
|
+
}
|
package/src/icon-names.ts
CHANGED
|
@@ -9,11 +9,13 @@
|
|
|
9
9
|
export const SF_SYMBOLS = {
|
|
10
10
|
"arrow-left": "arrow.left",
|
|
11
11
|
"arrow-up": "arrow.up",
|
|
12
|
+
aperture: "camera.aperture",
|
|
12
13
|
bell: "bell",
|
|
13
14
|
calendar: "calendar",
|
|
14
15
|
camera: "camera",
|
|
15
16
|
"camera-flip": "arrow.triangle.2.circlepath.camera",
|
|
16
17
|
check: "checkmark",
|
|
18
|
+
clapperboard: "movieclapper",
|
|
17
19
|
"chevron-down": "chevron.down",
|
|
18
20
|
"chevron-left": "chevron.left",
|
|
19
21
|
"chevron-right": "chevron.right",
|
|
@@ -29,6 +31,7 @@ export const SF_SYMBOLS = {
|
|
|
29
31
|
"external-link": "arrow.up.right.square",
|
|
30
32
|
file: "doc",
|
|
31
33
|
filter: "line.3.horizontal.decrease",
|
|
34
|
+
"folder-plus": "folder.badge.plus",
|
|
32
35
|
heart: "heart",
|
|
33
36
|
home: "house",
|
|
34
37
|
image: "photo",
|
|
@@ -36,6 +39,7 @@ export const SF_SYMBOLS = {
|
|
|
36
39
|
lock: "lock",
|
|
37
40
|
"log-out": "rectangle.portrait.and.arrow.right",
|
|
38
41
|
mail: "envelope",
|
|
42
|
+
maximize: "arrow.up.left.and.arrow.down.right",
|
|
39
43
|
menu: "line.3.horizontal",
|
|
40
44
|
message: "bubble.left",
|
|
41
45
|
mic: "mic",
|
|
@@ -46,10 +50,12 @@ export const SF_SYMBOLS = {
|
|
|
46
50
|
pin: "pin",
|
|
47
51
|
play: "play.fill",
|
|
48
52
|
plus: "plus",
|
|
53
|
+
radio: "dot.radiowaves.left.and.right",
|
|
49
54
|
refresh: "arrow.clockwise",
|
|
50
55
|
reply: "arrowshape.turn.up.left",
|
|
51
56
|
search: "magnifyingglass",
|
|
52
57
|
settings: "gearshape",
|
|
58
|
+
"settings-2": "slider.horizontal.3",
|
|
53
59
|
share: "square.and.arrow.up",
|
|
54
60
|
smile: "face.smiling",
|
|
55
61
|
star: "star",
|
package/src/icons/lucide.ts
CHANGED
|
@@ -9,12 +9,14 @@
|
|
|
9
9
|
* @stability Beta
|
|
10
10
|
*/
|
|
11
11
|
import {
|
|
12
|
+
Aperture,
|
|
12
13
|
ArrowLeft,
|
|
13
14
|
ArrowUp,
|
|
14
15
|
Bell,
|
|
15
16
|
Calendar,
|
|
16
17
|
Camera,
|
|
17
18
|
Check,
|
|
19
|
+
Clapperboard,
|
|
18
20
|
ChevronDown,
|
|
19
21
|
ChevronLeft,
|
|
20
22
|
ChevronRight,
|
|
@@ -27,11 +29,13 @@ import {
|
|
|
27
29
|
Ellipsis,
|
|
28
30
|
ExternalLink,
|
|
29
31
|
File,
|
|
32
|
+
FolderPlus,
|
|
30
33
|
Funnel,
|
|
31
34
|
Heart,
|
|
32
35
|
House,
|
|
33
36
|
Image,
|
|
34
37
|
Info,
|
|
38
|
+
Maximize,
|
|
35
39
|
Maximize2,
|
|
36
40
|
Lock,
|
|
37
41
|
LogOut,
|
|
@@ -46,12 +50,14 @@ import {
|
|
|
46
50
|
Pin,
|
|
47
51
|
Play,
|
|
48
52
|
Plus,
|
|
53
|
+
Radio,
|
|
49
54
|
RefreshCw,
|
|
50
55
|
Reply,
|
|
51
56
|
Search,
|
|
52
57
|
Square,
|
|
53
58
|
SwitchCamera,
|
|
54
59
|
Settings,
|
|
60
|
+
Settings2,
|
|
55
61
|
Share,
|
|
56
62
|
Smile,
|
|
57
63
|
SquarePen,
|
|
@@ -70,11 +76,13 @@ import type { GenesisIconComponent } from "../native-modules";
|
|
|
70
76
|
export const lucideIcons: Record<NativeIconName, GenesisIconComponent> = {
|
|
71
77
|
"arrow-left": ArrowLeft,
|
|
72
78
|
"arrow-up": ArrowUp,
|
|
79
|
+
aperture: Aperture,
|
|
73
80
|
bell: Bell,
|
|
74
81
|
calendar: Calendar,
|
|
75
82
|
camera: Camera,
|
|
76
83
|
"camera-flip": SwitchCamera,
|
|
77
84
|
check: Check,
|
|
85
|
+
clapperboard: Clapperboard,
|
|
78
86
|
"chevron-down": ChevronDown,
|
|
79
87
|
"chevron-left": ChevronLeft,
|
|
80
88
|
"chevron-right": ChevronRight,
|
|
@@ -90,6 +98,7 @@ export const lucideIcons: Record<NativeIconName, GenesisIconComponent> = {
|
|
|
90
98
|
"external-link": ExternalLink,
|
|
91
99
|
file: File,
|
|
92
100
|
filter: Funnel,
|
|
101
|
+
"folder-plus": FolderPlus,
|
|
93
102
|
heart: Heart,
|
|
94
103
|
home: House,
|
|
95
104
|
image: Image,
|
|
@@ -97,6 +106,7 @@ export const lucideIcons: Record<NativeIconName, GenesisIconComponent> = {
|
|
|
97
106
|
lock: Lock,
|
|
98
107
|
"log-out": LogOut,
|
|
99
108
|
mail: Mail,
|
|
109
|
+
maximize: Maximize,
|
|
100
110
|
menu: Menu,
|
|
101
111
|
message: MessageCircle,
|
|
102
112
|
mic: Mic,
|
|
@@ -107,10 +117,12 @@ export const lucideIcons: Record<NativeIconName, GenesisIconComponent> = {
|
|
|
107
117
|
pin: Pin,
|
|
108
118
|
play: Play,
|
|
109
119
|
plus: Plus,
|
|
120
|
+
radio: Radio,
|
|
110
121
|
refresh: RefreshCw,
|
|
111
122
|
reply: Reply,
|
|
112
123
|
search: Search,
|
|
113
124
|
settings: Settings,
|
|
125
|
+
"settings-2": Settings2,
|
|
114
126
|
share: Share,
|
|
115
127
|
smile: Smile,
|
|
116
128
|
star: Star,
|
|
@@ -198,4 +198,10 @@ describe("InboxPage", () => {
|
|
|
198
198
|
expect(screen.getByTestId("inbox-row-a").getAttribute("aria-label")).toMatch(/^2 unread, Sam, Morning crew/);
|
|
199
199
|
expect(screen.getByTestId("inbox-row-b").getAttribute("aria-label")).not.toContain("Ignored");
|
|
200
200
|
});
|
|
201
|
+
|
|
202
|
+
it("marks a selected row (the conversation open beside the list), as the web does", () => {
|
|
203
|
+
render(<InboxPage testID="inbox" items={[{ id: "s", title: "Sam", selected: true, onPress: () => {} }, { id: "t", title: "Tia", onPress: () => {} }]} />);
|
|
204
|
+
expect(screen.getByTestId("inbox-row-s").getAttribute("aria-selected")).toBe("true");
|
|
205
|
+
expect(screen.getByTestId("inbox-row-t").getAttribute("aria-selected")).toBeNull();
|
|
206
|
+
});
|
|
201
207
|
});
|