@seed-design/lynx-react 0.6.0 → 0.6.1

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.
@@ -6,8 +6,8 @@ export interface UseIconColorOptions {
6
6
  }
7
7
  /**
8
8
  * Lynx `<image>` 의 tint color 를 recipe 의 CSS `color` 로부터 main-thread 에서 읽어
9
- * `tint-color` attribute 로 mirror. `deps` 가 바뀌면 native class patch가 반영된
10
- * 다음 frame에 재동기화하고, UI 표시 이벤트에서는 즉시 동기화.
9
+ * `tint-color` attribute 로 mirror. `deps` 또는 시스템 테마가 바뀌면 native class
10
+ * patch가 반영된 다음 frame에 재동기화하고, UI 표시 이벤트에서는 즉시 동기화.
11
11
  *
12
12
  * ```tsx
13
13
  * const iconColorProps = useIconColor([variant, disabled, loading]);
@@ -1,4 +1,4 @@
1
- import { runOnMainThread, useEffect, useMainThreadRef } from "@lynx-js/react";
1
+ import { runOnMainThread, useEffect, useGlobalProps, useMainThreadRef } from "@lynx-js/react";
2
2
  //#region src/hooks/useIconColor.ts
3
3
  function syncTintColorOnce(targetRef, sourceRef) {
4
4
  "main thread";
@@ -31,8 +31,8 @@ function cancelTintColorSync(frameRef) {
31
31
  }
32
32
  /**
33
33
  * Lynx `<image>` 의 tint color 를 recipe 의 CSS `color` 로부터 main-thread 에서 읽어
34
- * `tint-color` attribute 로 mirror. `deps` 가 바뀌면 native class patch가 반영된
35
- * 다음 frame에 재동기화하고, UI 표시 이벤트에서는 즉시 동기화.
34
+ * `tint-color` attribute 로 mirror. `deps` 또는 시스템 테마가 바뀌면 native class
35
+ * patch가 반영된 다음 frame에 재동기화하고, UI 표시 이벤트에서는 즉시 동기화.
36
36
  *
37
37
  * ```tsx
38
38
  * const iconColorProps = useIconColor([variant, disabled, loading]);
@@ -44,6 +44,7 @@ function useIconColor(deps, options) {
44
44
  const sourceRef = options?.sourceRef;
45
45
  const enabled = options?.enabled ?? true;
46
46
  const frameRef = useMainThreadRef(0);
47
+ const theme = useGlobalProps()?.theme;
47
48
  function syncOnUiAppear() {
48
49
  "main thread";
49
50
  if (!enabled) return;
@@ -55,7 +56,11 @@ function useIconColor(deps, options) {
55
56
  return () => {
56
57
  runOnMainThread(cancelTintColorSync)(frameRef);
57
58
  };
58
- }, [...deps, enabled]);
59
+ }, [
60
+ ...deps,
61
+ enabled,
62
+ theme
63
+ ]);
59
64
  return {
60
65
  ref,
61
66
  "main-thread:binduiappear": syncOnUiAppear
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seed-design/lynx-react",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/daangn/seed-design.git",
@@ -39,7 +39,7 @@
39
39
  "devDependencies": {
40
40
  "@lynx-js/react": "^0.117.0",
41
41
  "@lynx-js/types": "^3.7.0",
42
- "@seed-design/lynx-css": "0.10.0",
42
+ "@seed-design/lynx-css": "0.10.1",
43
43
  "@testing-library/jest-dom": "^6.9.1",
44
44
  "jsdom": "^29.0.2",
45
45
  "preact": "npm:@lynx-js/internal-preact@10.28.4-ee7bb26",
@@ -1,13 +1,49 @@
1
+ import type * as ReactLynx from "@lynx-js/react";
1
2
  import { renderHook } from "@lynx-js/react/testing-library";
2
- import { describe, expect, it } from "vitest";
3
+ import { beforeEach, describe, expect, it, vi } from "vitest";
3
4
 
4
5
  import { useIconColor } from "./useIconColor";
5
6
 
7
+ const testState = vi.hoisted(() => ({
8
+ theme: "light",
9
+ workletCalls: [] as number[],
10
+ }));
11
+
12
+ vi.mock("@lynx-js/react", async (importOriginal) => {
13
+ const actual = await importOriginal<typeof ReactLynx>();
14
+
15
+ return {
16
+ ...actual,
17
+ runOnMainThread:
18
+ (_worklet: (...args: never[]) => unknown) =>
19
+ (...args: unknown[]) => {
20
+ testState.workletCalls.push(args.length);
21
+ },
22
+ useGlobalProps: () => ({ theme: testState.theme }),
23
+ };
24
+ });
25
+
6
26
  describe("useIconColor", () => {
27
+ beforeEach(() => {
28
+ testState.theme = "light";
29
+ testState.workletCalls.length = 0;
30
+ });
31
+
7
32
  it("returns icon tint sync props", () => {
8
33
  const { result } = renderHook(() => useIconColor([]));
9
34
 
10
35
  expect(result.current).toHaveProperty("ref");
11
36
  expect(result.current["main-thread:binduiappear"]).toBeDefined();
12
37
  });
38
+
39
+ it("schedules tint color synchronization when the system theme changes", () => {
40
+ const { rerender } = renderHook(() => useIconColor([]));
41
+
42
+ expect(testState.workletCalls).toEqual([3]);
43
+
44
+ testState.theme = "dark";
45
+ rerender();
46
+
47
+ expect(testState.workletCalls).toEqual([3, 1, 3]);
48
+ });
13
49
  });
@@ -1,4 +1,4 @@
1
- import { runOnMainThread, useEffect, useMainThreadRef } from "@lynx-js/react";
1
+ import { runOnMainThread, useEffect, useGlobalProps, useMainThreadRef } from "@lynx-js/react";
2
2
  import type { MainThread } from "@lynx-js/types";
3
3
  import type { DependencyList, RefObject } from "@lynx-js/react";
4
4
 
@@ -70,8 +70,8 @@ function cancelTintColorSync(frameRef: RefObject<number>) {
70
70
 
71
71
  /**
72
72
  * Lynx `<image>` 의 tint color 를 recipe 의 CSS `color` 로부터 main-thread 에서 읽어
73
- * `tint-color` attribute 로 mirror. `deps` 가 바뀌면 native class patch가 반영된
74
- * 다음 frame에 재동기화하고, UI 표시 이벤트에서는 즉시 동기화.
73
+ * `tint-color` attribute 로 mirror. `deps` 또는 시스템 테마가 바뀌면 native class
74
+ * patch가 반영된 다음 frame에 재동기화하고, UI 표시 이벤트에서는 즉시 동기화.
75
75
  *
76
76
  * ```tsx
77
77
  * const iconColorProps = useIconColor([variant, disabled, loading]);
@@ -89,6 +89,7 @@ export function useIconColor(
89
89
  const sourceRef = options?.sourceRef as RefObject<IconElement> | undefined;
90
90
  const enabled = options?.enabled ?? true;
91
91
  const frameRef = useMainThreadRef<number>(0);
92
+ const theme = (useGlobalProps() as { theme?: unknown } | undefined)?.theme;
92
93
 
93
94
  function syncOnUiAppear() {
94
95
  "main thread";
@@ -96,7 +97,6 @@ export function useIconColor(
96
97
  syncTintColorOnce(ref, sourceRef);
97
98
  }
98
99
 
99
- // deps 는 caller 가 책임.
100
100
  useEffect(() => {
101
101
  if (!enabled) return;
102
102
 
@@ -104,7 +104,7 @@ export function useIconColor(
104
104
  return () => {
105
105
  runOnMainThread(cancelTintColorSync)(frameRef);
106
106
  };
107
- }, [...deps, enabled]);
107
+ }, [...deps, enabled, theme]);
108
108
 
109
109
  return { ref, "main-thread:binduiappear": syncOnUiAppear };
110
110
  }