@shopify/react-native-skia 0.1.165 → 0.1.166

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +16 -5
  2. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseViewManager.java +34 -0
  3. package/android/src/main/java/com/shopify/reactnative/skia/SkiaDomViewManager.java +2 -47
  4. package/android/src/main/java/com/shopify/reactnative/skia/SkiaDrawViewManager.java +2 -44
  5. package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureViewManager.java +2 -47
  6. package/cpp/rnskia/dom/base/DerivedNodeProp.h +4 -4
  7. package/cpp/rnskia/dom/nodes/JsiBoxNode.h +4 -4
  8. package/cpp/rnskia/dom/nodes/JsiPathNode.h +12 -5
  9. package/cpp/rnskia/dom/nodes/JsiShaderNodes.h +17 -7
  10. package/cpp/rnskia/dom/props/ClipProp.h +6 -6
  11. package/cpp/rnskia/dom/props/ImageProps.h +3 -1
  12. package/cpp/rnskia/dom/props/PaintProps.h +0 -16
  13. package/cpp/rnskia/dom/props/VerticesProps.h +2 -2
  14. package/lib/commonjs/dom/nodes/drawings/Box.js +1 -1
  15. package/lib/commonjs/dom/nodes/drawings/Box.js.map +1 -1
  16. package/lib/commonjs/dom/nodes/paint/ImageFilters.js +1 -1
  17. package/lib/commonjs/dom/nodes/paint/ImageFilters.js.map +1 -1
  18. package/lib/commonjs/dom/nodes/paint/Shaders.js +5 -2
  19. package/lib/commonjs/dom/nodes/paint/Shaders.js.map +1 -1
  20. package/lib/commonjs/skia/types/Shader/Shader.js +26 -27
  21. package/lib/commonjs/skia/types/Shader/Shader.js.map +1 -1
  22. package/lib/module/dom/nodes/drawings/Box.js +1 -1
  23. package/lib/module/dom/nodes/drawings/Box.js.map +1 -1
  24. package/lib/module/dom/nodes/paint/ImageFilters.js +1 -1
  25. package/lib/module/dom/nodes/paint/ImageFilters.js.map +1 -1
  26. package/lib/module/dom/nodes/paint/Shaders.js +5 -4
  27. package/lib/module/dom/nodes/paint/Shaders.js.map +1 -1
  28. package/lib/module/skia/types/Shader/Shader.js +26 -27
  29. package/lib/module/skia/types/Shader/Shader.js.map +1 -1
  30. package/lib/typescript/src/skia/types/Shader/Shader.d.ts +1 -2
  31. package/package.json +1 -1
  32. package/src/dom/nodes/drawings/Box.ts +1 -1
  33. package/src/dom/nodes/paint/ImageFilters.ts +1 -1
  34. package/src/dom/nodes/paint/Shaders.ts +5 -5
  35. package/src/skia/types/Shader/Shader.ts +30 -38
@@ -7,9 +7,7 @@ export const isShader = (obj: SkJSIInstance<string> | null): obj is SkShader =>
7
7
 
8
8
  export type SkShader = SkJSIInstance<"Shader">;
9
9
 
10
- export type UniformValue = number | Vector | readonly number[];
11
-
12
- export type Uniform = UniformValue | readonly UniformValue[] | Float32Array;
10
+ export type Uniform = number | Vector | Float32Array | Uniform[];
13
11
 
14
12
  export interface Uniforms {
15
13
  [name: string]: Uniform;
@@ -20,11 +18,16 @@ const isVector = (obj: unknown): obj is Vector =>
20
18
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
19
  (obj as any).x !== undefined && (obj as any).y !== undefined;
22
20
 
23
- const processValue = (value: UniformValue): number | readonly number[] => {
24
- if (isVector(value)) {
25
- return [value.x, value.y];
21
+ const processValue = (values: number[], value: Uniform) => {
22
+ if (typeof value === "number") {
23
+ values.push(value);
24
+ } else if (Array.isArray(value)) {
25
+ value.forEach((v) => processValue(values, v));
26
+ } else if (isVector(value)) {
27
+ values.push(value.x, value.y);
28
+ } else if (value instanceof Float32Array) {
29
+ values.push(...value);
26
30
  }
27
- return value;
28
31
  };
29
32
 
30
33
  export const processUniforms = (
@@ -32,36 +35,25 @@ export const processUniforms = (
32
35
  uniforms: Uniforms,
33
36
  builder?: SkRuntimeShaderBuilder
34
37
  ) => {
35
- const processed = new Array(source.getUniformCount())
36
- .fill(0)
37
- .flatMap((_, i) => {
38
- const name = source.getUniformName(i);
39
- const rawValue = uniforms[name];
40
- if (rawValue === undefined) {
41
- throw new Error(`No value specified for uniform ${name}`);
42
- }
43
- const value =
44
- rawValue instanceof Float32Array ? Array.from(rawValue) : rawValue;
45
- const result = Array.isArray(value)
46
- ? value.flatMap(processValue)
47
- : processValue(value as UniformValue);
48
- builder?.setUniform(name, typeof result === "number" ? [result] : result);
49
- return result;
50
- });
51
- const names = Object.keys(uniforms);
52
- if (names.length > source.getUniformCount()) {
53
- const usedUniforms = new Array(source.getUniformCount())
54
- .fill(0)
55
- .map((_, i) => source.getUniformName(i));
56
- const unusedUniform = names
57
- .map((name) => {
58
- if (usedUniforms.indexOf(name) === -1) {
59
- return name;
60
- }
61
- return null;
62
- })
63
- .filter((n) => n !== null);
64
- console.warn("Unused uniforms were provided: " + unusedUniform.join(", "));
38
+ const result: number[] = [];
39
+ const uniformsCount = source.getUniformCount();
40
+ for (let i = 0; i < uniformsCount; i++) {
41
+ const name = source.getUniformName(i);
42
+ const value = uniforms[name];
43
+ if (!value === undefined) {
44
+ throw new Error(
45
+ // eslint-disable-next-line max-len
46
+ `The runtime effect has the uniform value "${name}" declared, but it is missing from the uniforms property of the Runtime effect.`
47
+ );
48
+ }
49
+ if (builder === undefined) {
50
+ processValue(result, value);
51
+ } else {
52
+ const uniformValue: number[] = [];
53
+ processValue(uniformValue, value);
54
+ builder.setUniform(name, uniformValue);
55
+ result.push(...uniformValue);
56
+ }
65
57
  }
66
- return processed;
58
+ return result;
67
59
  };