@react-native-oh/react-native-harmony 0.72.82 → 0.77.18

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 (81) hide show
  1. package/LICENSE +21 -0
  2. package/LICENSE-Meta +21 -0
  3. package/Libraries/Alert/delegates/AlertDelegate.harmony.ts +84 -0
  4. package/Libraries/Alert/{AlertManager.ts → delegates/AlertManager.harmony.ts} +10 -4
  5. package/Libraries/Animated/shouldUseTurboAnimatedModule.harmony.ts +10 -0
  6. package/Libraries/Components/AccessibilityInfo/delegates/AccessibilityInfoDelegate.harmony.ts +44 -0
  7. package/Libraries/Components/AccessibilityInfo/{NativeAccessibilityInfoHarmony.ts → delegates/NativeAccessibilityInfoHarmony.harmony.ts} +9 -2
  8. package/Libraries/Components/Keyboard/delegates/KeyboardAvoidingViewDelegate.harmony.ts +42 -0
  9. package/Libraries/Components/RefreshControl/delegates/RefreshControlDelegate.harmony.tsx +29 -0
  10. package/Libraries/Components/SafeAreaView/SafeAreaView.harmony.tsx +93 -31
  11. package/Libraries/Components/ScrollView/delegates/ScrollViewDelegate.harmony.tsx +41 -0
  12. package/Libraries/Components/ScrollView/delegates/ScrollViewNativeComponentDelegate.harmony.ts +89 -0
  13. package/Libraries/Components/ScrollView/processDecelerationRate.harmony.ts +19 -0
  14. package/Libraries/Components/StatusBar/delegates/NativeStatusBarManagerHarmony.harmony.ts +53 -0
  15. package/Libraries/Components/StatusBar/delegates/StatusBarDelegate.harmony.ts +83 -0
  16. package/Libraries/Components/TextInput/delegates/TextInputDelegate.harmony.tsx +98 -0
  17. package/Libraries/Components/TextInput/delegates/TextInputStateDelegate.harmony.tsx +20 -0
  18. package/Libraries/Components/Touchable/delegates/TouchableHighlightDelegate.harmony.ts +14 -0
  19. package/Libraries/Components/Touchable/delegates/TouchableNativeFeedbackDelegate.harmony.ts +14 -0
  20. package/Libraries/Components/Touchable/delegates/TouchableWithoutFeedbackDelegate.harmony.ts +14 -0
  21. package/Libraries/Components/delegates/ButtonDelegate.harmony.ts +41 -0
  22. package/Libraries/Core/setUpPlatform.harmony.js +30 -0
  23. package/Libraries/Image/AssetSourceResolver.harmony.ts +75 -29
  24. package/Libraries/Image/Image.harmony.ts +17 -0
  25. package/Libraries/NativeComponent/BaseViewConfig.harmony.js +12 -326
  26. package/Libraries/NativeComponent/delegates/ViewConfigIgnoreDelegate.harmony.ts +13 -0
  27. package/Libraries/ReactNative/delegates/BridgelessUIManagerDelegate.harmony.ts +14 -0
  28. package/Libraries/ReactNative/delegates/I18nManagerDelegate.harmony.ts +22 -0
  29. package/Libraries/Settings/Settings.harmony.ts +20 -0
  30. package/Libraries/Share/delegates/ShareDelegate.harmony.ts +42 -0
  31. package/Libraries/StyleSheet/NativePlatformColor.harmony.ts +15 -0
  32. package/Libraries/StyleSheet/PlatformColorValueTypes.harmony.ts +8 -1
  33. package/Libraries/Utilities/BackHandler.harmony.ts +10 -0
  34. package/Libraries/Utilities/NativePlatformConstantsHarmony.harmony.ts +17 -0
  35. package/Libraries/Utilities/Platform.harmony.ts +38 -13
  36. package/Libraries/Vibration/delegates/VibrationDelegate.harmony.ts +14 -0
  37. package/NOTICE.md +846 -0
  38. package/README.md +2 -2
  39. package/index.js +53 -63
  40. package/jest.config.js +0 -7
  41. package/metro.config.d.ts +17 -0
  42. package/metro.config.js +398 -115
  43. package/package.json +58 -37
  44. package/react-native.config.js +57 -9
  45. package/react_native_openharmony.har +0 -0
  46. package/tsconfig.json +10 -4
  47. package/types/index.harmony.d.ts +99 -0
  48. package/Libraries/Alert/Alert.harmony.js +0 -77
  49. package/Libraries/Animated/NativeAnimatedHelper.harmony.js +0 -601
  50. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.harmony.js +0 -441
  51. package/Libraries/Components/Button/Button.harmony.js +0 -451
  52. package/Libraries/Components/Image/Image.flow.harmony.js +0 -53
  53. package/Libraries/Components/Image/Image.harmony.js +0 -317
  54. package/Libraries/Components/Image/NativeImageLoaderHarmony.js +0 -38
  55. package/Libraries/Components/Keyboard/KeyboardAvoidingView.harmony.js +0 -256
  56. package/Libraries/Components/RefreshControl/RefreshControl.harmony.js +0 -210
  57. package/Libraries/Components/ScrollView/ScrollView.harmony.js +0 -1951
  58. package/Libraries/Components/ScrollView/processDecelerationRate.harmony.js +0 -24
  59. package/Libraries/Components/StatusBar/NativeStatusBarManagerHarmony.js +0 -71
  60. package/Libraries/Components/StatusBar/StatusBar.harmony.js +0 -447
  61. package/Libraries/Components/TextInput/TextInput.harmony.js +0 -1716
  62. package/Libraries/Components/TextInput/TextInputState.harmony.js +0 -220
  63. package/Libraries/Components/Touchable/TouchableHighlight.harmony.js +0 -396
  64. package/Libraries/Components/Touchable/TouchableNativeFeedback.harmony.js +0 -364
  65. package/Libraries/Components/Touchable/TouchableWithoutFeedback.harmony.js +0 -227
  66. package/Libraries/Components/View/View.harmony.js +0 -149
  67. package/Libraries/Core/setUpReactDevTools.harmony.js +0 -93
  68. package/Libraries/ReactNative/I18nManager.harmony.js +0 -78
  69. package/Libraries/ReactNative/UIManager.harmony.js +0 -210
  70. package/Libraries/Settings/Settings.harmony.js +0 -15
  71. package/Libraries/Share/Share.harmony.js +0 -174
  72. package/Libraries/StyleSheet/NativePlatformColor.ts +0 -8
  73. package/Libraries/Utilities/BackHandler.harmony.js +0 -109
  74. package/Libraries/Utilities/NativePlatformConstants.harmony.ts +0 -8
  75. package/Libraries/Utilities/Platform.d.ts +0 -117
  76. package/Libraries/Utilities/createPerformanceLogger.harmony.js +0 -328
  77. package/Libraries/Vibration/Vibration.harmony.js +0 -88
  78. package/harmony/.keep +0 -0
  79. package/harmony/rnoh-hvigor-plugin-0.2.0.tgz +0 -0
  80. package/react_native_openharmony_release.har +0 -0
  81. package/types/index.d.ts +0 -108
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Copyright (c) 2024 Huawei Technologies Co., Ltd.
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
+
8
+ import * as TurboModuleRegistry from '../../../TurboModule/TurboModuleRegistry';
9
+ import type { TurboModule } from '../../../TurboModule/RCTExport';
10
+
11
+ type NativeStatusBarManagerConstants = {
12
+ HEIGHT: number;
13
+ DEFAULT_BACKGROUND_COLOR?: string;
14
+ };
15
+
16
+ export interface Spec extends TurboModule {
17
+ getConstants: () => NativeStatusBarManagerConstants;
18
+ setColor: (color: number, animated: boolean) => void;
19
+ setTranslucent: (translucent: boolean) => void;
20
+ setStyle: (statusBarStyle: string) => void;
21
+ setHidden: (hidden: boolean) => void;
22
+ }
23
+
24
+ const NativeModule = TurboModuleRegistry.getEnforcing<Spec>('StatusBarManager');
25
+
26
+ let constants: NativeStatusBarManagerConstants | null = null;
27
+
28
+ const NativeStatusBarManager: Spec = {
29
+ getConstants(): NativeStatusBarManagerConstants {
30
+ if (constants == null) {
31
+ constants = NativeModule.getConstants();
32
+ }
33
+ return constants;
34
+ },
35
+
36
+ setColor(color: number, animated: boolean): void {
37
+ NativeModule.setColor(color, animated);
38
+ },
39
+
40
+ setTranslucent(translucent: boolean): void {
41
+ NativeModule.setTranslucent(translucent);
42
+ },
43
+
44
+ setStyle(statusBarStyle: string): void {
45
+ NativeModule.setStyle(statusBarStyle);
46
+ },
47
+
48
+ setHidden(hidden: boolean): void {
49
+ NativeModule.setHidden(hidden);
50
+ },
51
+ };
52
+
53
+ export default NativeStatusBarManager;
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Copyright (c) 2024 Huawei Technologies Co., Ltd.
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
+
8
+ import {
9
+ BaseStatusBarDelegate,
10
+ StatusBarAnimation,
11
+ StatusBarStyle,
12
+ } from './BaseStatusBarDelegate';
13
+ import NativeStatusBarManagerHarmony from './NativeStatusBarManagerHarmony.harmony';
14
+ import invariant from 'invariant';
15
+ import processColor from '../../../StyleSheet/processColor';
16
+
17
+ export default class StatusBarDelegate extends BaseStatusBarDelegate {
18
+ override getCurrentHeight(): number {
19
+ return NativeStatusBarManagerHarmony.getConstants().HEIGHT;
20
+ }
21
+
22
+ override getDefaultBackgroundColor(): string {
23
+ return (
24
+ NativeStatusBarManagerHarmony.getConstants().DEFAULT_BACKGROUND_COLOR ??
25
+ 'black'
26
+ );
27
+ }
28
+
29
+ override setBarStyle(style: StatusBarStyle, animated?: boolean): void {
30
+ NativeStatusBarManagerHarmony.setStyle(style);
31
+ }
32
+
33
+ override setColor(processedColor: number, animated?: boolean): void {
34
+ NativeStatusBarManagerHarmony.setColor(processedColor, animated ?? false);
35
+ }
36
+
37
+ override setHidden(hidden: boolean, animation?: StatusBarAnimation): void {
38
+ NativeStatusBarManagerHarmony.setHidden(hidden);
39
+ }
40
+
41
+ override setNetworkActivityIndicatorVisible(visible: boolean): void {
42
+ // NOOP
43
+ return;
44
+ }
45
+
46
+ override setTranslucent(translucent: boolean): void {
47
+ NativeStatusBarManagerHarmony.setTranslucent(translucent);
48
+ }
49
+
50
+ override updatePropsStack(oldProps: any, newProps: any): void {
51
+ if (!oldProps || oldProps.hidden.value !== newProps.hidden.value) {
52
+ NativeStatusBarManagerHarmony.setHidden(newProps.hidden.value);
53
+ }
54
+ if (!oldProps || oldProps.barStyle.value !== newProps.barStyle.value) {
55
+ NativeStatusBarManagerHarmony.setStyle(newProps.barStyle.value);
56
+ }
57
+ if (!oldProps || oldProps.translucent !== newProps.translucent) {
58
+ NativeStatusBarManagerHarmony.setTranslucent(newProps.translucent);
59
+ }
60
+ if (
61
+ !oldProps ||
62
+ oldProps.backgroundColor.value !== newProps.backgroundColor.value
63
+ ) {
64
+ const processedColor = (processColor as any)(
65
+ newProps.backgroundColor.value
66
+ );
67
+ if (processedColor == null) {
68
+ console.warn(
69
+ `\`StatusBarDelegate::updatePropsStack\`: Color ${newProps.backgroundColor.value} parsed to null or undefined`
70
+ );
71
+ } else {
72
+ invariant(
73
+ typeof processedColor === 'number',
74
+ 'Unexpected color given in StatusBarDelegate::updatePropsStack'
75
+ );
76
+ NativeStatusBarManagerHarmony.setColor(
77
+ processedColor,
78
+ newProps.backgroundColor.animated
79
+ );
80
+ }
81
+ }
82
+ }
83
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Copyright (c) 2024 Huawei Technologies Co., Ltd.
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
+
8
+ import {
9
+ BaseTextInputDelegate,
10
+ GetNativeTextContentTypeOptions,
11
+ } from './BaseTextInputDelegate';
12
+
13
+ const RCTSinglelineTextInputView =
14
+ require('../RCTSingelineTextInputNativeComponent').default;
15
+ const RCTMultilineTextInputView =
16
+ require('../RCTMultilineTextInputNativeComponent').default;
17
+ const RCTSinglelineTextInputNativeCommands =
18
+ require('../RCTSingelineTextInputNativeComponent').Commands;
19
+ const RCTMultilineTextInputNativeCommands =
20
+ require('../RCTMultilineTextInputNativeComponent').Commands;
21
+
22
+ export default class TextInputDelegate extends BaseTextInputDelegate {
23
+ override createNativeTextInput(props: any): React.ReactNode {
24
+ const RCTTextInputView =
25
+ props.multiline === true
26
+ ? RCTMultilineTextInputView
27
+ : RCTSinglelineTextInputView;
28
+
29
+ return <RCTTextInputView {...props} />;
30
+ }
31
+
32
+ private keyboardTypeByInputMode = new Map<string, string>()
33
+ .set('none', 'default')
34
+ .set('text', 'default')
35
+ .set('decimal', 'decimal-pad')
36
+ .set('numeric', 'number-pad')
37
+ .set('tel', 'phone-pad')
38
+ .set('search', 'web-search')
39
+ .set('email', 'email-address')
40
+ .set('url', 'url');
41
+
42
+ override getKeyboardTypeByInputMode(inputMode: string): string {
43
+ return this.keyboardTypeByInputMode.get(inputMode) ?? 'default';
44
+ }
45
+
46
+ override getSupportedKeyboardTypes(): string[] {
47
+ return [
48
+ 'default',
49
+ 'email-address',
50
+ 'numeric',
51
+ 'phone-pad',
52
+ 'number-pad',
53
+ 'url',
54
+ 'decimal-pad',
55
+ 'ascii-capable',
56
+ 'numbers-and-punctuation',
57
+ 'name-phone-pad',
58
+ 'twitter',
59
+ 'web-search',
60
+ 'ascii-capable-number-pad',
61
+ 'visible-password',
62
+ ];
63
+ }
64
+
65
+ override getNativeAutocomplete(
66
+ autocomplete: string | null | undefined
67
+ ): string | null | undefined {
68
+ return undefined;
69
+ }
70
+
71
+ override getNativeTextContentType(
72
+ textContentType: string | null | undefined,
73
+ {
74
+ autocomplete,
75
+ autocompleteWebToTextContentTypeMap,
76
+ }: GetNativeTextContentTypeOptions
77
+ ): string | null | undefined {
78
+ return textContentType != null
79
+ ? textContentType
80
+ : autocomplete && autocomplete in autocompleteWebToTextContentTypeMap
81
+ ? autocompleteWebToTextContentTypeMap[autocomplete]
82
+ : textContentType;
83
+ }
84
+
85
+ override shouldBeCancellable(
86
+ rejectResponderTermination: boolean
87
+ ): boolean | null {
88
+ return !rejectResponderTermination;
89
+ }
90
+
91
+ override getTextInputCommands(multiline: boolean): any {
92
+ if (multiline) {
93
+ return RCTMultilineTextInputNativeCommands;
94
+ } else {
95
+ return RCTSinglelineTextInputNativeCommands;
96
+ }
97
+ }
98
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright (c) 2024 Huawei Technologies Co., Ltd.
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
+
8
+ import { BaseTextInputStateDelegate } from './BaseTextInputStateDelegate';
9
+ // @ts-ignore
10
+ import { Commands } from '../RCTSingelineTextInputNativeComponent';
11
+
12
+ export default class TextInputDelegate extends BaseTextInputStateDelegate {
13
+ blur(ref: React.ComponentRef<any>): void {
14
+ Commands.blur(ref);
15
+ }
16
+
17
+ focus(ref: React.ComponentRef<any>): void {
18
+ Commands.focus(ref);
19
+ }
20
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) 2024 Huawei Technologies Co., Ltd.
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
+
8
+ import { BaseTouchableHighlightDelegate } from './BaseTouchableHighlightDelegate';
9
+
10
+ export default class TouchableHighlightDelegate extends BaseTouchableHighlightDelegate {
11
+ override getExtraContainerProps(): Record<string, any> {
12
+ return { collapsable: false };
13
+ }
14
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) 2024 Huawei Technologies Co., Ltd.
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
+
8
+ import { BaseTouchableNativeFeedbackDelegate } from './BaseTouchableNativeFeedbackDelegate';
9
+
10
+ export default class TouchableNativeFeedbackDelegate extends BaseTouchableNativeFeedbackDelegate {
11
+ override getExtraProps(): Record<string, any> {
12
+ return { collapsable: false };
13
+ }
14
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) 2024 Huawei Technologies Co., Ltd.
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
+
8
+ import { BaseTouchableWithoutFeedbackDelegate } from './BaseTouchableWithoutFeedbackDelegate';
9
+
10
+ export default class TouchableWithoutFeedbackDelegate extends BaseTouchableWithoutFeedbackDelegate {
11
+ override getExtraProps(): Record<string, any> {
12
+ return { collapsable: false };
13
+ }
14
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Copyright (c) 2024 Huawei Technologies Co., Ltd.
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
+
8
+ import { TextStyle, ViewStyle } from 'react-native';
9
+ import { BaseButtonDelegate } from './BaseButtonDelegate';
10
+
11
+ export default class ButtonDelegate extends BaseButtonDelegate {
12
+ override getButtonDisabledStyle(): ViewStyle {
13
+ return {
14
+ opacity: 0.4,
15
+ };
16
+ }
17
+
18
+ override getButtonStyle(): ViewStyle {
19
+ return {
20
+ backgroundColor: '#317aff',
21
+ borderRadius: 8,
22
+ };
23
+ }
24
+
25
+ override getTextDisabledStyle(): TextStyle {
26
+ return {
27
+ fontWeight: '500',
28
+ };
29
+ }
30
+
31
+ override getTextStyle(): TextStyle {
32
+ return {
33
+ color: '#FFFFFF',
34
+ fontSize: 16,
35
+ };
36
+ }
37
+
38
+ override getInnerViewFocusable(): boolean {
39
+ return false;
40
+ }
41
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Copyright (c) 2024 Huawei Technologies Co., Ltd.
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
+
8
+ const {
9
+ setRuntimeConfigProvider,
10
+ } = require('../NativeComponent/NativeComponentRegistry');
11
+
12
+ setRuntimeConfigProvider((_viewConfigName) => {
13
+ return {
14
+ /**
15
+ * A ViewConfig describe what a component can send "to" and "from" the native side.
16
+ * On iOS/Android ViewConfigs for core components are configured in JS.
17
+ *
18
+ * In RNOH, ViewConfigs for core components are defined on the native side in ComponentJSIBinders.
19
+ * Native ViewConfigs are prefered for RNOH because they:
20
+ * 1) don't require patching RN
21
+ * 2) improve code consistency by using the same approach that is used by third party components
22
+ *
23
+ * After upgrading RNOH to 0.77 and enabling bridgless, RNOH needs to inform RN explicitly to continue using native ViewConfigs.
24
+ *
25
+ * ReactNativeFeatureFlags.js::useNativeViewConfigsInBridgelessMode can't be used here, because this code is executed before TurboModules can be used.
26
+ */
27
+ native: true,
28
+ verify: false,
29
+ };
30
+ });
@@ -1,11 +1,64 @@
1
- import {
2
- getAssetDestRelativePath,
3
- Asset,
4
- } from '@react-native-oh/react-native-harmony-cli/src/assetResolver';
5
- import {
6
- getBasePath,
7
- } from '@react-native/assets-registry/path-support';
8
- import { Platform } from 'react-native';
1
+ /**
2
+ * Copyright (c) 2024 Huawei Technologies Co., Ltd.
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
+
8
+ import type { AssetData } from 'metro';
9
+ // @ts-ignore
10
+ import { getBasePath } from '@react-native/assets-registry/path-support';
11
+ import { Dimensions, Platform } from 'react-native';
12
+
13
+ const ALLOWED_SCALES: number[] = [1, 2, 3, 4];
14
+
15
+ function filterAssetScales(
16
+ scales: readonly number[],
17
+ ): readonly number[] {
18
+ const result = scales.filter(scale => ALLOWED_SCALES.includes(scale));
19
+ if (result.length === 0 && scales.length > 0) {
20
+ // No matching scale found, but there are some available. Ideally we don't
21
+ // want to be in this situation and should throw, but for now as a fallback
22
+ // let's just use the closest larger image
23
+ const maxScale = ALLOWED_SCALES[ALLOWED_SCALES.length - 1];
24
+ for (const scale of scales) {
25
+ if (scale > maxScale) {
26
+ result.push(scale);
27
+ break;
28
+ }
29
+ }
30
+ // There is no larger scales available, use the largest we have
31
+ if (result.length === 0) {
32
+ result.push(scales[scales.length - 1]);
33
+ }
34
+ }
35
+ return result;
36
+ }
37
+
38
+ function pickScale(scales: Array<number>, deviceScale?: number): number {
39
+ const validScales = filterAssetScales(scales);
40
+ if (deviceScale == null) {
41
+ deviceScale = Dimensions.get('window').scale;
42
+ }
43
+ // Packager guarantees that `scales` array is sorted
44
+ for (let i = 0; i < validScales.length; i++) {
45
+ if (validScales[i] >= deviceScale) {
46
+ return validScales[i];
47
+ }
48
+ }
49
+
50
+ // If nothing matches, device scale is larger than any available
51
+ // scales, so we return the biggest one. Unless the array is empty,
52
+ // in which case we default to 1
53
+ return validScales[validScales.length - 1] || 1;
54
+ }
55
+
56
+ function getScaledAssetPath(asset: AssetData): string {
57
+ const scale = pickScale(asset.scales);
58
+ const scaleSuffix = scale === 1 ? '' : '@' + scale + 'x';
59
+ const assetDir = getBasePath(asset);
60
+ return assetDir + '/' + asset.name + scaleSuffix + '.' + asset.type;
61
+ }
9
62
 
10
63
  type ResolvedAssetSource = {
11
64
  readonly __packager_asset: boolean;
@@ -15,40 +68,33 @@ type ResolvedAssetSource = {
15
68
  readonly scale: number;
16
69
  };
17
70
 
18
- function getAssetPath(asset: Asset): string {
19
- const assetDir = getBasePath(asset);
20
- return assetDir + '/' + asset.name + '.' + asset.type;
21
- }
22
-
23
71
  class AssetSourceResolver {
24
72
  constructor(
25
73
  private serverUrl: string | undefined,
26
74
  private jsbundleUrl: string | undefined,
27
- private asset: Asset
75
+ private asset: AssetData
28
76
  ) {}
29
77
 
30
78
  isLoadedFromServer(): boolean {
31
79
  return !!this.serverUrl;
32
80
  }
33
81
 
34
- isLoadedFromFileSystem(): boolean {
35
- return !!(this.jsbundleUrl && this.jsbundleUrl.startsWith('file://'));
36
- }
37
-
38
82
  public defaultAsset(): ResolvedAssetSource {
39
83
  if (this.isLoadedFromServer()) {
40
84
  return this.assetServerURL();
41
85
  }
42
86
 
43
- const prefix = this.isLoadedFromFileSystem() ? this.jsbundleUrl : 'asset://';
87
+ const path = 'asset://';
44
88
 
45
- return {
46
- __packager_asset: this.asset.__packager_asset,
47
- uri: `${prefix}${getAssetDestRelativePath(this.asset)}`,
48
- scale: 1,
49
- width: this.asset.width,
50
- height: this.asset.height,
51
- };
89
+ // Assets can have relative paths outside of the project root.
90
+ // Replace `../` with `_` to make sure they don't end up outside of
91
+ // the expected assets directory.
92
+ return this.fromSource(
93
+ path +
94
+ getScaledAssetPath(this.asset)
95
+ .replace(/^assets\//, '')
96
+ .replace(/\.\.\//g, '_')
97
+ );
52
98
  }
53
99
 
54
100
  /**
@@ -62,11 +108,11 @@ class AssetSourceResolver {
62
108
 
63
109
  return this.fromSource(
64
110
  this.serverUrl +
65
- getAssetPath(this.asset) +
111
+ getScaledAssetPath(this.asset) +
66
112
  '?platform=' +
67
113
  Platform.OS +
68
114
  '&hash=' +
69
- this.asset.hash,
115
+ this.asset.hash
70
116
  );
71
117
  }
72
118
 
@@ -76,7 +122,7 @@ class AssetSourceResolver {
76
122
  width: this.asset.width,
77
123
  height: this.asset.height,
78
124
  uri: source,
79
- scale: 1,
125
+ scale: pickScale(this.asset.scales),
80
126
  };
81
127
  }
82
128
  }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Copyright (c) 2024 Huawei Technologies Co., Ltd.
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
+
8
+ // @ts-ignore
9
+ import Image from './Image.ios';
10
+ // @ts-ignore
11
+ import ImageAndroid from './Image.android';
12
+
13
+ Image.getSize = ImageAndroid.getSize
14
+ Image.prefetch = ImageAndroid.prefetch
15
+ Image.abortPrefetch = ImageAndroid.abortPrefetch
16
+
17
+ export default Image;