@shopify/react-native-skia 0.1.148 → 0.1.149
Sign up to get free protection for your applications and to get access to all the features.
- package/cpp/api/JsiSkFont.h +4 -4
- package/cpp/rnskia/RNSkJsiViewApi.h +2 -2
- package/lib/commonjs/skia/core/Data.js +10 -1
- package/lib/commonjs/skia/core/Data.js.map +1 -1
- package/lib/module/skia/core/Data.js +11 -2
- package/lib/module/skia/core/Data.js.map +1 -1
- package/package.json +1 -1
- package/src/skia/core/Data.ts +11 -2
package/cpp/api/JsiSkFont.h
CHANGED
@@ -71,7 +71,7 @@ namespace RNSkia
|
|
71
71
|
|
72
72
|
JSI_HOST_FUNCTION(getTextWidth) {
|
73
73
|
auto str = arguments[0].asString(runtime).utf8(runtime);
|
74
|
-
auto numGlyphIDs = str.length();
|
74
|
+
auto numGlyphIDs = getObject()->countText(str.c_str(), str.length(), SkTextEncoding::kUTF8);
|
75
75
|
std::vector<SkGlyphID> glyphs;
|
76
76
|
glyphs.resize(numGlyphIDs);
|
77
77
|
int glyphsSize = static_cast<int>(numGlyphIDs);
|
@@ -111,9 +111,9 @@ namespace RNSkia
|
|
111
111
|
JSI_HOST_FUNCTION(getGlyphIDs)
|
112
112
|
{
|
113
113
|
auto str = arguments[0].asString(runtime).utf8(runtime);
|
114
|
-
|
115
|
-
? arguments[1].asNumber()
|
116
|
-
: str.length();
|
114
|
+
int numGlyphIDs = count > 1 && !arguments[1].isNull() && !arguments[1].isUndefined()
|
115
|
+
? static_cast<int>(arguments[1].asNumber())
|
116
|
+
: getObject()->countText(str.c_str(), str.length(), SkTextEncoding::kUTF8);
|
117
117
|
std::vector<SkGlyphID> glyphIDs;
|
118
118
|
glyphIDs.resize(numGlyphIDs);
|
119
119
|
getObject()->textToGlyphs(str.c_str(), str.length(), SkTextEncoding::kUTF8,
|
@@ -114,9 +114,9 @@ public:
|
|
114
114
|
}
|
115
115
|
|
116
116
|
JSI_HOST_FUNCTION(requestRedraw) {
|
117
|
-
if (count
|
117
|
+
if (count != 1) {
|
118
118
|
_platformContext->raiseError(
|
119
|
-
std::string("requestRedraw: Expected
|
119
|
+
std::string("requestRedraw: Expected 1 arguments, got " + std::to_string(count) + "."));
|
120
120
|
|
121
121
|
return jsi::Value::undefined();
|
122
122
|
}
|
@@ -40,9 +40,18 @@ const loadData = (source, factory, onError) => {
|
|
40
40
|
};
|
41
41
|
|
42
42
|
const useLoading = (source, loader) => {
|
43
|
+
const mounted = (0, _react.useRef)(false);
|
43
44
|
const [data, setData] = (0, _react.useState)(null);
|
44
45
|
(0, _react.useEffect)(() => {
|
45
|
-
|
46
|
+
mounted.current = true;
|
47
|
+
loader().then(value => {
|
48
|
+
if (mounted.current) {
|
49
|
+
setData(value);
|
50
|
+
}
|
51
|
+
});
|
52
|
+
return () => {
|
53
|
+
mounted.current = false;
|
54
|
+
}; // eslint-disable-next-line react-hooks/exhaustive-deps
|
46
55
|
}, [source]);
|
47
56
|
return data;
|
48
57
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Data.ts"],"names":["resolveAsset","source","Image","resolveAssetSource","uri","default","factoryWrapper","data2","factory","onError","factoryResult","Error","loadData","undefined","Promise","resolve","Uint8Array","Skia","Data","fromBytes","fromURI","then","d","useLoading","loader","data","setData","useRawData","identity","useData"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;AACA;;AAGA,MAAMA,YAAY,GAAIC,MAAD,IAAwB;AAC3C,SAAO,uBAAWA,MAAX,IACHC,mBAAMC,kBAAN,CAAyBF,MAAzB,EAAiCG,GAD9B,GAEHH,MAAM,CAACI,OAFX;AAGD,CAJD;;AAMA,MAAMC,cAAc,GAAG,CACrBC,KADqB,EAErBC,OAFqB,EAGrBC,OAHqB,KAIlB;AACH,QAAMC,aAAa,GAAGF,OAAO,CAACD,KAAD,CAA7B;;AACA,MAAIG,aAAa,KAAK,IAAtB,EAA4B;AAC1BD,IAAAA,OAAO,IAAIA,OAAO,CAAC,IAAIE,KAAJ,CAAU,qBAAV,CAAD,CAAlB;AACA,WAAO,IAAP;AACD,GAHD,MAGO;AACL,WAAOD,aAAP;AACD;AACF,CAZD;;AAcA,MAAME,QAAQ,GAAG,CACfX,MADe,EAEfO,OAFe,EAGfC,OAHe,KAIO;AACtB,MAAIR,MAAM,KAAK,IAAX,IAAmBA,MAAM,KAAKY,SAAlC,EAA6C;AAC3C,WAAO,IAAIC,OAAJ,CAAaC,OAAD,IAAaA,OAAO,CAAC,IAAD,CAAhC,CAAP;AACD,GAFD,MAEO,IAAId,MAAM,YAAYe,UAAtB,EAAkC;AACvC,WAAO,IAAIF,OAAJ,CAAaC,OAAD,IACjBA,OAAO,CAACT,cAAc,CAACW,WAAKC,IAAL,CAAUC,SAAV,CAAoBlB,MAApB,CAAD,EAA8BO,OAA9B,EAAuCC,OAAvC,CAAf,CADF,CAAP;AAGD,GAJM,MAIA;AACL,UAAML,GAAG,GAAG,OAAOH,MAAP,KAAkB,QAAlB,GAA6BA,MAA7B,GAAsCD,YAAY,CAACC,MAAD,CAA9D;AACA,WAAOgB,WAAKC,IAAL,CAAUE,OAAV,CAAkBhB,GAAlB,EAAuBiB,IAAvB,CAA6BC,CAAD,IACjChB,cAAc,CAACgB,CAAD,EAAId,OAAJ,EAAaC,OAAb,CADT,CAAP;AAGD;AACF,CAjBD;;AAkBA,MAAMc,UAAU,GAAG,CACjBtB,MADiB,EAEjBuB,MAFiB,KAGd;AACH,QAAM,CAACC,IAAD,EAAOC,OAAP,IAAkB,qBAAmB,IAAnB,CAAxB;AACA,wBAAU,MAAM;AACdF,IAAAA,MAAM,GAAGH,IAAT,
|
1
|
+
{"version":3,"sources":["Data.ts"],"names":["resolveAsset","source","Image","resolveAssetSource","uri","default","factoryWrapper","data2","factory","onError","factoryResult","Error","loadData","undefined","Promise","resolve","Uint8Array","Skia","Data","fromBytes","fromURI","then","d","useLoading","loader","mounted","data","setData","current","value","useRawData","identity","useData"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;AACA;;AAGA,MAAMA,YAAY,GAAIC,MAAD,IAAwB;AAC3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O,GAAG,mBAAO,KAAP,CAAhB;AACA,QAAM,CAACC,IAAD,EAAOC,OAAP,IAAkB,qBAAmB,IAAnB,CAAxB;AACA,wBAAU,MAAM;AACdF,IAAAA,OAAO,CAACG,OAAR,GAAkB,IAAlB;AACAJ,IAAAA,MAAM,GAAGH,IAAT,CAAeQ,KAAD,IAAW;AACvB,UAAIJ,OAAO,CAACG,OAAZ,EAAqB;AACnBD,QAAAA,OAAO,CAACE,KAAD,CAAP;AACD;AACF,KAJD;AAKA,WAAO,MAAM;AACXJ,MAAAA,OAAO,CAACG,OAAR,GAAkB,KAAlB;AACD,KAFD,CAPc,CAUd;AACD,GAXD,EAWG,CAAC3B,MAAD,CAXH;AAYA,SAAOyB,IAAP;AACD,CAnBD;;AAqBO,MAAMI,UAAU,GAAG,CACxB7B,MADwB,EAExBO,OAFwB,EAGxBC,OAHwB,KAIrBc,UAAU,CAACtB,MAAD,EAAS,MAAMW,QAAQ,CAACX,MAAD,EAASO,OAAT,EAAkBC,OAAlB,CAAvB,CAJR;;;;AAMP,MAAMsB,QAAQ,GAAIL,IAAD,IAAkBA,IAAnC;;AAEO,MAAMM,OAAO,GAAG,CACrB/B,MADqB,EAErBQ,OAFqB,KAGlBqB,UAAU,CAAC7B,MAAD,EAAS8B,QAAT,EAAmBtB,OAAnB,CAHR","sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { Image } from \"react-native\";\n\nimport { Skia } from \"../Skia\";\nimport { isRNModule } from \"../types\";\nimport type { SkData, DataModule, DataSourceParam } from \"../types\";\n\nconst resolveAsset = (source: DataModule) => {\n return isRNModule(source)\n ? Image.resolveAssetSource(source).uri\n : source.default;\n};\n\nconst factoryWrapper = <T>(\n data2: SkData,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n) => {\n const factoryResult = factory(data2);\n if (factoryResult === null) {\n onError && onError(new Error(\"Could not load data\"));\n return null;\n } else {\n return factoryResult;\n }\n};\n\nconst loadData = <T>(\n source: DataSourceParam,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n): Promise<T | null> => {\n if (source === null || source === undefined) {\n return new Promise((resolve) => resolve(null));\n } else if (source instanceof Uint8Array) {\n return new Promise((resolve) =>\n resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError))\n );\n } else {\n const uri = typeof source === \"string\" ? source : resolveAsset(source);\n return Skia.Data.fromURI(uri).then((d) =>\n factoryWrapper(d, factory, onError)\n );\n }\n};\nconst useLoading = <T>(\n source: DataSourceParam,\n loader: () => Promise<T | null>\n) => {\n const mounted = useRef(false);\n const [data, setData] = useState<T | null>(null);\n useEffect(() => {\n mounted.current = true;\n loader().then((value) => {\n if (mounted.current) {\n setData(value);\n }\n });\n return () => {\n mounted.current = false;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [source]);\n return data;\n};\n\nexport const useRawData = <T>(\n source: DataSourceParam,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n) => useLoading(source, () => loadData(source, factory, onError));\n\nconst identity = (data: SkData) => data;\n\nexport const useData = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => useRawData(source, identity, onError);\n"]}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { useEffect, useState } from "react";
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
2
2
|
import { Image } from "react-native";
|
3
3
|
import { Skia } from "../Skia";
|
4
4
|
import { isRNModule } from "../types";
|
@@ -30,9 +30,18 @@ const loadData = (source, factory, onError) => {
|
|
30
30
|
};
|
31
31
|
|
32
32
|
const useLoading = (source, loader) => {
|
33
|
+
const mounted = useRef(false);
|
33
34
|
const [data, setData] = useState(null);
|
34
35
|
useEffect(() => {
|
35
|
-
|
36
|
+
mounted.current = true;
|
37
|
+
loader().then(value => {
|
38
|
+
if (mounted.current) {
|
39
|
+
setData(value);
|
40
|
+
}
|
41
|
+
});
|
42
|
+
return () => {
|
43
|
+
mounted.current = false;
|
44
|
+
}; // eslint-disable-next-line react-hooks/exhaustive-deps
|
36
45
|
}, [source]);
|
37
46
|
return data;
|
38
47
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["Data.ts"],"names":["useEffect","useState","Image","Skia","isRNModule","resolveAsset","source","resolveAssetSource","uri","default","factoryWrapper","data2","factory","onError","factoryResult","Error","loadData","undefined","Promise","resolve","Uint8Array","Data","fromBytes","fromURI","then","d","useLoading","loader","data","setData","useRawData","identity","useData"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,
|
1
|
+
{"version":3,"sources":["Data.ts"],"names":["useEffect","useRef","useState","Image","Skia","isRNModule","resolveAsset","source","resolveAssetSource","uri","default","factoryWrapper","data2","factory","onError","factoryResult","Error","loadData","undefined","Promise","resolve","Uint8Array","Data","fromBytes","fromURI","then","d","useLoading","loader","mounted","data","setData","current","value","useRawData","identity","useData"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,MAApB,EAA4BC,QAA5B,QAA4C,OAA5C;AACA,SAASC,KAAT,QAAsB,cAAtB;AAEA,SAASC,IAAT,QAAqB,SAArB;AACA,SAASC,UAAT,QAA2B,UAA3B;;AAGA,MAAMC,YAAY,GAAIC,MAAD,IAAwB;AAC3C,SAAOF,UAAU,CAACE,MAAD,CAAV,GACHJ,KAAK,CAACK,kBAAN,CAAyBD,MAAzB,EAAiCE,GAD9B,GAEHF,MAAM,CAACG,OAFX;AAGD,CAJD;;AAMA,MAAMC,cAAc,GAAG,CACrBC,KADqB,EAErBC,OAFqB,EAGrBC,OAHqB,KAIlB;AACH,QAAMC,aAAa,GAAGF,OAAO,CAACD,KAAD,CAA7B;;AACA,MAAIG,aAAa,KAAK,IAAtB,EAA4B;AAC1BD,IAAAA,OAAO,IAAIA,OAAO,CAAC,IAAIE,KAAJ,CAAU,qBAAV,CAAD,CAAlB;AACA,WAAO,IAAP;AACD,GAHD,MAGO;AACL,WAAOD,aAAP;AACD;AACF,CAZD;;AAcA,MAAME,QAAQ,GAAG,CACfV,MADe,EAEfM,OAFe,EAGfC,OAHe,KAIO;AACtB,MAA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BD;;AAqBA,OAAO,MAAMI,UAAU,GAAG,CACxB3B,MADwB,EAExBM,OAFwB,EAGxBC,OAHwB,KAIrBa,UAAU,CAACpB,MAAD,EAAS,MAAMU,QAAQ,CAACV,MAAD,EAASM,OAAT,EAAkBC,OAAlB,CAAvB,CAJR;;AAMP,MAAMqB,QAAQ,GAAIL,IAAD,IAAkBA,IAAnC;;AAEA,OAAO,MAAMM,OAAO,GAAG,CACrB7B,MADqB,EAErBO,OAFqB,KAGlBoB,UAAU,CAAC3B,MAAD,EAAS4B,QAAT,EAAmBrB,OAAnB,CAHR","sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { Image } from \"react-native\";\n\nimport { Skia } from \"../Skia\";\nimport { isRNModule } from \"../types\";\nimport type { SkData, DataModule, DataSourceParam } from \"../types\";\n\nconst resolveAsset = (source: DataModule) => {\n return isRNModule(source)\n ? Image.resolveAssetSource(source).uri\n : source.default;\n};\n\nconst factoryWrapper = <T>(\n data2: SkData,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n) => {\n const factoryResult = factory(data2);\n if (factoryResult === null) {\n onError && onError(new Error(\"Could not load data\"));\n return null;\n } else {\n return factoryResult;\n }\n};\n\nconst loadData = <T>(\n source: DataSourceParam,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n): Promise<T | null> => {\n if (source === null || source === undefined) {\n return new Promise((resolve) => resolve(null));\n } else if (source instanceof Uint8Array) {\n return new Promise((resolve) =>\n resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError))\n );\n } else {\n const uri = typeof source === \"string\" ? source : resolveAsset(source);\n return Skia.Data.fromURI(uri).then((d) =>\n factoryWrapper(d, factory, onError)\n );\n }\n};\nconst useLoading = <T>(\n source: DataSourceParam,\n loader: () => Promise<T | null>\n) => {\n const mounted = useRef(false);\n const [data, setData] = useState<T | null>(null);\n useEffect(() => {\n mounted.current = true;\n loader().then((value) => {\n if (mounted.current) {\n setData(value);\n }\n });\n return () => {\n mounted.current = false;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [source]);\n return data;\n};\n\nexport const useRawData = <T>(\n source: DataSourceParam,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n) => useLoading(source, () => loadData(source, factory, onError));\n\nconst identity = (data: SkData) => data;\n\nexport const useData = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => useRawData(source, identity, onError);\n"]}
|
package/package.json
CHANGED
package/src/skia/core/Data.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { useEffect, useState } from "react";
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
2
2
|
import { Image } from "react-native";
|
3
3
|
|
4
4
|
import { Skia } from "../Skia";
|
@@ -47,9 +47,18 @@ const useLoading = <T>(
|
|
47
47
|
source: DataSourceParam,
|
48
48
|
loader: () => Promise<T | null>
|
49
49
|
) => {
|
50
|
+
const mounted = useRef(false);
|
50
51
|
const [data, setData] = useState<T | null>(null);
|
51
52
|
useEffect(() => {
|
52
|
-
|
53
|
+
mounted.current = true;
|
54
|
+
loader().then((value) => {
|
55
|
+
if (mounted.current) {
|
56
|
+
setData(value);
|
57
|
+
}
|
58
|
+
});
|
59
|
+
return () => {
|
60
|
+
mounted.current = false;
|
61
|
+
};
|
53
62
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
54
63
|
}, [source]);
|
55
64
|
return data;
|