@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,175 @@
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
+ * This is a controlled component version of RNCPickerHarmony
8
+ * @format
9
+ */
10
+ /**
11
+ * NOTICE: This file is copied from @react-native-oh-tpl/picker and adapted.
12
+ *
13
+ * PickerIOS was initially part of the RN hence such copyright header is used.
14
+ * This component was later extracted and moved to a separate library.
15
+ * The copyright header above is also used in the react-native-community version, but the community version is converted to TypeScript.
16
+ * @react-native-oh-tpl/picker is based on from react-native-community and slightly adapted for OHOS.
17
+ */
18
+
19
+ "use strict";
20
+
21
+ import * as React from "react";
22
+ import type {
23
+ ColorValue,
24
+ NativeSyntheticEvent,
25
+ TextStyle,
26
+ ViewProps,
27
+ } from "react-native";
28
+ import { processColor, StyleSheet, View } from "react-native";
29
+ import PickerIOSNativeComponent, {
30
+ NativePickerItem,
31
+ } from "../../../src/private/specs/components/PickerIOSNativeComponent";
32
+
33
+ type PickerHarmonyChangeEvent = NativeSyntheticEvent<{
34
+ newValue: number | string;
35
+ newIndex: number;
36
+ }>;
37
+
38
+ type Label = string | number;
39
+
40
+ interface Props extends ViewProps {
41
+ children: React.ReactNode;
42
+ itemStyle?: TextStyle;
43
+ numberOfLines?: number;
44
+ onChange?: (event: PickerHarmonyChangeEvent) => void;
45
+ onValueChange?: (itemValue: string | number, itemIndex: number) => void;
46
+ selectedValue?: number | string;
47
+ selectionColor?: string;
48
+ themeVariant?: string;
49
+ }
50
+
51
+ type ItemProps = Readonly<{
52
+ label?: Label;
53
+ value?: number | string;
54
+ color?: ColorValue;
55
+ testID?: string;
56
+ }>;
57
+
58
+ type CallbackRef<T> = (value: T) => void;
59
+ type ObjectRef<T> = { current: T };
60
+ type Ref<T> = CallbackRef<T> | ObjectRef<T>;
61
+
62
+ /**
63
+ * Constructs a new ref that forwards new values to each of the given refs. The
64
+ * given refs will always be invoked in the order that they are supplied.
65
+ *
66
+ * WARNING: A known problem of merging refs using this approach is that if any
67
+ * of the given refs change, the returned callback ref will also be changed. If
68
+ * the returned callback ref is supplied as a `ref` to a React element, this may
69
+ * lead to problems with the given refs being invoked more times than desired.
70
+ */
71
+ function useMergeRefs<T>(...refs: Array<Ref<T> | null>): CallbackRef<T> {
72
+ return React.useCallback((current: T) => {
73
+ for (const ref of refs) {
74
+ if (ref == null) continue;
75
+ if (typeof ref === "function") {
76
+ ref(current);
77
+ } else if (typeof (ref as any) === "object") {
78
+ (ref as any).current = current;
79
+ }
80
+ }
81
+ }, refs as any);
82
+ }
83
+
84
+ const PickerHarmonyItem: React.FC<ItemProps> = (_props: ItemProps) => null;
85
+
86
+ const PickerHarmonyWithForwardedRef = React.forwardRef<
87
+ React.ElementRef<typeof PickerIOSNativeComponent>,
88
+ Props
89
+ >(function PickerHarmony(props, forwardedRef): React.ReactElement {
90
+ const {
91
+ children,
92
+ selectedValue,
93
+ selectionColor,
94
+ themeVariant,
95
+ testID,
96
+ itemStyle,
97
+ numberOfLines,
98
+ onChange,
99
+ onValueChange,
100
+ style,
101
+ } = props;
102
+ const nativePickerRef =
103
+ React.useRef<React.ElementRef<typeof PickerIOSNativeComponent>>(null);
104
+
105
+ const ref = useMergeRefs(nativePickerRef, forwardedRef);
106
+
107
+ const items = React.useMemo((): NativePickerItem[] => {
108
+ return React.Children.toArray(children).map((child: any) => ({
109
+ value: String(child.props.value),
110
+ label: String(child.props.label),
111
+ textColor: child.props.color,
112
+ testID: child.props.testID,
113
+ }));
114
+ }, [children]);
115
+
116
+ const selectedIndex = React.useMemo((): number => {
117
+ if (selectedValue === undefined) {
118
+ return 0;
119
+ } else {
120
+ return (
121
+ items.findIndex((item) => item.value === String(selectedValue)) ?? 0
122
+ );
123
+ }
124
+ }, [items, selectedValue]);
125
+
126
+ let parsedNumberOfLines = Math.round(numberOfLines ?? 1);
127
+ if (parsedNumberOfLines < 1) {
128
+ parsedNumberOfLines = 1;
129
+ }
130
+
131
+ const _onChange = React.useCallback(
132
+ (event: PickerHarmonyChangeEvent) => {
133
+ onChange?.(event);
134
+ onValueChange?.(event.nativeEvent.newValue, event.nativeEvent.newIndex);
135
+ },
136
+ [onChange, onValueChange]
137
+ );
138
+
139
+ return (
140
+ <View style={style}>
141
+ <PickerIOSNativeComponent
142
+ ref={ref}
143
+ themeVariant={themeVariant}
144
+ testID={testID}
145
+ color={processColor(itemStyle?.color) ?? undefined}
146
+ textAlign={itemStyle?.textAlign}
147
+ fontSize={itemStyle?.fontSize}
148
+ fontWeight={itemStyle?.fontWeight as string}
149
+ fontStyle={itemStyle?.fontStyle}
150
+ fontFamily={itemStyle?.fontFamily}
151
+ style={[styles.pickerHarmony, itemStyle]}
152
+ items={items}
153
+ onChange={_onChange}
154
+ numberOfLines={parsedNumberOfLines}
155
+ selectedIndex={selectedIndex}
156
+ selectionColor={
157
+ processColor(selectionColor ?? itemStyle?.color) ?? undefined
158
+ }
159
+ />
160
+ </View>
161
+ );
162
+ });
163
+
164
+ const styles = StyleSheet.create({
165
+ pickerHarmony: {
166
+ // The picker will conform to whatever width is given, but we do
167
+ // have to set the component's height explicitly on the
168
+ // surrounding view to ensure it gets rendered.
169
+ height: 216,
170
+ },
171
+ });
172
+
173
+ (PickerHarmonyWithForwardedRef as any).Item = PickerHarmonyItem;
174
+
175
+ export default PickerHarmonyWithForwardedRef;
@@ -0,0 +1,156 @@
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
+ /**
9
+ * NOTICE: This file is copied from @react-native-oh-tpl/progress-bar-android and adapted.
10
+ *
11
+ * ProgressBarAndroid was initially part of the RN hence such copyright header is used.
12
+ * This component was later extracted and moved to a separate library.
13
+ * The copyright header above is also used in the react-native-community version, but the community version is converted to TypeScript.
14
+ * @react-native-oh-tpl/progress-bar-android is based on from react-native-community and slightly adapted for OHOS.
15
+ */
16
+
17
+ import React from "react";
18
+ import { ColorValue, StyleSheet, processColor } from "react-native";
19
+
20
+ import type { ViewProps } from "react-native/Libraries/Components/View/ViewPropTypes";
21
+ import RNProgressWheelNativeComponent from "../../../src/private/specs/components/ProgressWheelNativeComponent";
22
+ import RNProgressBarNativeComponent from "../../../src/private/specs/components/ProgressBarNativeComponent";
23
+
24
+ // #region types
25
+ /**
26
+ * Style of the ProgressBar and whether it shows indeterminate progress (e.g. spinner).
27
+ *
28
+ * `indeterminate` can only be false if `styleAttr` is Horizontal, and requires a
29
+ * `progress` value.
30
+ */
31
+ type AnimatingStyle =
32
+ | {
33
+ styleAttr: "Horizontal";
34
+ indeterminate: false;
35
+ progress: number;
36
+ }
37
+ | {
38
+ styleAttr:
39
+ | "Horizontal"
40
+ | "Normal"
41
+ | "Small"
42
+ | "Large"
43
+ | "Inverse"
44
+ | "SmallInverse"
45
+ | "LargeInverse";
46
+ // [RNOH] changed from RN declaration to include undefined,
47
+ // since .defaultProps used to inject the default was deprecated.
48
+ indeterminate?: true;
49
+ };
50
+
51
+ export type ProgressBarAndroidProps = Readonly<
52
+ ViewProps &
53
+ AnimatingStyle & {
54
+ /**
55
+ * Whether to show the ProgressBar (true, the default) or hide it (false).
56
+ */
57
+ animating?: boolean;
58
+ /**
59
+ * Color of the progress bar.
60
+ */
61
+ color?: ColorValue;
62
+ /**
63
+ * Used to locate this view in end-to-end tests.
64
+ */
65
+ testID?: string;
66
+ }
67
+ >;
68
+ // #endregion
69
+
70
+ const styleAttrToHeight = (styleAttr: AnimatingStyle["styleAttr"]) => {
71
+ const attrHeight = {
72
+ Horizontal: 16,
73
+ Small: 16,
74
+ SmallInverse: 16,
75
+ Normal: 48,
76
+ Inverse: 48,
77
+ Large: 76,
78
+ LargeInverse: 76,
79
+ };
80
+ return attrHeight[styleAttr] ?? 16;
81
+ };
82
+
83
+ /**
84
+ * React component that wraps the Android-only `ProgressBar`. This component is
85
+ * used to indicate that the app is loading or there is activity in the app.
86
+ *
87
+ * Example:
88
+ *
89
+ * ```
90
+ * render: function() {
91
+ * var progressBar =
92
+ * <View style={styles.container}>
93
+ * <ProgressBar styleAttr="Inverse" />
94
+ * </View>;
95
+
96
+ * return (
97
+ * <MyLoadingComponent
98
+ * componentView={componentView}
99
+ * loadingView={progressBar}
100
+ * style={styles.loadingComponent}
101
+ * />
102
+ * );
103
+ * },
104
+ * ```
105
+ */
106
+ const ProgressBarAndroid = React.forwardRef(
107
+ (props: ProgressBarAndroidProps, forwardedRef) => {
108
+ // set default values
109
+ const {
110
+ color = "#008577",
111
+ style,
112
+ styleAttr = "Normal",
113
+ animating = true,
114
+ testID
115
+ } = props;
116
+
117
+ const styleSheet = StyleSheet.create({
118
+ progress: {
119
+ height: styleAttrToHeight(styleAttr),
120
+ width: "100%",
121
+ display: animating ? undefined : "none",
122
+ },
123
+ });
124
+
125
+ const processedColor = processColor(color);
126
+ const commonProps = {
127
+ // typechecking complains about `null` type missing from native component's color type spec without this check
128
+ color: processedColor ?? undefined,
129
+ style: [styleSheet.progress, style],
130
+ };
131
+
132
+ if (styleAttr == "Horizontal") {
133
+ return (
134
+ <RNProgressBarNativeComponent
135
+ testID={testID}
136
+ progress={props.indeterminate === false ? props.progress : undefined}
137
+ indeterminate={props.indeterminate}
138
+ {...commonProps}
139
+ ref={forwardedRef as any}
140
+ ></RNProgressBarNativeComponent>
141
+ );
142
+ }
143
+
144
+ return (
145
+ <RNProgressWheelNativeComponent
146
+ testID={testID}
147
+ {...commonProps}
148
+ ref={forwardedRef as any}
149
+ />
150
+ );
151
+ }
152
+ );
153
+
154
+ ProgressBarAndroid.displayName = "ProgressBarAndroid";
155
+
156
+ export default ProgressBarAndroid;
@@ -0,0 +1,65 @@
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
+ import React, { useEffect } from "react";
9
+ import {
10
+ StyleSheet,
11
+ processColor,
12
+ } from "@react-native-oh/react-native-harmony";
13
+ import type { ViewProps, ColorValue, ProcessedColorValue } from "react-native";
14
+ import ProgressViewNativeComponent from "../../../src/private/specs/components/ProgressViewNativeComponent";
15
+
16
+ // iOS ProgressViewIOS default colors (now as strings)
17
+ const DEFAULT_PROGRESS_TINT = "#0066CC";
18
+ const DEFAULT_TRACK_TINT = "#F5F5F7";
19
+
20
+ type Props = Readonly<
21
+ ViewProps & {
22
+ progressViewStyle?: "default" | "bar";
23
+ progress?: number;
24
+ progressTintColor?: ColorValue;
25
+ trackTintColor?: ColorValue;
26
+ isIndeterminate?: boolean;
27
+ }
28
+ >;
29
+
30
+ export default function ProgressViewIOS(props: Props) {
31
+ const {
32
+ progress,
33
+ progressTintColor,
34
+ trackTintColor,
35
+ isIndeterminate,
36
+ style,
37
+ ...rest
38
+ } = props;
39
+
40
+ const ref =
41
+ React.useRef<React.ElementRef<typeof ProgressViewNativeComponent>>(null);
42
+
43
+ useEffect(() => {
44
+ if (!ref.current) return;
45
+
46
+ const processedProps: Record<string, ProcessedColorValue> = {
47
+ progressTintColor: processColor(
48
+ progressTintColor ?? DEFAULT_PROGRESS_TINT
49
+ )!,
50
+ trackTintColor: processColor(trackTintColor ?? DEFAULT_TRACK_TINT)!,
51
+ };
52
+
53
+ ref.current.setNativeProps?.(processedProps);
54
+ }, [progressTintColor, trackTintColor]);
55
+
56
+ return (
57
+ <ProgressViewNativeComponent
58
+ {...rest}
59
+ ref={ref}
60
+ progress={progress}
61
+ isIndeterminate={isIndeterminate}
62
+ style={StyleSheet.compose({ height: 20 }, style)}
63
+ />
64
+ );
65
+ }