@react-native-oh/react-native-harmony 0.61.16

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 (82) hide show
  1. package/Libraries/ART/ReactNativeART.js +43 -0
  2. package/Libraries/Animated/Animated.js +154 -0
  3. package/Libraries/Animated/delegates/createAnimatedComponentDelegate.js +20 -0
  4. package/Libraries/Animated/src/Easing.js +20 -0
  5. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js +15 -0
  6. package/Libraries/Components/AppleTV/TVEventHandler.js +13 -0
  7. package/Libraries/Components/CheckBox/CheckBox.tsx +182 -0
  8. package/Libraries/Components/DatePickerAndroid/DatePickerAndroid.tsx +32 -0
  9. package/Libraries/Components/DatePickerIOS/DatePickerIOS.tsx +285 -0
  10. package/Libraries/Components/MaskedView/MaskedView.tsx +32 -0
  11. package/Libraries/Components/Picker/Picker.tsx +303 -0
  12. package/Libraries/Components/PickerIOS/PickerIOS.tsx +175 -0
  13. package/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.tsx +156 -0
  14. package/Libraries/Components/ProgressViewIOS/ProgressViewIOS.tsx +65 -0
  15. package/Libraries/Components/PushNotificationIOS/PushNotificationIOS.tsx +609 -0
  16. package/Libraries/Components/RefreshControl/RefreshControl.tsx +54 -0
  17. package/Libraries/Components/ScrollView/ScrollView.js +34 -0
  18. package/Libraries/Components/SegmentedControlIOS/SegmentedControlIOS.tsx +79 -0
  19. package/Libraries/Components/Slider/Slider.tsx +204 -0
  20. package/Libraries/Components/TextInput/TextInput.js +24 -0
  21. package/Libraries/Components/TimePickerAndroid/TimePickerAndroid.tsx +20 -0
  22. package/Libraries/Components/Touchable/TouchableOpacity.js +90 -0
  23. package/Libraries/Components/View/ViewPropTypes.js +16 -0
  24. package/Libraries/Components/View/delegate/ViewDelegate.js +49 -0
  25. package/Libraries/Core/ReactNativeVersion.js +21 -0
  26. package/Libraries/Core/polyfillPromise.js +18 -0
  27. package/Libraries/Core/setUpPlatform.js +13 -0
  28. package/Libraries/DeprecatedPropTypes/DeprecatedColorPropType.js +16 -0
  29. package/Libraries/DeprecatedPropTypes/DeprecatedEdgeInsetsPropType.js +16 -0
  30. package/Libraries/DeprecatedPropTypes/DeprecatedImagePropType.js +15 -0
  31. package/Libraries/DeprecatedPropTypes/DeprecatedImageSourcePropType.js +16 -0
  32. package/Libraries/DeprecatedPropTypes/DeprecatedImageStylePropTypes.js +15 -0
  33. package/Libraries/DeprecatedPropTypes/DeprecatedLayoutPropTypes.js +15 -0
  34. package/Libraries/DeprecatedPropTypes/DeprecatedPointPropType.js +16 -0
  35. package/Libraries/DeprecatedPropTypes/DeprecatedShadowPropTypesIOS.js +15 -0
  36. package/Libraries/DeprecatedPropTypes/DeprecatedStyleSheetPropType.js +16 -0
  37. package/Libraries/DeprecatedPropTypes/DeprecatedTVViewPropTypes.js +15 -0
  38. package/Libraries/DeprecatedPropTypes/DeprecatedTextInputPropTypes.js +15 -0
  39. package/Libraries/DeprecatedPropTypes/DeprecatedTextPropTypes.js +16 -0
  40. package/Libraries/DeprecatedPropTypes/DeprecatedTextStylePropTypes.js +15 -0
  41. package/Libraries/DeprecatedPropTypes/DeprecatedTransformPropTypes.js +15 -0
  42. package/Libraries/DeprecatedPropTypes/DeprecatedViewAccessibility.js +15 -0
  43. package/Libraries/DeprecatedPropTypes/DeprecatedViewPropTypes.js +16 -0
  44. package/Libraries/DeprecatedPropTypes/DeprecatedViewStylePropTypes.js +15 -0
  45. package/Libraries/DeprecatedPropTypes/deprecatedCreateStrictShapeTypeChecker.js +20 -0
  46. package/Libraries/EventEmitter/NativeEventEmitter.js +50 -0
  47. package/Libraries/Image/Image.tsx +88 -0
  48. package/Libraries/Promise.js +50 -0
  49. package/Libraries/Storage/AsyncStorage.ts +216 -0
  50. package/Libraries/Storage/helpers.ts +36 -0
  51. package/Libraries/Storage/hooks.ts +19 -0
  52. package/Libraries/Storage/index.ts +5 -0
  53. package/Libraries/Storage/types.ts +43 -0
  54. package/Libraries/StyleSheet/EdgeInsetsPropType.js +15 -0
  55. package/Libraries/StyleSheet/PointPropType.js +15 -0
  56. package/Libraries/Utilities/Platform.harmony.ts +68 -0
  57. package/Libraries/Utilities/setAndForwardRef.js +71 -0
  58. package/README.dev.md +55 -0
  59. package/README.md +146 -0
  60. package/compat/ensurePropTypes.js +45 -0
  61. package/compat/getNoopPropType.js +42 -0
  62. package/compat/restoreRemoveListener.js +117 -0
  63. package/index.js +348 -0
  64. package/package.json +45 -0
  65. package/patched-virtualized-list/VirtualizedList.js +87 -0
  66. package/polyfills/dateSlash.js +89 -0
  67. package/react_native_harmony.har +0 -0
  68. package/src/private/specs/AsyncStorage.ts +37 -0
  69. package/src/private/specs/NativeDatePickerAndroid.ts +27 -0
  70. package/src/private/specs/NativeTimePickerAndroid.ts +28 -0
  71. package/src/private/specs/PushNotificationIOS.ts +167 -0
  72. package/src/private/specs/components/CheckBoxNativeComponent.ts +35 -0
  73. package/src/private/specs/components/DatePickerNativeComponent.ts +40 -0
  74. package/src/private/specs/components/MaskedViewNativeComponent.ts +17 -0
  75. package/src/private/specs/components/PickerIOSNativeComponent.ts +53 -0
  76. package/src/private/specs/components/PickerNativeComponent.ts +67 -0
  77. package/src/private/specs/components/ProgressBarNativeComponent.ts +24 -0
  78. package/src/private/specs/components/ProgressViewNativeComponent.ts +24 -0
  79. package/src/private/specs/components/ProgressWheelNativeComponent.ts +18 -0
  80. package/src/private/specs/components/RNSliderNativeComponent.ts +44 -0
  81. package/src/private/specs/components/SegmentedControlNativeComponent.ts +38 -0
  82. package/src/private/specs/components/TimePickerNativeComponent.ts +40 -0
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright (c) 2025 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
+ 'use strict';
8
+
9
+ /**
10
+ * Deep-import alias for RN 0.61 compatibility
11
+ */
12
+
13
+ const getNoopPropType = require('../../compat/getNoopPropType');
14
+
15
+ module.exports = getNoopPropType('StyleSheetPropType');
16
+ module.exports.default = module.exports;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) 2025 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
+ 'use strict';
8
+
9
+ /**
10
+ * Deep-import alias for RN 0.61 compatibility
11
+ * Returns empty object as a no-op replacement for legacy PropTypes maps
12
+ */
13
+
14
+ module.exports = {};
15
+ module.exports.default = module.exports;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) 2025 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
+ 'use strict';
8
+
9
+ /**
10
+ * Deep-import alias for RN 0.61 compatibility
11
+ * Returns empty object as a no-op replacement for legacy PropTypes maps
12
+ */
13
+
14
+ module.exports = {};
15
+ module.exports.default = module.exports;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright (c) 2025 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
+ 'use strict';
8
+
9
+ /**
10
+ * Deep-import alias for RN 0.61 compatibility
11
+ */
12
+
13
+ const getNoopPropType = require('../../compat/getNoopPropType');
14
+
15
+ module.exports = { style: getNoopPropType('style') };
16
+ module.exports.default = module.exports;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) 2025 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
+ 'use strict';
8
+
9
+ /**
10
+ * Deep-import alias for RN 0.61 compatibility
11
+ * Returns empty object as a no-op replacement for legacy PropTypes maps
12
+ */
13
+
14
+ module.exports = {};
15
+ module.exports.default = module.exports;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) 2025 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
+ 'use strict';
8
+
9
+ /**
10
+ * Deep-import alias for RN 0.61 compatibility
11
+ * Returns empty object as a no-op replacement for legacy PropTypes maps
12
+ */
13
+
14
+ module.exports = {};
15
+ module.exports.default = module.exports;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) 2025 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
+ 'use strict';
8
+
9
+ /**
10
+ * Deep-import alias for RN 0.61 compatibility
11
+ * Returns empty object as a no-op replacement for legacy PropTypes maps
12
+ */
13
+
14
+ module.exports = {};
15
+ module.exports.default = module.exports;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright (c) 2025 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
+ 'use strict';
8
+
9
+ /**
10
+ * Deep-import alias for RN 0.61 compatibility
11
+ */
12
+
13
+ const getNoopPropType = require('../../compat/getNoopPropType');
14
+
15
+ module.exports = { style: getNoopPropType('style') };
16
+ module.exports.default = module.exports;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) 2025 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
+ 'use strict';
8
+
9
+ /**
10
+ * Deep-import alias for RN 0.61 compatibility
11
+ * Returns empty object as a no-op replacement for legacy PropTypes maps
12
+ */
13
+
14
+ module.exports = {};
15
+ module.exports.default = module.exports;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright (c) 2025 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
+ 'use strict';
8
+
9
+ /**
10
+ * Deep-import alias for RN 0.61 compatibility
11
+ */
12
+
13
+ const getNoopPropType = require('../../compat/getNoopPropType');
14
+
15
+ function deprecatedCreateStrictShapeTypeChecker() {
16
+ return getNoopPropType('StrictShapePropType');
17
+ }
18
+
19
+ module.exports = deprecatedCreateStrictShapeTypeChecker;
20
+ module.exports.default = module.exports;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Copyright (c) 2025 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
+ 'use strict';
9
+
10
+ /**
11
+ * Restores legacy listener-removal methods for NativeEventEmitter.
12
+ *
13
+ * Context:
14
+ * - RN 0.61 exposed two removal paths on NativeEventEmitter:
15
+ * 1) removeSubscription(subscription)
16
+ * 2) removeListener(event, handler) (inherited from EventEmitter) - removes all
17
+ * subscriptions registered with the same handler for the given event.
18
+ * - Since RN >= 0.65/0.77 these legacy entry points are no longer present;
19
+ * instead, listeners should be removed by calling `remove()` on the subscription.
20
+ *
21
+ * This shim reintroduces both legacy listener-removal methods:
22
+ * 1) removeSubscription(subscription) - delegates to subscription.remove()
23
+ * 2) removeListener(event, handler) - via restoreRemoveListener helper
24
+ *
25
+ * The patch is idempotent – calling it multiple times for the same module is
26
+ * safe.
27
+ */
28
+
29
+ const BaseNativeEventEmitter =
30
+ require('@react-native-oh/react-native-harmony/Libraries/EventEmitter/NativeEventEmitter').default;
31
+ const restoreRemoveListener = require('../../compat/restoreRemoveListener');
32
+
33
+ if (typeof BaseNativeEventEmitter.prototype.removeSubscription !== 'function') {
34
+ BaseNativeEventEmitter.prototype.removeSubscription = function removeSubscription(subscription) {
35
+ if (!subscription || typeof subscription.remove !== 'function') {
36
+ return;
37
+ }
38
+ subscription.remove();
39
+ };
40
+ }
41
+
42
+ class NativeEventEmitter extends BaseNativeEventEmitter {
43
+ constructor(nativeModule) {
44
+ super(nativeModule);
45
+ restoreRemoveListener(this, 'addListener', 'removeListener');
46
+ }
47
+ }
48
+
49
+ module.exports = NativeEventEmitter;
50
+ module.exports.default = NativeEventEmitter;
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Copyright (c) 2025 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
+ /**
9
+ * [INTEROP-WRAPPER]
10
+ * Wraps Harmony Image to adapt RN 0.61 semantics.
11
+ * The only change is the scheme of onLoad's input event.
12
+ * For reference on the differences, see:
13
+ * - RN 0.61 ImageLoadEvent type definition: https://github.com/facebook/react-native/blob/v0.61.5/Libraries/Image/ImageProps.js#L20
14
+ * - RN 0.77 ImageLoadEventData type definition: https://github.com/facebook/react-native/blob/v0.77.1/packages/react-native/Libraries/Image/Image.d.ts#L102
15
+ * - RN 0.6x changelog describing the change with linked commit: https://github.com/facebook/react-native/blob/main/CHANGELOG-0.6x.md?plain=1#L1282
16
+ */
17
+ import React from "react";
18
+ import { NativeSyntheticEvent } from "react-native";
19
+ import RNOHImage, {
20
+ ImageBase,
21
+ } from "@react-native-oh/react-native-harmony/Libraries/Image/Image";
22
+ import type {
23
+ ImageLoadEventData,
24
+ ImageProps,
25
+ } from "@react-native-oh/react-native-harmony/Libraries/Image/Image";
26
+
27
+ // #region types
28
+ type Event = NativeSyntheticEvent<ImageLoadEventData>;
29
+
30
+ type Event61 = Omit<Event, "nativeEvent"> & {
31
+ nativeEvent: Omit<ImageLoadEventData, "source"> & {
32
+ source: Omit<ImageLoadEventData["source"], "uri"> & {
33
+ url: string;
34
+ uri?: string;
35
+ };
36
+ };
37
+ };
38
+
39
+ type Props61 = Omit<ImageProps, "onLoad"> & {
40
+ onLoad?: (e: Event61) => void;
41
+ };
42
+ // #endregion
43
+
44
+ const Image = React.forwardRef<Props61>((props: Props61, ref) => {
45
+ const onLoad = props.onLoad;
46
+ const adaptedOnLoad: ((e: Event) => void) | undefined = onLoad
47
+ ? (event) => {
48
+ const { uri, ...sourceWithoutUri } = event.nativeEvent.source;
49
+ const adaptedEvent: Event61 = {
50
+ ...event,
51
+ nativeEvent: {
52
+ ...event.nativeEvent,
53
+ source: {
54
+ ...sourceWithoutUri,
55
+ url: event.nativeEvent.source.uri,
56
+ uri: event.nativeEvent.source.uri,
57
+ },
58
+ },
59
+ };
60
+
61
+ onLoad(adaptedEvent);
62
+ }
63
+ : undefined;
64
+
65
+ const BaseImage = RNOHImage as unknown as typeof ImageBase;
66
+ return <BaseImage ref={ref as any} {...props} onLoad={adaptedOnLoad} />;
67
+ });
68
+
69
+ Image.displayName = "Image";
70
+
71
+ // #region static methods
72
+ // @ts-ignore
73
+ Image.getSize = RNOHImage.getSize;
74
+ // @ts-ignore
75
+ Image.getSizeWithHeaders = RNOHImage.getSizeWithHeaders;
76
+ // @ts-ignore
77
+ Image.prefetch = RNOHImage.prefetch;
78
+ // @ts-ignore
79
+ Image.abortPrefetch = RNOHImage.abortPrefetch
80
+ // @ts-ignore
81
+ Image.prefetchWithMetadata = RNOHImage.prefetchWithMetadata;
82
+ // @ts-ignore
83
+ Image.queryCache = RNOHImage.queryCache;
84
+ // @ts-ignore
85
+ Image.resolveAssetSource = RNOHImage.resolveAssetSource;
86
+ // #endregion
87
+
88
+ export default Image;
@@ -0,0 +1,50 @@
1
+ //RNOH 0.61 PATCH: use version of file from RN 0.61
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ *
8
+ * @format
9
+ * @flow
10
+ */
11
+
12
+ "use strict";
13
+
14
+ const Promise = require("promise/setimmediate/es6-extensions");
15
+
16
+ require("promise/setimmediate/done");
17
+ require("promise/setimmediate/finally");
18
+
19
+ if (__DEV__) {
20
+ require("promise/setimmediate/rejection-tracking").enable({
21
+ allRejections: true,
22
+ onUnhandled: (id, error = {}) => {
23
+ let message: string;
24
+ let stack: ?string;
25
+
26
+ const stringValue = Object.prototype.toString.call(error);
27
+ if (stringValue === "[object Error]") {
28
+ message = Error.prototype.toString.call(error);
29
+ stack = error.stack;
30
+ } else {
31
+ message = require("pretty-format")(error);
32
+ }
33
+
34
+ const warning =
35
+ `Possible Unhandled Promise Rejection (id: ${id}):\n` +
36
+ `${message}\n` +
37
+ (stack == null ? "" : stack);
38
+ console.warn(warning);
39
+ },
40
+ onHandled: (id) => {
41
+ const warning =
42
+ `Promise Rejection Handled (id: ${id})\n` +
43
+ "This means you can ignore any previous messages of the form " +
44
+ `"Possible Unhandled Promise Rejection (id: ${id}):"`;
45
+ console.warn(warning);
46
+ },
47
+ });
48
+ }
49
+
50
+ module.exports = Promise;
@@ -0,0 +1,216 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its 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
+ /**
8
+ * NOTICE: This file is copied from @react-native-oh-tpl/async-storage and adapted.
9
+ *
10
+ * AsyncStorage was initially part of React Native, which is why this copyright header is used.
11
+ * It was later extracted and moved to a separate library.
12
+ * @react-native-oh-tpl/async-storage is based on @react-native-async-storage/async-storage and has been slightly adapted for OHOS.
13
+ */
14
+
15
+ import { convertError, convertErrors } from "./helpers";
16
+ import RCTAsyncStorage from "../../src/private/specs/AsyncStorage";
17
+ import type {
18
+ CallbackWithResult,
19
+ Callback,
20
+ MultiCallback,
21
+ MultiGetCallback,
22
+ ErrorLike,
23
+ KeyValuePair,
24
+ } from "./types";
25
+
26
+ if (!RCTAsyncStorage) {
27
+ throw new Error("AsyncStorage is null");
28
+ }
29
+
30
+ const AsyncStorage = (() => {
31
+ return {
32
+ getItem: (
33
+ key: string,
34
+ callback?: CallbackWithResult<string>
35
+ ): Promise<string | null> => {
36
+ return new Promise((resolve, reject) => {
37
+ RCTAsyncStorage.multiGet(
38
+ [key],
39
+ (errors?: ErrorLike[], result?: string[][]) => {
40
+ const value = result?.[0]?.[1] ? result[0][1] : null;
41
+ const errs = convertErrors(errors);
42
+ callback?.(errs?.[0], value);
43
+ if (errs) {
44
+ reject(errs[0]);
45
+ } else {
46
+ resolve(value);
47
+ }
48
+ }
49
+ );
50
+ });
51
+ },
52
+
53
+ setItem: (
54
+ key: string,
55
+ value: string,
56
+ callback?: Callback
57
+ ): Promise<null> => {
58
+ return new Promise((resolve, reject) => {
59
+ RCTAsyncStorage.multiSet([[key, value]], (errors?: ErrorLike[]) => {
60
+ const errs = convertErrors(errors);
61
+ callback?.(errs?.[0]);
62
+ if (errs) {
63
+ reject(errs[0]);
64
+ } else {
65
+ resolve(null);
66
+ }
67
+ });
68
+ });
69
+ },
70
+
71
+ removeItem: (key: string, callback?: Callback): Promise<null> => {
72
+ return new Promise((resolve, reject) => {
73
+ RCTAsyncStorage.multiRemove([key], (errors?: ErrorLike[]) => {
74
+ const errs = convertErrors(errors);
75
+ callback?.(errs?.[0]);
76
+ if (errs) {
77
+ reject(errs[0]);
78
+ } else {
79
+ resolve(null);
80
+ }
81
+ });
82
+ });
83
+ },
84
+
85
+ mergeItem: (
86
+ key: string,
87
+ value: string,
88
+ callback?: Callback
89
+ ): Promise<null> => {
90
+ return new Promise((resolve, reject) => {
91
+ RCTAsyncStorage.multiMerge([[key, value]], (errors?: ErrorLike[]) => {
92
+ const errs = convertErrors(errors);
93
+ callback?.(errs?.[0]);
94
+ if (errs) {
95
+ reject(errs[0]);
96
+ } else {
97
+ resolve(null);
98
+ }
99
+ });
100
+ });
101
+ },
102
+
103
+ clear: (callback?: Callback): Promise<null> => {
104
+ return new Promise((resolve, reject) => {
105
+ RCTAsyncStorage.clear((errors?: ErrorLike[]) => {
106
+ const errs = convertErrors(errors);
107
+ callback?.(errs?.[0]);
108
+ if (errs) {
109
+ reject(errs[0]);
110
+ } else {
111
+ resolve(null);
112
+ }
113
+ });
114
+ });
115
+ },
116
+
117
+ getAllKeys: (
118
+ callback?: CallbackWithResult<readonly string[]>
119
+ ): Promise<readonly string[]> => {
120
+ return new Promise((resolve, reject) => {
121
+ RCTAsyncStorage.getAllKeys(
122
+ (errors?: ErrorLike[], result?: [string, string][]) => {
123
+ const errs = convertErrors(errors);
124
+ callback?.(errs?.[0], result);
125
+ if (errs) {
126
+ reject(errs[0]);
127
+ } else {
128
+ resolve(result ?? []);
129
+ }
130
+ }
131
+ );
132
+ });
133
+ },
134
+
135
+ flushGetRequests: () => undefined,
136
+
137
+ multiGet: (
138
+ keys: readonly string[],
139
+ callback?: MultiGetCallback
140
+ ): Promise<readonly KeyValuePair[]> => {
141
+ return new Promise((resolve) => {
142
+ RCTAsyncStorage.multiGet(
143
+ keys.map((key) => key as string),
144
+ (errors?: ErrorLike[], result?: string[][]) => {
145
+ const map: Record<string, string | null> = {};
146
+ result?.forEach(([key, value]) => {
147
+ const normalized = value === "" ? null : value;
148
+ map[key] = normalized as string | null;
149
+ return value;
150
+ });
151
+ const requestResult = keys.map<KeyValuePair>((key) => [
152
+ key,
153
+ map[key],
154
+ ]);
155
+ const errs = convertErrors(errors);
156
+ callback?.(errs, requestResult);
157
+ resolve(requestResult);
158
+ }
159
+ );
160
+ });
161
+ },
162
+
163
+ multiSet: (
164
+ keyValuePairs: [string, string][],
165
+ callback?: MultiCallback
166
+ ): Promise<null> => {
167
+ return new Promise((resolve, reject) => {
168
+ RCTAsyncStorage.multiSet(keyValuePairs, (errors?: ErrorLike[]) => {
169
+ const error = convertErrors(errors);
170
+ callback?.(error);
171
+ if (error) {
172
+ reject(error);
173
+ } else {
174
+ resolve(null);
175
+ }
176
+ });
177
+ });
178
+ },
179
+
180
+ multiRemove: (
181
+ keys: readonly string[],
182
+ callback?: MultiCallback
183
+ ): Promise<null> => {
184
+ return new Promise((resolve, reject) => {
185
+ RCTAsyncStorage.multiRemove(keys, (errors?: ErrorLike[]) => {
186
+ const error = convertErrors(errors);
187
+ callback?.(error);
188
+ if (error) {
189
+ reject(error);
190
+ } else {
191
+ resolve(null);
192
+ }
193
+ });
194
+ });
195
+ },
196
+
197
+ multiMerge: (
198
+ keyValuePairs: [string, string][],
199
+ callback?: MultiCallback
200
+ ): Promise<null> => {
201
+ return new Promise((resolve, reject) => {
202
+ RCTAsyncStorage.multiMerge(keyValuePairs, (errors?: ErrorLike[]) => {
203
+ const error = convertErrors(errors);
204
+ callback?.(error);
205
+ if (error) {
206
+ reject(error);
207
+ } else {
208
+ resolve(null);
209
+ }
210
+ });
211
+ });
212
+ },
213
+ };
214
+ })();
215
+
216
+ export default AsyncStorage;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * NOTICE: This file is copied from @react-native-oh-tpl/async-storage and adapted.
3
+ *
4
+ * AsyncStorage was initially part of React Native, which is why this copyright header is used.
5
+ * It was later extracted and moved to a separate library.
6
+ * @react-native-oh-tpl/async-storage is based on @react-native-async-storage/async-storage and has been slightly adapted for OHOS.
7
+ */
8
+
9
+ import type { ErrorLike } from "./types";
10
+
11
+ export function convertError(error?: ErrorLike): Error | null {
12
+ if (!error) {
13
+ return null;
14
+ }
15
+
16
+ const out = new Error(error.message) as Error & ErrorLike;
17
+ out["key"] = error.key;
18
+ return out;
19
+ }
20
+
21
+ export function convertErrors(
22
+ errs?: ErrorLike[]
23
+ ): ReadonlyArray<Error | null> | null {
24
+ const errors = ensureArray(errs);
25
+ return errors ? errors.map((e) => convertError(e)) : null;
26
+ }
27
+
28
+ function ensureArray(e?: ErrorLike | ErrorLike[]): ErrorLike[] | null {
29
+ if (Array.isArray(e)) {
30
+ return e.length === 0 ? null : e;
31
+ } else if (e) {
32
+ return [e];
33
+ } else {
34
+ return null;
35
+ }
36
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * NOTICE: This file is copied from @react-native-oh-tpl/async-storage and adapted.
3
+ *
4
+ * AsyncStorage was initially part of React Native, which is why this copyright header is used.
5
+ * It was later extracted and moved to a separate library.
6
+ * @react-native-oh-tpl/async-storage is based on @react-native-async-storage/async-storage and has been slightly adapted for OHOS.
7
+ */
8
+
9
+ import AsyncStorage from "./AsyncStorage";
10
+ import type { AsyncStorageHook } from "./types";
11
+
12
+ export function useAsyncStorage(key: string): AsyncStorageHook {
13
+ return {
14
+ getItem: (...args) => AsyncStorage.getItem(key, ...args),
15
+ setItem: (...args) => AsyncStorage.setItem(key, ...args),
16
+ mergeItem: (...args) => AsyncStorage.mergeItem(key, ...args),
17
+ removeItem: (...args) => AsyncStorage.removeItem(key, ...args),
18
+ };
19
+ }
@@ -0,0 +1,5 @@
1
+ import AsyncStorage from "./AsyncStorage";
2
+
3
+ export { useAsyncStorage } from "./hooks";
4
+
5
+ export default AsyncStorage;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * NOTICE: This file is copied from @react-native-oh-tpl/async-storage and adapted.
3
+ *
4
+ * AsyncStorage was initially part of React Native, which is why this copyright header is used.
5
+ * It was later extracted and moved to a separate library.
6
+ * @react-native-oh-tpl/async-storage is based on @react-native-async-storage/async-storage and has been slightly adapted for OHOS.
7
+ */
8
+
9
+ export type ErrorLike = {
10
+ message: string;
11
+ key?: string;
12
+ };
13
+
14
+ export type Callback = (error?: Error | null) => void;
15
+
16
+ export type CallbackWithResult<T> = (
17
+ error?: Error | null,
18
+ result?: T | null
19
+ ) => void;
20
+
21
+ export type KeyValuePair = [string, string | null];
22
+
23
+ export type MultiCallback = (errors?: readonly (Error | null)[] | null) => void;
24
+
25
+ export type MultiGetCallback = (
26
+ errors?: readonly (Error | null)[] | null,
27
+ result?: readonly KeyValuePair[]
28
+ ) => void;
29
+
30
+ export type MultiRequest = {
31
+ keys: readonly string[];
32
+ callback?: MultiGetCallback;
33
+ keyIndex: number;
34
+ resolve?: (result: readonly KeyValuePair[]) => void;
35
+ reject?: (error?: ErrorLike) => void;
36
+ };
37
+
38
+ export type AsyncStorageHook = {
39
+ getItem: (callback?: CallbackWithResult<string>) => Promise<string | null>;
40
+ setItem: (value: string, callback?: Callback) => Promise<null>;
41
+ mergeItem: (value: string, callback?: Callback) => Promise<null>;
42
+ removeItem: (callback?: Callback) => Promise<null>;
43
+ };