@shopify/react-native-skia 0.1.133 → 0.1.137

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.
Files changed (153) hide show
  1. package/README.md +4 -47
  2. package/android/CMakeLists.txt +1 -1
  3. package/android/build.gradle +17 -2
  4. package/cpp/api/JsiSkFont.h +25 -1
  5. package/cpp/api/JsiSkMatrix.h +12 -0
  6. package/cpp/rnskia/RNSkValueApi.h +6 -6
  7. package/cpp/rnskia/values/{RNSkDerivedValue.h → RNSkComputedValue.h} +7 -7
  8. package/ios/RNSkia-iOS/SkiaManager.mm +1 -1
  9. package/jestSetup.js +5 -0
  10. package/lib/commonjs/animation/functions/interpolate.js +3 -2
  11. package/lib/commonjs/animation/functions/interpolate.js.map +1 -1
  12. package/lib/commonjs/animation/functions/interpolateColors.js +2 -2
  13. package/lib/commonjs/animation/functions/interpolateColors.js.map +1 -1
  14. package/lib/commonjs/animation/functions/interpolatePaths.js +45 -11
  15. package/lib/commonjs/animation/functions/interpolatePaths.js.map +1 -1
  16. package/lib/commonjs/mock/index.js +134 -0
  17. package/lib/commonjs/mock/index.js.map +1 -0
  18. package/lib/commonjs/renderer/components/Group.js +1 -1
  19. package/lib/commonjs/renderer/components/Group.js.map +1 -1
  20. package/lib/commonjs/renderer/processors/Transform.js +8 -15
  21. package/lib/commonjs/renderer/processors/Transform.js.map +1 -1
  22. package/lib/commonjs/skia/core/Data.js +33 -43
  23. package/lib/commonjs/skia/core/Data.js.map +1 -1
  24. package/lib/commonjs/skia/core/Typeface.js +1 -1
  25. package/lib/commonjs/skia/core/Typeface.js.map +1 -1
  26. package/lib/commonjs/skia/types/Font/Font.js.map +1 -1
  27. package/lib/commonjs/skia/types/Matrix.js +17 -2
  28. package/lib/commonjs/skia/types/Matrix.js.map +1 -1
  29. package/lib/commonjs/skia/web/JsiSkFont.js +6 -0
  30. package/lib/commonjs/skia/web/JsiSkFont.js.map +1 -1
  31. package/lib/commonjs/skia/web/JsiSkMatrix.js +4 -0
  32. package/lib/commonjs/skia/web/JsiSkMatrix.js.map +1 -1
  33. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  34. package/lib/commonjs/values/api.js +1 -7
  35. package/lib/commonjs/values/api.js.map +1 -1
  36. package/lib/commonjs/values/api.web.js +3 -3
  37. package/lib/commonjs/values/api.web.js.map +1 -1
  38. package/lib/commonjs/values/hooks/index.js +4 -4
  39. package/lib/commonjs/values/hooks/index.js.map +1 -1
  40. package/lib/commonjs/values/hooks/useComputedValue.js +32 -0
  41. package/lib/commonjs/values/hooks/useComputedValue.js.map +1 -0
  42. package/lib/commonjs/values/web/{RNSkDerivedValue.js → RNSkComputedValue.js} +4 -4
  43. package/lib/commonjs/values/web/RNSkComputedValue.js.map +1 -0
  44. package/lib/commonjs/values/web/api.js +3 -3
  45. package/lib/commonjs/values/web/api.js.map +1 -1
  46. package/lib/commonjs/views/SkiaView.web.js +18 -18
  47. package/lib/commonjs/views/SkiaView.web.js.map +1 -1
  48. package/lib/commonjs/web/LoadSkiaWeb.js +25 -0
  49. package/lib/commonjs/web/LoadSkiaWeb.js.map +1 -0
  50. package/lib/commonjs/web/WithSkiaWeb.js +38 -0
  51. package/lib/commonjs/web/WithSkiaWeb.js.map +1 -0
  52. package/lib/commonjs/web/index.js +22 -12
  53. package/lib/commonjs/web/index.js.map +1 -1
  54. package/lib/module/animation/functions/interpolate.js +2 -2
  55. package/lib/module/animation/functions/interpolate.js.map +1 -1
  56. package/lib/module/animation/functions/interpolateColors.js +1 -1
  57. package/lib/module/animation/functions/interpolateColors.js.map +1 -1
  58. package/lib/module/animation/functions/interpolatePaths.js +44 -11
  59. package/lib/module/animation/functions/interpolatePaths.js.map +1 -1
  60. package/lib/module/mock/index.js +108 -0
  61. package/lib/module/mock/index.js.map +1 -0
  62. package/lib/module/renderer/components/Group.js +1 -1
  63. package/lib/module/renderer/components/Group.js.map +1 -1
  64. package/lib/module/renderer/processors/Transform.js +8 -15
  65. package/lib/module/renderer/processors/Transform.js.map +1 -1
  66. package/lib/module/skia/core/Data.js +32 -41
  67. package/lib/module/skia/core/Data.js.map +1 -1
  68. package/lib/module/skia/core/Typeface.js +1 -1
  69. package/lib/module/skia/core/Typeface.js.map +1 -1
  70. package/lib/module/skia/types/Font/Font.js.map +1 -1
  71. package/lib/module/skia/types/Matrix.js +11 -1
  72. package/lib/module/skia/types/Matrix.js.map +1 -1
  73. package/lib/module/skia/web/JsiSkFont.js +6 -0
  74. package/lib/module/skia/web/JsiSkFont.js.map +1 -1
  75. package/lib/module/skia/web/JsiSkMatrix.js +4 -0
  76. package/lib/module/skia/web/JsiSkMatrix.js.map +1 -1
  77. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  78. package/lib/module/values/api.js +0 -4
  79. package/lib/module/values/api.js.map +1 -1
  80. package/lib/module/values/api.web.js +1 -1
  81. package/lib/module/values/api.web.js.map +1 -1
  82. package/lib/module/values/hooks/index.js +1 -1
  83. package/lib/module/values/hooks/index.js.map +1 -1
  84. package/lib/module/values/hooks/useComputedValue.js +18 -0
  85. package/lib/module/values/hooks/useComputedValue.js.map +1 -0
  86. package/lib/module/values/web/{RNSkDerivedValue.js → RNSkComputedValue.js} +2 -2
  87. package/lib/module/values/web/RNSkComputedValue.js.map +1 -0
  88. package/lib/module/values/web/api.js +3 -3
  89. package/lib/module/values/web/api.js.map +1 -1
  90. package/lib/module/views/SkiaView.web.js +18 -18
  91. package/lib/module/views/SkiaView.web.js.map +1 -1
  92. package/lib/module/web/LoadSkiaWeb.js +12 -0
  93. package/lib/module/web/LoadSkiaWeb.js.map +1 -0
  94. package/lib/module/web/WithSkiaWeb.js +22 -0
  95. package/lib/module/web/WithSkiaWeb.js.map +1 -0
  96. package/lib/module/web/index.js +2 -9
  97. package/lib/module/web/index.js.map +1 -1
  98. package/lib/typescript/jestSetup.d.ts +1 -0
  99. package/lib/typescript/src/animation/functions/interpolate.d.ts +6 -0
  100. package/lib/typescript/src/animation/functions/interpolatePaths.d.ts +3 -1
  101. package/lib/typescript/src/mock/index.d.ts +16 -0
  102. package/lib/typescript/src/renderer/Canvas.d.ts +1 -1
  103. package/lib/typescript/src/renderer/processors/Transform.d.ts +2 -2
  104. package/lib/typescript/src/skia/core/Data.d.ts +3 -3
  105. package/lib/typescript/src/skia/types/Font/Font.d.ts +6 -0
  106. package/lib/typescript/src/skia/types/Matrix.d.ts +5 -1
  107. package/lib/typescript/src/skia/types/Skia.d.ts +1 -1
  108. package/lib/typescript/src/skia/web/JsiSkFont.d.ts +1 -0
  109. package/lib/typescript/src/skia/web/JsiSkMatrix.d.ts +1 -0
  110. package/lib/typescript/src/values/api.d.ts +0 -1
  111. package/lib/typescript/src/values/api.web.d.ts +1 -1
  112. package/lib/typescript/src/values/hooks/index.d.ts +1 -1
  113. package/lib/typescript/src/values/hooks/{useDerivedValue.d.ts → useComputedValue.d.ts} +2 -1
  114. package/lib/typescript/src/values/types.d.ts +2 -2
  115. package/lib/typescript/src/values/web/{RNSkDerivedValue.d.ts → RNSkComputedValue.d.ts} +1 -1
  116. package/lib/typescript/src/views/SkiaView.web.d.ts +2 -2
  117. package/lib/typescript/src/web/LoadSkiaWeb.d.ts +6 -0
  118. package/lib/typescript/src/web/WithSkiaWeb.d.ts +10 -0
  119. package/lib/typescript/src/web/index.d.ts +2 -5
  120. package/package.json +8 -3
  121. package/scripts/setup-canvaskit.js +74 -0
  122. package/src/animation/functions/interpolate.ts +4 -2
  123. package/src/animation/functions/interpolateColors.ts +1 -1
  124. package/src/animation/functions/interpolatePaths.ts +59 -10
  125. package/src/mock/index.ts +110 -0
  126. package/src/renderer/components/Group.tsx +1 -1
  127. package/src/renderer/processors/Transform.ts +7 -10
  128. package/src/skia/core/Data.ts +67 -50
  129. package/src/skia/core/Typeface.ts +6 -1
  130. package/src/skia/types/Font/Font.ts +7 -0
  131. package/src/skia/types/Matrix.ts +18 -2
  132. package/src/skia/types/Skia.ts +1 -1
  133. package/src/skia/web/JsiSkFont.ts +6 -0
  134. package/src/skia/web/JsiSkMatrix.ts +4 -0
  135. package/src/skia/web/JsiSkia.ts +1 -1
  136. package/src/values/api.ts +0 -2
  137. package/src/values/api.web.ts +1 -1
  138. package/src/values/hooks/index.ts +1 -1
  139. package/src/values/hooks/useComputedValue.ts +23 -0
  140. package/src/values/types.ts +2 -2
  141. package/src/values/web/{RNSkDerivedValue.ts → RNSkComputedValue.ts} +1 -1
  142. package/src/values/web/api.ts +3 -3
  143. package/src/views/SkiaView.web.tsx +27 -24
  144. package/src/web/LoadSkiaWeb.tsx +18 -0
  145. package/src/web/WithSkiaWeb.tsx +32 -0
  146. package/src/web/index.ts +2 -15
  147. package/lib/commonjs/values/hooks/useDerivedValue.js +0 -25
  148. package/lib/commonjs/values/hooks/useDerivedValue.js.map +0 -1
  149. package/lib/commonjs/values/web/RNSkDerivedValue.js.map +0 -1
  150. package/lib/module/values/hooks/useDerivedValue.js +0 -14
  151. package/lib/module/values/hooks/useDerivedValue.js.map +0 -1
  152. package/lib/module/values/web/RNSkDerivedValue.js.map +0 -1
  153. package/src/values/hooks/useDerivedValue.ts +0 -18
