react-native-livechart 4.22.0 → 4.22.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.
@@ -4,6 +4,8 @@ import type { FontConfig } from "../types";
4
4
  * Resolves Skia text for charts: optional bundled `typeface` via `useFont`, otherwise
5
5
  * `matchFont` with optional custom `fontManager`. System-font matches are cached
6
6
  * module-wide, so many charts sharing a family/size/weight resolve it once.
7
+ * Custom-manager matches are reused while the manager and resolved inputs stay
8
+ * unchanged, even if the caller passes a new font config object each render.
7
9
  */
8
10
  export declare function useChartSkiaFont(fontProp: FontConfig | undefined, defaultFamily: string, defaultSize: number): SkFont;
9
11
  //# sourceMappingURL=useChartSkiaFont.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useChartSkiaFont.d.ts","sourceRoot":"","sources":["../../src/hooks/useChartSkiaFont.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,MAAM,EAEZ,MAAM,4BAA4B,CAAC;AAGpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AA2B3C;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,UAAU,GAAG,SAAS,EAChC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,GAClB,MAAM,CAcR"}
1
+ {"version":3,"file":"useChartSkiaFont.d.ts","sourceRoot":"","sources":["../../src/hooks/useChartSkiaFont.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,MAAM,EAEZ,MAAM,4BAA4B,CAAC;AAIpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AA2B3C;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,UAAU,GAAG,SAAS,EAChC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,GAClB,MAAM,CAcR"}
package/package.json CHANGED
@@ -67,5 +67,5 @@
67
67
  },
68
68
  "sideEffects": false,
69
69
  "types": "./dist/index.d.ts",
70
- "version": "4.22.0"
70
+ "version": "4.22.1"
71
71
  }
@@ -5,6 +5,7 @@ import {
5
5
  type SkFont,
6
6
  type SkFontMgr,
7
7
  } from "@shopify/react-native-skia";
8
+ import { useMemo } from "react";
8
9
 
9
10
  import { resolveFontConfig } from "../core/resolveConfig";
10
11
  import type { FontConfig } from "../types";
@@ -15,7 +16,7 @@ import type { FontConfig } from "../types";
15
16
  * fonts per render, so a screen full of sparklines would otherwise re-match
16
17
  * the same `{family, size, weight}` dozens of times. `SkFont` instances are
17
18
  * immutable and safe to share across canvases. Custom `fontManager`s bypass
18
- * the cache (their identity isn't part of the key).
19
+ * this module-wide cache; their fonts are memoized per hook instead.
19
20
  */
20
21
  const systemFontCache = new Map<string, SkFont>();
21
22
  let systemFontMgr: SkFontMgr | null = null;
@@ -38,6 +39,8 @@ function matchSystemFont(
38
39
  * Resolves Skia text for charts: optional bundled `typeface` via `useFont`, otherwise
39
40
  * `matchFont` with optional custom `fontManager`. System-font matches are cached
40
41
  * module-wide, so many charts sharing a family/size/weight resolve it once.
42
+ * Custom-manager matches are reused while the manager and resolved inputs stay
43
+ * unchanged, even if the caller passes a new font config object each render.
41
44
  */
42
45
  export function useChartSkiaFont(
43
46
  fontProp: FontConfig | undefined,
@@ -49,12 +52,12 @@ export function useChartSkiaFont(
49
52
  const typefaceSource = fontProp?.typeface ?? null;
50
53
  const customFont = useFont(typefaceSource, fontSize);
51
54
 
52
- const fallbackFont = fontProp?.fontManager
53
- ? matchFont({ fontFamily, fontSize, fontWeight }, fontProp.fontManager)
54
- : matchSystemFont(fontFamily, fontSize, fontWeight);
55
-
56
- if (typefaceSource != null) {
57
- return customFont ?? fallbackFont;
58
- }
59
- return fallbackFont;
55
+ const fontManager = fontProp?.fontManager;
56
+ return useMemo(() => {
57
+ // A loaded typeface needs no fallback, so avoid matching an unused font.
58
+ if (typefaceSource != null && customFont) return customFont;
59
+ return fontManager
60
+ ? matchFont({ fontFamily, fontSize, fontWeight }, fontManager)
61
+ : matchSystemFont(fontFamily, fontSize, fontWeight);
62
+ }, [typefaceSource, customFont, fontManager, fontFamily, fontSize, fontWeight]);
60
63
  }