@seed-design/lynx-react 0.6.2 → 0.6.3
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIconColor.d.ts","sourceRoot":"","sources":["../../src/hooks/useIconColor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAOhE,MAAM,WAAW,mBAAmB;IAClC,SAAS,CAAC,EAAE,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAC1C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AA0DD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,cAAc,EACpB,OAAO,CAAC,EAAE,mBAAmB,GAC5B;IACD,GAAG,EAAE,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACnC,0BAA0B,EAAE,MAAM,IAAI,CAAC;CACxC,
|
|
1
|
+
{"version":3,"file":"useIconColor.d.ts","sourceRoot":"","sources":["../../src/hooks/useIconColor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAOhE,MAAM,WAAW,mBAAmB;IAClC,SAAS,CAAC,EAAE,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAC1C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AA0DD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,cAAc,EACpB,OAAO,CAAC,EAAE,mBAAmB,GAC5B;IACD,GAAG,EAAE,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACnC,0BAA0B,EAAE,MAAM,IAAI,CAAC;CACxC,CA6BA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { runOnMainThread, useEffect, useGlobalProps, useMainThreadRef } from "@lynx-js/react";
|
|
1
|
+
import { runOnMainThread, useEffect, useGlobalProps, useMainThreadRef, useRef } from "@lynx-js/react";
|
|
2
2
|
//#region src/hooks/useIconColor.ts
|
|
3
3
|
function syncTintColorOnce(targetRef, sourceRef) {
|
|
4
4
|
"main thread";
|
|
@@ -45,12 +45,17 @@ function useIconColor(deps, options) {
|
|
|
45
45
|
const enabled = options?.enabled ?? true;
|
|
46
46
|
const frameRef = useMainThreadRef(0);
|
|
47
47
|
const theme = useGlobalProps()?.theme;
|
|
48
|
+
const hasMountedRef = useRef(false);
|
|
48
49
|
function syncOnUiAppear() {
|
|
49
50
|
"main thread";
|
|
50
51
|
if (!enabled) return;
|
|
51
|
-
|
|
52
|
+
scheduleTintColorSync(ref, sourceRef, frameRef);
|
|
52
53
|
}
|
|
53
54
|
useEffect(() => {
|
|
55
|
+
if (!hasMountedRef.current) {
|
|
56
|
+
hasMountedRef.current = true;
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
54
59
|
if (!enabled) return;
|
|
55
60
|
runOnMainThread(scheduleTintColorSync)(ref, sourceRef, frameRef);
|
|
56
61
|
return () => {
|
package/package.json
CHANGED
|
@@ -80,7 +80,7 @@ function installMainThreadStyleMocks(getComputedColor: () => string) {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
describe("InternalIcon", () => {
|
|
83
|
-
it("reads the updated computed color
|
|
83
|
+
it("reads the updated computed color after dependency changes", async () => {
|
|
84
84
|
let computedColor = "rgb(134, 139, 148)";
|
|
85
85
|
const { frames, runNextFrame } = installMainThreadStyleMocks(() => computedColor);
|
|
86
86
|
|
|
@@ -94,16 +94,14 @@ describe("InternalIcon", () => {
|
|
|
94
94
|
await waitSchedule();
|
|
95
95
|
|
|
96
96
|
const { image } = getSourceAndImage();
|
|
97
|
-
expect(frames.size).toBe(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
expect(image.getAttribute("tint-color")).toBe("rgb(134, 139, 148)");
|
|
97
|
+
expect(frames.size).toBe(0);
|
|
98
|
+
expect(image.getAttribute("tint-color")).toBeNull();
|
|
101
99
|
|
|
102
100
|
rerender(renderIcon("checked"));
|
|
103
101
|
await waitSchedule();
|
|
104
102
|
|
|
105
103
|
expect(frames.size).toBe(1);
|
|
106
|
-
expect(image.getAttribute("tint-color")).
|
|
104
|
+
expect(image.getAttribute("tint-color")).toBeNull();
|
|
107
105
|
|
|
108
106
|
computedColor = "rgb(255, 102, 0)";
|
|
109
107
|
runNextFrame();
|
|
@@ -15,7 +15,7 @@ vi.mock("@lynx-js/react", async (importOriginal) => {
|
|
|
15
15
|
return {
|
|
16
16
|
...actual,
|
|
17
17
|
runOnMainThread:
|
|
18
|
-
(
|
|
18
|
+
() =>
|
|
19
19
|
(...args: unknown[]) => {
|
|
20
20
|
testState.workletCalls.push(args.length);
|
|
21
21
|
},
|
|
@@ -36,14 +36,14 @@ describe("useIconColor", () => {
|
|
|
36
36
|
expect(result.current["main-thread:binduiappear"]).toBeDefined();
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
it("
|
|
39
|
+
it("avoids cross-thread calls on mount and resynchronizes after theme changes", () => {
|
|
40
40
|
const { rerender } = renderHook(() => useIconColor([]));
|
|
41
41
|
|
|
42
|
-
expect(testState.workletCalls).toEqual([
|
|
42
|
+
expect(testState.workletCalls).toEqual([]);
|
|
43
43
|
|
|
44
44
|
testState.theme = "dark";
|
|
45
45
|
rerender();
|
|
46
46
|
|
|
47
|
-
expect(testState.workletCalls).toEqual([3
|
|
47
|
+
expect(testState.workletCalls).toEqual([3]);
|
|
48
48
|
});
|
|
49
49
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { runOnMainThread, useEffect, useGlobalProps, useMainThreadRef } from "@lynx-js/react";
|
|
1
|
+
import { runOnMainThread, useEffect, useGlobalProps, useMainThreadRef, useRef } 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
|
|
|
@@ -90,14 +90,20 @@ export function useIconColor(
|
|
|
90
90
|
const enabled = options?.enabled ?? true;
|
|
91
91
|
const frameRef = useMainThreadRef<number>(0);
|
|
92
92
|
const theme = (useGlobalProps() as { theme?: unknown } | undefined)?.theme;
|
|
93
|
+
const hasMountedRef = useRef(false);
|
|
93
94
|
|
|
94
95
|
function syncOnUiAppear() {
|
|
95
96
|
"main thread";
|
|
96
97
|
if (!enabled) return;
|
|
97
|
-
|
|
98
|
+
scheduleTintColorSync(ref, sourceRef, frameRef);
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
useEffect(() => {
|
|
102
|
+
if (!hasMountedRef.current) {
|
|
103
|
+
hasMountedRef.current = true;
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
101
107
|
if (!enabled) return;
|
|
102
108
|
|
|
103
109
|
runOnMainThread(scheduleTintColorSync)(ref, sourceRef, frameRef);
|