@@ -27,6 +27,12 @@ Clients should use "Font.getGlyphWidths" instead (the latter does no shaping)`
27
27
  return new JsiSkRect(this.CanvasKit, this.CanvasKit.XYWHRect(0, 0, 0, 0));
28
28
  }
29
29
 
30
+ getTextWidth(text: string, paint?: SkPaint | undefined) {
31
+ const ids = this.getGlyphIDs(text);
32
+ const widths = this.getGlyphWidths(ids, paint);
33
+ return widths.reduce((a, b) => a + b, 0);
34
+ }
35
+
30
36
  getMetrics() {
31
37
  const result = this.ref.getMetrics();
32
38
  return {
@@ -51,4 +51,8 @@ export class JsiSkMatrix
51
51
  )
52
52
  );
53
53
  }
54
+
55
+ identity() {
56
+ this.ref.set(this.CanvasKit.Matrix.identity());
57
+ }
54
58
  }
@@ -63,7 +63,7 @@ export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
63
63
  new JsiSkPictureRecorder(CanvasKit, new CanvasKit.PictureRecorder()),
64
64
  Picture: new JsiSkPictureFactory(CanvasKit),
65
65
  Path: new JsiSkPathFactory(CanvasKit),
66
- Matrix: (matrix?: number[]) =>
66
+ Matrix: (matrix?: readonly number[]) =>
67
67
  new JsiSkMatrix(
68
68
  CanvasKit,
69
69
  matrix
package/src/values/api.ts CHANGED
@@ -6,5 +6,3 @@ declare global {
6
6
 
7
7
  const { SkiaValueApi } = global;
8
8
  export const ValueApi = SkiaValueApi;
9
-
10
- export const { createValue, createDerivedValue } = ValueApi;
@@ -2,4 +2,4 @@ import { ValueApi as ValueApiWeb } from "./web";
2
2
 
3
3
  export const ValueApi = ValueApiWeb;
4
4
 
5
- export const { createValue, createDerivedValue } = ValueApi;
5
+ export const { createValue, createComputedValue } = ValueApi;
@@ -1,4 +1,4 @@
1
1
  export * from "./useClockValue";
2
- export * from "./useDerivedValue";
2
+ export * from "./useComputedValue";
3
3
  export * from "./useValue";
4
4
  export * from "./useValueEffect";
@@ -0,0 +1,23 @@
1
+ import { useMemo } from "react";
2
+
3
+ import { ValueApi } from "../api";
4
+ import { isValue } from "../../renderer/processors/Animations";
5
+
6
+ /**
7
+ * Creates a new computed value - a value that will calculate its value depending
8
+ * on other values.
9
+ * @param cb Callback to calculate new value
10
+ * @param values Dependant values
11
+ * @returns A readonly value
12
+ */
13
+ export const useComputedValue = <R>(cb: () => R, values: unknown[]) =>
14
+ useMemo(
15
+ () => ValueApi.createComputedValue<R>(cb, values.filter(isValue)),
16
+ // eslint-disable-next-line react-hooks/exhaustive-deps
17
+ values
18
+ );
19
+
20
+ export const useDerivedValue = <R>(cb: () => R, values: unknown[]) => {
21
+ console.warn("useDerivedValue is deprecated. Use useComputedValue instead.");
22
+ return useComputedValue(cb, values);
23
+ };
@@ -46,10 +46,10 @@ export interface ISkiaValueApi {
46
46
  */
47
47
  createValue: <T>(initialValue: T) => SkiaMutableValue<T>;
48
48
  /**
49
- * Creates a derived value. This is a calculated value that returns the result of
49
+ * Creates a computed value. This is a calculated value that returns the result of
50
50
  * a function that is called with the values of the dependencies.
51
51
  */
52
- createDerivedValue: <R>(
52
+ createComputedValue: <R>(
53
53
  cb: () => R,
54
54
  values: Array<SkiaValue<unknown>>
55
55
  ) => SkiaValue<R>;
@@ -2,7 +2,7 @@ import type { DependencyList } from "react";
2
2
 
3
3
  import { RNSkReadonlyValue } from "./RNSkReadonlyValue";
4
4
 
5
- export class RNSkDerivedValue<T> extends RNSkReadonlyValue<T> {
5
+ export class RNSkComputedValue<T> extends RNSkReadonlyValue<T> {
6
6
  constructor(callback: () => T, dependencies: DependencyList) {
7
7
  // Initialize dependencies - we can't call this yet, since
8
8
  // super if not called and it requires a start value to be set.
@@ -9,18 +9,18 @@ import type {
9
9
 
10
10
  import { RNSkAnimation } from "./RNSkAnimation";
11
11
  import { RNSkClockValue } from "./RNSkClockValue";
12
- import { RNSkDerivedValue } from "./RNSkDerivedValue";
12
+ import { RNSkComputedValue } from "./RNSkComputedValue";
13
13
  import { RNSkValue } from "./RNSkValue";
14
14
 
15
15
  export const ValueApi: ISkiaValueApi = {
16
16
  createValue: function <T>(initialValue: T): SkiaMutableValue<T> {
17
17
  return new RNSkValue(initialValue);
18
18
  },
19
- createDerivedValue: function <R>(
19
+ createComputedValue: function <R>(
20
20
  cb: () => R,
21
21
  values: SkiaValue<unknown>[]
22
22
  ): SkiaValue<R> {
23
- return new RNSkDerivedValue(cb, values);
23
+ return new RNSkComputedValue(cb, values);
24
24
  },
25
25
  createClockValue: function (): SkiaClockValue {
26
26
  return new RNSkClockValue(requestAnimationFrame.bind(window));
@@ -36,29 +36,32 @@ export class SkiaView extends React.Component<
36
36
  }
37
37
 
38
38
  private onLayout(evt: LayoutChangeEvent) {
39
- this.setState({
40
- width: evt.nativeEvent.layout.width,
41
- height: evt.nativeEvent.layout.height,
42
- });
43
- // Reset canvas / surface on layout change
44
- if (this._canvasRef.current) {
45
- // Create surface
46
- this._surface = new JsiSkSurface(
47
- global.CanvasKit,
48
- global.CanvasKit.MakeCanvasSurface(this._canvasRef.current)!
49
- );
50
- // Get canvas and repaint
51
- if (this._surface) {
52
- this._canvas = this._surface.getCanvas();
53
- this.requestRedraw();
54
- this.redraw();
39
+ this.setState(
40
+ {
41
+ width: evt.nativeEvent.layout.width,
42
+ height: evt.nativeEvent.layout.height,
43
+ },
44
+ () => {
45
+ // Reset canvas / surface on layout change
46
+ if (this._canvasRef.current) {
47
+ // Create surface
48
+ this._surface = new JsiSkSurface(
49
+ global.CanvasKit,
50
+ global.CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current)!
51
+ );
52
+ // Get canvas and repaint
53
+ if (this._surface) {
54
+ this._canvas = this._surface.getCanvas();
55
+ this.redraw();
56
+ }
57
+ }
55
58
  }
56
- }
59
+ );
57
60
  }
58
61
 
59
62
  componentDidMount() {
60
63
  // Start render loop
61
- this.redraw();
64
+ this.tick();
62
65
  }
63
66
 
64
67
  componentWillUnmount() {
@@ -80,7 +83,7 @@ export class SkiaView extends React.Component<
80
83
  /**
81
84
  * Sends a redraw request to the native SkiaView.
82
85
  */
83
- private redraw() {
86
+ private tick() {
84
87
  if (this._mode === "continuous" || this._redrawRequests > 0) {
85
88
  this._redrawRequests = 0;
86
89
  if (
@@ -103,11 +106,11 @@ export class SkiaView extends React.Component<
103
106
  }
104
107
  // Always request a new redraw as long as we're not unmounted
105
108
  if (!this._unmounted) {
106
- requestAnimationFrame(this.redraw.bind(this));
109
+ requestAnimationFrame(this.tick.bind(this));
107
110
  }
108
111
  }
109
112
 
110
- public requestRedraw() {
113
+ public redraw() {
111
114
  this._redrawRequests++;
112
115
  }
113
116
 
@@ -122,7 +125,7 @@ export class SkiaView extends React.Component<
122
125
  */
123
126
  public setDrawMode(mode: DrawMode) {
124
127
  this._mode = mode;
125
- this.redraw();
128
+ this.tick();
126
129
  }
127
130
 
128
131
  /**
@@ -137,7 +140,7 @@ export class SkiaView extends React.Component<
137
140
  _values.forEach((v) => {
138
141
  this._unsubscriptions.push(
139
142
  v.addListener(() => {
140
- this.requestRedraw();
143
+ this.redraw();
141
144
  })
142
145
  );
143
146
  });
@@ -152,7 +155,7 @@ export class SkiaView extends React.Component<
152
155
  type: touchType,
153
156
  timestamp: Date.now(),
154
157
  });
155
- this.requestRedraw();
158
+ this.redraw();
156
159
  }
157
160
 
158
161
  handleTouchStart(evt: PointerEvent) {
@@ -0,0 +1,18 @@
1
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
+ // @ts-expect-error
3
+ import CanvasKitInit from "canvaskit-wasm/bin/full/canvaskit";
4
+ import type { CanvasKit as CanvasKitType } from "canvaskit-wasm";
5
+
6
+ declare global {
7
+ var CanvasKit: CanvasKitType;
8
+ }
9
+
10
+ export const LoadSkiaWeb = async () => {
11
+ const CanvasKit = await CanvasKitInit();
12
+ // The CanvasKit API is stored on the global object and used
13
+ // to create the JsiSKApi in the Skia.web.ts file.
14
+ global.CanvasKit = CanvasKit;
15
+ };
16
+
17
+ // We keep this function for backward compatibility
18
+ export const LoadSkia = LoadSkiaWeb;
@@ -0,0 +1,32 @@
1
+ import type { ComponentProps, ComponentType } from "react";
2
+ import React, { useMemo, lazy, Suspense } from "react";
3
+ import { Platform } from "react-native";
4
+
5
+ import { LoadSkiaWeb } from "./LoadSkiaWeb";
6
+
7
+ interface WithSkiaProps {
8
+ fallback: ComponentProps<typeof Suspense>["fallback"];
9
+ getComponent: () => Promise<{ default: ComponentType }>;
10
+ }
11
+
12
+ export const WithSkiaWeb = ({ getComponent, fallback }: WithSkiaProps) => {
13
+ const Inner = useMemo(
14
+ () =>
15
+ lazy(async () => {
16
+ if (Platform.OS === "web") {
17
+ await LoadSkiaWeb();
18
+ } else {
19
+ console.warn(
20
+ "<WithSkiaWeb /> is only necessary on web. Consider not using on native."
21
+ );
22
+ }
23
+ return getComponent();
24
+ }),
25
+ [getComponent]
26
+ );
27
+ return (
28
+ <Suspense fallback={fallback}>
29
+ <Inner />
30
+ </Suspense>
31
+ );
32
+ };
package/src/web/index.ts CHANGED
@@ -1,15 +1,2 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
- // @ts-expect-error
3
- import CanvasKitInit from "canvaskit-wasm/bin/full/canvaskit";
4
- import type { CanvasKit as CanvasKitType } from "canvaskit-wasm";
5
-
6
- declare global {
7
- var CanvasKit: CanvasKitType;
8
- }
9
-
10
- export const LoadSkia = async () => {
11
- const CanvasKit = await CanvasKitInit();
12
- // The CanvasKit API is stored on the global object and used
13
- // to create the JsiSKApi in the Skia.web.ts file.
14
- global.CanvasKit = CanvasKit;
15
- };
1
+ export * from "./LoadSkiaWeb";
2
+ export * from "./WithSkiaWeb";
@@ -1,25 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useDerivedValue = void 0;
7
-
8
- var _react = require("react");
9
-
10
- var _api = require("../api");
11
-
12
- var _processors = require("../../renderer/processors");
13
-
14
- /**
15
- * Creates a new derived value - a value that will calculate its value depending
16
- * on other values.
17
- * @param cb Callback to calculate new value
18
- * @param values Dependant values
19
- * @returns A readonly value
20
- */
21
- const useDerivedValue = (cb, values) => (0, _react.useMemo)(() => _api.ValueApi.createDerivedValue(cb, values.filter(_processors.isValue)), // eslint-disable-next-line react-hooks/exhaustive-deps
22
- values);
23
-
24
- exports.useDerivedValue = useDerivedValue;
25
- //# sourceMappingURL=useDerivedValue.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["useDerivedValue.ts"],"names":["useDerivedValue","cb","values","ValueApi","createDerivedValue","filter","isValue"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,eAAe,GAAG,CAAIC,EAAJ,EAAiBC,MAAjB,KAC7B,oBACE,MAAMC,cAASC,kBAAT,CAA+BH,EAA/B,EAAmCC,MAAM,CAACG,MAAP,CAAcC,mBAAd,CAAnC,CADR,EAEE;AACAJ,MAHF,CADK","sourcesContent":["import { useMemo } from \"react\";\n\nimport { ValueApi } from \"../api\";\nimport { isValue } from \"../../renderer/processors\";\n\n/**\n * Creates a new derived value - a value that will calculate its value depending\n * on other values.\n * @param cb Callback to calculate new value\n * @param values Dependant values\n * @returns A readonly value\n */\nexport const useDerivedValue = <R>(cb: () => R, values: unknown[]) =>\n useMemo(\n () => ValueApi.createDerivedValue<R>(cb, values.filter(isValue)),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n values\n );\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["RNSkDerivedValue.ts"],"names":["RNSkDerivedValue","RNSkReadonlyValue","constructor","callback","dependencies","unsubscribers","notifyUpdateRef","current","undefined","forEach","dep","push","addListener","_unsubscribers","dependecyUpdated","bind","_callback","update","unsubscribe"],"mappings":";;;;;;;AAEA;;;;AAEO,MAAMA,gBAAN,SAAkCC,oCAAlC,CAAuD;AAC5DC,EAAAA,WAAW,CAACC,QAAD,EAAoBC,YAApB,EAAkD;AAC3D;AACA;AACA,UAAMC,aAAgC,GAAG,EAAzC;AACA,UAAMC,eAAsD,GAAG;AAC7DC,MAAAA,OAAO,EAAEC;AADoD,KAA/D;AAGAJ,IAAAA,YAAY,CAACK,OAAb,CAAsBC,GAAD,IAAS;AAC5B,UAAI,kBAAkBA,GAAlB,IAAyB,iBAAiBA,GAA9C,EAAmD;AACjDL,QAAAA,aAAa,CAACM,IAAd,CACGD,GAAD,CAAoCE,WAApC,CAAgD;AAAA;;AAAA,0CAC9CN,eAAe,CAACC,OAD8B,0DAC9C,2BAAAD,eAAe,CAD+B;AAAA,SAAhD,CADF;AAKD;AACF,KARD;AASA,UAAMH,QAAQ,EAAd;;AAhB2D;;AAAA;;AAiB3D,SAAKU,cAAL,GAAsBR,aAAtB;AACAC,IAAAA,eAAe,CAACC,OAAhB,GAA0B,KAAKO,gBAAL,CAAsBC,IAAtB,CAA2B,IAA3B,CAA1B;AACA,SAAKC,SAAL,GAAiBb,QAAjB;AACD;;AAEOW,EAAAA,gBAAgB,GAAG;AACzB,SAAKG,MAAL,CAAY,KAAKD,SAAL,EAAZ;AACD;;AAKME,EAAAA,WAAW,GAAG;AACnB,SAAKL,cAAL,CAAoBJ,OAApB,CAA6BS,WAAD,IAAiBA,WAAW,EAAxD;AACD;;AAhC2D","sourcesContent":["import type { DependencyList } from \"react\";\n\nimport { RNSkReadonlyValue } from \"./RNSkReadonlyValue\";\n\nexport class RNSkDerivedValue<T> extends RNSkReadonlyValue<T> {\n constructor(callback: () => T, dependencies: DependencyList) {\n // Initialize dependencies - we can't call this yet, since\n // super if not called and it requires a start value to be set.\n const unsubscribers: Array<() => void> = [];\n const notifyUpdateRef: { current: (() => void) | undefined } = {\n current: undefined,\n };\n dependencies.forEach((dep) => {\n if (\"__typename__\" in dep && \"addListener\" in dep) {\n unsubscribers.push(\n (dep as RNSkReadonlyValue<unknown>).addListener(() =>\n notifyUpdateRef.current?.()\n )\n );\n }\n });\n super(callback());\n this._unsubscribers = unsubscribers;\n notifyUpdateRef.current = this.dependecyUpdated.bind(this);\n this._callback = callback;\n }\n\n private dependecyUpdated() {\n this.update(this._callback());\n }\n\n private _callback: () => T;\n private _unsubscribers: Array<() => void>;\n\n public unsubscribe() {\n this._unsubscribers.forEach((unsubscribe) => unsubscribe());\n }\n}\n"]}
@@ -1,14 +0,0 @@
1
- import { useMemo } from "react";
2
- import { ValueApi } from "../api";
3
- import { isValue } from "../../renderer/processors";
4
- /**
5
- * Creates a new derived value - a value that will calculate its value depending
6
- * on other values.
7
- * @param cb Callback to calculate new value
8
- * @param values Dependant values
9
- * @returns A readonly value
10
- */
11
-
12
- export const useDerivedValue = (cb, values) => useMemo(() => ValueApi.createDerivedValue(cb, values.filter(isValue)), // eslint-disable-next-line react-hooks/exhaustive-deps
13
- values);
14
- //# sourceMappingURL=useDerivedValue.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["useDerivedValue.ts"],"names":["useMemo","ValueApi","isValue","useDerivedValue","cb","values","createDerivedValue","filter"],"mappings":"AAAA,SAASA,OAAT,QAAwB,OAAxB;AAEA,SAASC,QAAT,QAAyB,QAAzB;AACA,SAASC,OAAT,QAAwB,2BAAxB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,eAAe,GAAG,CAAIC,EAAJ,EAAiBC,MAAjB,KAC7BL,OAAO,CACL,MAAMC,QAAQ,CAACK,kBAAT,CAA+BF,EAA/B,EAAmCC,MAAM,CAACE,MAAP,CAAcL,OAAd,CAAnC,CADD,EAEL;AACAG,MAHK,CADF","sourcesContent":["import { useMemo } from \"react\";\n\nimport { ValueApi } from \"../api\";\nimport { isValue } from \"../../renderer/processors\";\n\n/**\n * Creates a new derived value - a value that will calculate its value depending\n * on other values.\n * @param cb Callback to calculate new value\n * @param values Dependant values\n * @returns A readonly value\n */\nexport const useDerivedValue = <R>(cb: () => R, values: unknown[]) =>\n useMemo(\n () => ValueApi.createDerivedValue<R>(cb, values.filter(isValue)),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n values\n );\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["RNSkDerivedValue.ts"],"names":["RNSkReadonlyValue","RNSkDerivedValue","constructor","callback","dependencies","unsubscribers","notifyUpdateRef","current","undefined","forEach","dep","push","addListener","_unsubscribers","dependecyUpdated","bind","_callback","update","unsubscribe"],"mappings":";;AAEA,SAASA,iBAAT,QAAkC,qBAAlC;AAEA,OAAO,MAAMC,gBAAN,SAAkCD,iBAAlC,CAAuD;AAC5DE,EAAAA,WAAW,CAACC,QAAD,EAAoBC,YAApB,EAAkD;AAC3D;AACA;AACA,UAAMC,aAAgC,GAAG,EAAzC;AACA,UAAMC,eAAsD,GAAG;AAC7DC,MAAAA,OAAO,EAAEC;AADoD,KAA/D;AAGAJ,IAAAA,YAAY,CAACK,OAAb,CAAsBC,GAAD,IAAS;AAC5B,UAAI,kBAAkBA,GAAlB,IAAyB,iBAAiBA,GAA9C,EAAmD;AACjDL,QAAAA,aAAa,CAACM,IAAd,CACGD,GAAD,CAAoCE,WAApC,CAAgD;AAAA;;AAAA,0CAC9CN,eAAe,CAACC,OAD8B,0DAC9C,2BAAAD,eAAe,CAD+B;AAAA,SAAhD,CADF;AAKD;AACF,KARD;AASA,UAAMH,QAAQ,EAAd;;AAhB2D;;AAAA;;AAiB3D,SAAKU,cAAL,GAAsBR,aAAtB;AACAC,IAAAA,eAAe,CAACC,OAAhB,GAA0B,KAAKO,gBAAL,CAAsBC,IAAtB,CAA2B,IAA3B,CAA1B;AACA,SAAKC,SAAL,GAAiBb,QAAjB;AACD;;AAEOW,EAAAA,gBAAgB,GAAG;AACzB,SAAKG,MAAL,CAAY,KAAKD,SAAL,EAAZ;AACD;;AAKME,EAAAA,WAAW,GAAG;AACnB,SAAKL,cAAL,CAAoBJ,OAApB,CAA6BS,WAAD,IAAiBA,WAAW,EAAxD;AACD;;AAhC2D","sourcesContent":["import type { DependencyList } from \"react\";\n\nimport { RNSkReadonlyValue } from \"./RNSkReadonlyValue\";\n\nexport class RNSkDerivedValue<T> extends RNSkReadonlyValue<T> {\n constructor(callback: () => T, dependencies: DependencyList) {\n // Initialize dependencies - we can't call this yet, since\n // super if not called and it requires a start value to be set.\n const unsubscribers: Array<() => void> = [];\n const notifyUpdateRef: { current: (() => void) | undefined } = {\n current: undefined,\n };\n dependencies.forEach((dep) => {\n if (\"__typename__\" in dep && \"addListener\" in dep) {\n unsubscribers.push(\n (dep as RNSkReadonlyValue<unknown>).addListener(() =>\n notifyUpdateRef.current?.()\n )\n );\n }\n });\n super(callback());\n this._unsubscribers = unsubscribers;\n notifyUpdateRef.current = this.dependecyUpdated.bind(this);\n this._callback = callback;\n }\n\n private dependecyUpdated() {\n this.update(this._callback());\n }\n\n private _callback: () => T;\n private _unsubscribers: Array<() => void>;\n\n public unsubscribe() {\n this._unsubscribers.forEach((unsubscribe) => unsubscribe());\n }\n}\n"]}
@@ -1,18 +0,0 @@
1
- import { useMemo } from "react";
2
-
3
- import { ValueApi } from "../api";
4
- import { isValue } from "../../renderer/processors";
5
-
6
- /**
7
- * Creates a new derived value - a value that will calculate its value depending
8
- * on other values.
9
- * @param cb Callback to calculate new value
10
- * @param values Dependant values
11
- * @returns A readonly value
12
- */
13
- export const useDerivedValue = <R>(cb: () => R, values: unknown[]) =>
14
- useMemo(
15
- () => ValueApi.createDerivedValue<R>(cb, values.filter(isValue)),
16
- // eslint-disable-next-line react-hooks/exhaustive-deps
17
- values
18
- );