react-native-windows 0.74.0-preview.2 → 0.74.0-preview.3

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.
@@ -17,7 +17,7 @@ const version: $ReadOnly<{
17
17
  major: 0,
18
18
  minor: 74,
19
19
  patch: 0,
20
- prerelease: 'rc.6',
20
+ prerelease: 'rc.9',
21
21
  };
22
22
 
23
23
  module.exports = {version};
@@ -0,0 +1,186 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ export type ResolvedAssetSource = {|
14
+ +__packager_asset: boolean,
15
+ +width: ?number,
16
+ +height: ?number,
17
+ +uri: string,
18
+ +scale: number,
19
+ |};
20
+
21
+ import type {PackagerAsset} from '@react-native/assets-registry/registry';
22
+
23
+ const PixelRatio = require('../Utilities/PixelRatio').default;
24
+ const Platform = require('../Utilities/Platform');
25
+ const {pickScale} = require('./AssetUtils');
26
+ const {
27
+ getAndroidResourceFolderName,
28
+ getAndroidResourceIdentifier,
29
+ } = require('@react-native/assets-registry/path-support');
30
+ const invariant = require('invariant');
31
+ // $FlowFixMe[untyped-import]
32
+ const ensureShortPath = require('./assetPaths.js'); // [Windows]
33
+
34
+ // [Windows - instead of using basePath from @react-native/assets-registry/path-support]
35
+ function getBasePath(asset: PackagerAsset, local: boolean) {
36
+ let basePath = asset.httpServerLocation;
37
+ if (basePath[0] === '/') {
38
+ basePath = basePath.substr(1);
39
+ }
40
+
41
+ if (local) {
42
+ const safePath = basePath.replace(/\.\.\//g, '_');
43
+ // If this asset was created with saveAssetPlugin, then we should shorten the path
44
+ // This conditional allow compat of bundles which might have been created without the saveAssetPlugin
45
+ // $FlowFixMe: __useShortPath not part of public type
46
+ if (asset.__useShortPath) {
47
+ return ensureShortPath(safePath);
48
+ }
49
+ return safePath;
50
+ }
51
+
52
+ return basePath;
53
+ }
54
+
55
+ /**
56
+ * Returns a path like 'assets/AwesomeModule/icon@2x.png'
57
+ */
58
+ function getScaledAssetPath(asset: PackagerAsset, local: boolean): string {
59
+ const scale = pickScale(asset.scales, PixelRatio.get());
60
+ const scaleSuffix = scale === 1 ? '' : '@' + scale + 'x';
61
+ const assetDir = getBasePath(asset, local);
62
+ return assetDir + '/' + asset.name + scaleSuffix + '.' + asset.type;
63
+ }
64
+
65
+ /**
66
+ * Returns a path like 'drawable-mdpi/icon.png'
67
+ */
68
+ function getAssetPathInDrawableFolder(asset: PackagerAsset): string {
69
+ const scale = pickScale(asset.scales, PixelRatio.get());
70
+ const drawableFolder = getAndroidResourceFolderName(asset, scale);
71
+ const fileName = getAndroidResourceIdentifier(asset);
72
+ return drawableFolder + '/' + fileName + '.' + asset.type;
73
+ }
74
+
75
+ class AssetSourceResolver {
76
+ serverUrl: ?string;
77
+ // where the jsbundle is being run from
78
+ jsbundleUrl: ?string;
79
+ // the asset to resolve
80
+ asset: PackagerAsset;
81
+
82
+ constructor(serverUrl: ?string, jsbundleUrl: ?string, asset: PackagerAsset) {
83
+ this.serverUrl = serverUrl;
84
+ this.jsbundleUrl = jsbundleUrl;
85
+ this.asset = asset;
86
+ }
87
+
88
+ isLoadedFromServer(): boolean {
89
+ return !!this.serverUrl;
90
+ }
91
+
92
+ isLoadedFromFileSystem(): boolean {
93
+ return this.jsbundleUrl != null && this.jsbundleUrl?.startsWith('file://');
94
+ }
95
+
96
+ defaultAsset(): ResolvedAssetSource {
97
+ if (this.isLoadedFromServer()) {
98
+ return this.assetServerURL();
99
+ }
100
+
101
+ if (Platform.OS === 'android') {
102
+ return this.isLoadedFromFileSystem()
103
+ ? this.drawableFolderInBundle()
104
+ : this.resourceIdentifierWithoutScale();
105
+ } else {
106
+ return this.scaledAssetURLNearBundle();
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Returns an absolute URL which can be used to fetch the asset
112
+ * from the devserver
113
+ */
114
+ assetServerURL(): ResolvedAssetSource {
115
+ invariant(this.serverUrl != null, 'need server to load from');
116
+ return this.fromSource(
117
+ this.serverUrl +
118
+ getScaledAssetPath(this.asset, false) +
119
+ '?platform=' +
120
+ Platform.OS +
121
+ '&hash=' +
122
+ this.asset.hash,
123
+ );
124
+ }
125
+
126
+ /**
127
+ * Resolves to just the scaled asset filename
128
+ * E.g. 'assets/AwesomeModule/icon@2x.png'
129
+ */
130
+ scaledAssetPath(local: boolean): ResolvedAssetSource {
131
+ return this.fromSource(getScaledAssetPath(this.asset, local));
132
+ }
133
+
134
+ /**
135
+ * Resolves to where the bundle is running from, with a scaled asset filename
136
+ * E.g. 'file:///sdcard/bundle/assets/AwesomeModule/icon@2x.png'
137
+ */
138
+ scaledAssetURLNearBundle(): ResolvedAssetSource {
139
+ const path = this.jsbundleUrl ?? 'file://';
140
+ return this.fromSource(
141
+ // Assets can have relative paths outside of the project root.
142
+ // When bundling them we replace `../` with `_` to make sure they
143
+ // don't end up outside of the expected assets directory.
144
+ path + getScaledAssetPath(this.asset, true).replace(/\.\.\//g, '_'),
145
+ );
146
+ }
147
+
148
+ /**
149
+ * The default location of assets bundled with the app, located by
150
+ * resource identifier
151
+ * The Android resource system picks the correct scale.
152
+ * E.g. 'assets_awesomemodule_icon'
153
+ */
154
+ resourceIdentifierWithoutScale(): ResolvedAssetSource {
155
+ invariant(
156
+ Platform.OS === 'android',
157
+ 'resource identifiers work on Android',
158
+ );
159
+ return this.fromSource(getAndroidResourceIdentifier(this.asset));
160
+ }
161
+
162
+ /**
163
+ * If the jsbundle is running from a sideload location, this resolves assets
164
+ * relative to its location
165
+ * E.g. 'file:///sdcard/AwesomeModule/drawable-mdpi/icon.png'
166
+ */
167
+ drawableFolderInBundle(): ResolvedAssetSource {
168
+ const path = this.jsbundleUrl ?? 'file://';
169
+ return this.fromSource(path + getAssetPathInDrawableFolder(this.asset));
170
+ }
171
+
172
+ fromSource(source: string): ResolvedAssetSource {
173
+ return {
174
+ __packager_asset: true,
175
+ width: this.asset.width,
176
+ height: this.asset.height,
177
+ uri: source,
178
+ scale: pickScale(this.asset.scales, PixelRatio.get()),
179
+ };
180
+ }
181
+
182
+ static pickScale: (scales: Array<number>, deviceScale?: number) => number =
183
+ pickScale;
184
+ }
185
+
186
+ module.exports = AssetSourceResolver;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ *
5
+ * Dont use flow here, since this file is used by saveAssetPlugin.js which will run without flow transform
6
+ * @format
7
+ */
8
+
9
+ 'use strict';
10
+
11
+ // Some windows machines may not have long paths enabled
12
+ // https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
13
+ // Assets in nested node_modules (common when using pnpm) - end up creating very long paths
14
+ // Using this function we shorten longer paths to prevent paths from hitting the path limit
15
+ function ensureShortPath(str) {
16
+ if (str.length < 40) return str;
17
+
18
+ const assetsPrefix = 'assets/';
19
+
20
+ if (!str.startsWith(assetsPrefix)) {
21
+ console.warn(`Unexpected asset uri - ${str} may not load correctly.`);
22
+ }
23
+
24
+ const postStr = str.slice(assetsPrefix.length);
25
+ var hash = 0,
26
+ i,
27
+ chr;
28
+ for (i = 0; i < postStr.length; i++) {
29
+ chr = postStr.charCodeAt(i);
30
+ hash = (hash << 5) - hash + chr;
31
+ hash |= 0; // Convert to 32bit integer
32
+ }
33
+ return assetsPrefix + hash.toString();
34
+ }
35
+
36
+ module.exports = ensureShortPath;
@@ -10,11 +10,11 @@
10
10
  -->
11
11
  <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
12
12
  <PropertyGroup>
13
- <ReactNativeWindowsVersion>0.74.0-preview.2</ReactNativeWindowsVersion>
13
+ <ReactNativeWindowsVersion>0.74.0-preview.3</ReactNativeWindowsVersion>
14
14
  <ReactNativeWindowsMajor>0</ReactNativeWindowsMajor>
15
15
  <ReactNativeWindowsMinor>74</ReactNativeWindowsMinor>
16
16
  <ReactNativeWindowsPatch>0</ReactNativeWindowsPatch>
17
17
  <ReactNativeWindowsCanary>false</ReactNativeWindowsCanary>
18
- <ReactNativeWindowsCommitId>5f10e604924b47b0baa64825d8770be4e3a074b1</ReactNativeWindowsCommitId>
18
+ <ReactNativeWindowsCommitId>a7fbde79bab1d8ce811614bfaa5d2770d6c69041</ReactNativeWindowsCommitId>
19
19
  </PropertyGroup>
20
20
  </Project>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-windows",
3
- "version": "0.74.0-preview.2",
3
+ "version": "0.74.0-preview.3",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,13 +28,13 @@
28
28
  "@react-native-community/cli-platform-ios": "13.6.4",
29
29
  "@react-native-windows/cli": "0.74.0-preview.2",
30
30
  "@react-native/assets": "1.0.0",
31
- "@react-native/assets-registry": "0.74.77",
32
- "@react-native/codegen": "0.74.77",
33
- "@react-native/community-cli-plugin": "0.74.77",
34
- "@react-native/gradle-plugin": "0.74.77",
35
- "@react-native/js-polyfills": "0.74.77",
36
- "@react-native/normalize-colors": "0.74.77",
37
- "@react-native/virtualized-lists": "0.74.77",
31
+ "@react-native/assets-registry": "0.74.80",
32
+ "@react-native/codegen": "0.74.80",
33
+ "@react-native/community-cli-plugin": "0.74.80",
34
+ "@react-native/gradle-plugin": "0.74.80",
35
+ "@react-native/js-polyfills": "0.74.80",
36
+ "@react-native/normalize-colors": "0.74.80",
37
+ "@react-native/virtualized-lists": "0.74.80",
38
38
  "abort-controller": "^3.0.0",
39
39
  "anser": "^1.4.9",
40
40
  "ansi-regex": "^5.0.0",
@@ -65,7 +65,7 @@
65
65
  },
66
66
  "devDependencies": {
67
67
  "@react-native-windows/codegen": "0.74.0-preview.1",
68
- "@react-native/metro-config": "0.74.77",
68
+ "@react-native/metro-config": "0.74.80",
69
69
  "@rnw-scripts/babel-react-native-config": "0.0.0",
70
70
  "@rnw-scripts/eslint-config": "1.2.9",
71
71
  "@rnw-scripts/jest-out-of-tree-snapshot-resolver": "^1.1.13",
@@ -81,7 +81,7 @@
81
81
  "just-scripts": "^1.3.3",
82
82
  "prettier": "2.8.8",
83
83
  "react": "18.2.0",
84
- "react-native": "0.74.0-rc.6",
84
+ "react-native": "0.74.0-rc.9",
85
85
  "react-native-platform-override": "^1.9.25",
86
86
  "react-refresh": "^0.14.0",
87
87
  "typescript": "5.0.4"
@@ -89,7 +89,7 @@
89
89
  "peerDependencies": {
90
90
  "@types/react": "^18.2.6",
91
91
  "react": "18.2.0",
92
- "react-native": "0.74.0-rc.6"
92
+ "react-native": "0.74.0-rc.9"
93
93
  },
94
94
  "beachball": {
95
95
  "defaultNpmTag": "preview",