-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path@shopify+react-native-skia+0.1.221.patch
122 lines (115 loc) · 4.67 KB
/
@shopify+react-native-skia+0.1.221.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
diff --git a/node_modules/@shopify/react-native-skia/lib/module/Platform/Platform.web.js b/node_modules/@shopify/react-native-skia/lib/module/Platform/Platform.web.js
index 95b7ee2..be77fcc 100644
--- a/node_modules/@shopify/react-native-skia/lib/module/Platform/Platform.web.js
+++ b/node_modules/@shopify/react-native-skia/lib/module/Platform/Platform.web.js
@@ -123,9 +123,17 @@ const View = _ref => {
export const Platform = {
OS: "web",
- PixelRatio: window.devicePixelRatio,
+ PixelRatio: typeof window !== "undefined" ? window.devicePixelRatio : 1,
resolveAsset: source => {
if (isRNModule(source)) {
+ if (typeof source === "number" && typeof require === "function") {
+ const {
+ getAssetByID,
+ } = require("react-native/Libraries/Image/AssetRegistry");
+ const { httpServerLocation, name, type } = getAssetByID(source);
+ const uri = `${httpServerLocation}/${name}.${type}`;
+ return uri;
+ }
throw new Error("Image source is a number - this is not supported on the web");
}
diff --git a/node_modules/@shopify/react-native-skia/scripts/setup-canvaskit.js b/node_modules/@shopify/react-native-skia/scripts/setup-canvaskit.js
index c151639..c25ff97 100755
--- a/node_modules/@shopify/react-native-skia/scripts/setup-canvaskit.js
+++ b/node_modules/@shopify/react-native-skia/scripts/setup-canvaskit.js
@@ -7,6 +7,7 @@
* In `@expo/webpack-config` this is `./web` (default for now).
*
* This script does the following:
+ * 0. Try to detect if it's an expo project and if the bundler is set to metro
* 1. Resolve the public path relative to wherever the script is being run.
* 2. Log out some useful info about the web setup, just in case anything goes wrong.
* 3. Resolve the installed wasm file `canvaskit-wasm/bin/full/canvaskit.wasm`
@@ -15,14 +16,18 @@
*
*
* Usage:
- * $ `npx <script> web`
+ * $ `npx <script>`
*
+ * On webpack:
* -> Copies the file to `<project>/web/static/js/canvaskit.wasm`
+ * on metro:
+ * -> Copies the file to `<project>/public/canvaskit.wasm`
*
- * Tooling that uses `/public`:
- * $ `npx <script> public`
+ * Tooling that uses a custom static assets folder, like `/assets` for example:
+ * $ `npx <script> assets`
+ *
+ * -> Copies the file to `<project>/assets/canvaskit.wasm`
*
- * -> Copies the file to `<project>/public/static/js/canvaskit.wasm`
*/
const fs = require("fs");
const path = require("path");
@@ -32,6 +37,29 @@ const args = process.argv.slice(2);
const gray = (text) => `\x1b[90m${text}\x1b[0m`;
const lime = (text) => `\x1b[32m${text}\x1b[0m`;
+function getWetherItsAnExpoProjectWithMetro() {
+ try {
+ const appJsonPath = path.join(process.cwd(), 'app.json');
+
+ console.log(
+ `› Reading Expo settings from (if any):\n ${gray(appJsonPath)}`
+ );
+
+ const appJson = require(appJsonPath);
+ const isAnExpoProjectWithMetro = appJson.expo && appJson.expo.web && appJson.expo.web.bundler === 'metro';
+ if (isAnExpoProjectWithMetro) {
+ console.log(` ${gray(`Expo project with metro bundler detected`)}\n`);
+ return true;
+ } else {
+ console.log(` ${gray(`Metro bundler not detected. Assuming the project is using Webpack.`)}\n`);
+ return false;
+ }
+ } catch (error) {
+ console.log(` ${gray(`No Expo settings found`)}\n`);
+ return false;
+ }
+}
+
function getWasmFilePath() {
try {
return require.resolve("canvaskit-wasm/bin/full/canvaskit.wasm");
@@ -43,14 +71,14 @@ function getWasmFilePath() {
}
}
-function getOutputFilePath() {
+function getOutputFilePath(isAnExpoProjectWithMetro) {
// Default to using `web` public path.
- const publicFolder = path.resolve(args[0] || "web");
- const publicLocation = "./static/js/canvaskit.wasm";
+ const publicFolder = path.resolve(args[0] || (isAnExpoProjectWithMetro) ? "public" : "web/static/js");
+ const publicLocation = "./canvaskit.wasm";
const output = path.join(publicFolder, publicLocation);
console.log(
- `› Copying 'canvaskit.wasm' file to static folder:\n ${gray(output)}\n`
+ `› Copying 'canvaskit.wasm' file to public folder:\n ${gray(output)}\n`
);
return output;
}
@@ -61,9 +89,12 @@ function copyFile(from, to) {
fs.writeFileSync(to, data);
}
-// Copy the WASM file to `<static>/static/js/canvaskit.wasm`
(() => {
- copyFile(getWasmFilePath(), getOutputFilePath());
+ // Automatically detect if it's an expo project with a metro bundler
+ const isAnExpoProjectWithMetro = getWetherItsAnExpoProjectWithMetro();
+
+ // Copy the WASM file to `<static>/canvaskit.wasm`
+ copyFile(getWasmFilePath(), getOutputFilePath(isAnExpoProjectWithMetro));
console.log(lime("› Success! You are almost there:"));
console.log(