@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.
- package/LICENSE +21 -0
- package/LICENSE-Meta +21 -0
- package/Libraries/Alert/delegates/AlertDelegate.harmony.ts +84 -0
- package/Libraries/Alert/{AlertManager.ts → delegates/AlertManager.harmony.ts} +10 -4
- package/Libraries/Animated/shouldUseTurboAnimatedModule.harmony.ts +10 -0
- package/Libraries/Components/AccessibilityInfo/delegates/AccessibilityInfoDelegate.harmony.ts +44 -0
- package/Libraries/Components/AccessibilityInfo/{NativeAccessibilityInfoHarmony.ts → delegates/NativeAccessibilityInfoHarmony.harmony.ts} +9 -2
- package/Libraries/Components/Keyboard/delegates/KeyboardAvoidingViewDelegate.harmony.ts +42 -0
- package/Libraries/Components/RefreshControl/delegates/RefreshControlDelegate.harmony.tsx +29 -0
- package/Libraries/Components/SafeAreaView/SafeAreaView.harmony.tsx +93 -31
- package/Libraries/Components/ScrollView/delegates/ScrollViewDelegate.harmony.tsx +41 -0
- package/Libraries/Components/ScrollView/delegates/ScrollViewNativeComponentDelegate.harmony.ts +89 -0
- package/Libraries/Components/ScrollView/processDecelerationRate.harmony.ts +19 -0
- package/Libraries/Components/StatusBar/delegates/NativeStatusBarManagerHarmony.harmony.ts +53 -0
- package/Libraries/Components/StatusBar/delegates/StatusBarDelegate.harmony.ts +83 -0
- package/Libraries/Components/TextInput/delegates/TextInputDelegate.harmony.tsx +98 -0
- package/Libraries/Components/TextInput/delegates/TextInputStateDelegate.harmony.tsx +20 -0
- package/Libraries/Components/Touchable/delegates/TouchableHighlightDelegate.harmony.ts +14 -0
- package/Libraries/Components/Touchable/delegates/TouchableNativeFeedbackDelegate.harmony.ts +14 -0
- package/Libraries/Components/Touchable/delegates/TouchableWithoutFeedbackDelegate.harmony.ts +14 -0
- package/Libraries/Components/delegates/ButtonDelegate.harmony.ts +41 -0
- package/Libraries/Core/setUpPlatform.harmony.js +30 -0
- package/Libraries/Image/AssetSourceResolver.harmony.ts +75 -29
- package/Libraries/Image/Image.harmony.ts +17 -0
- package/Libraries/NativeComponent/BaseViewConfig.harmony.js +12 -326
- package/Libraries/NativeComponent/delegates/ViewConfigIgnoreDelegate.harmony.ts +13 -0
- package/Libraries/ReactNative/delegates/BridgelessUIManagerDelegate.harmony.ts +14 -0
- package/Libraries/ReactNative/delegates/I18nManagerDelegate.harmony.ts +22 -0
- package/Libraries/Settings/Settings.harmony.ts +20 -0
- package/Libraries/Share/delegates/ShareDelegate.harmony.ts +42 -0
- package/Libraries/StyleSheet/NativePlatformColor.harmony.ts +15 -0
- package/Libraries/StyleSheet/PlatformColorValueTypes.harmony.ts +8 -1
- package/Libraries/Utilities/BackHandler.harmony.ts +10 -0
- package/Libraries/Utilities/NativePlatformConstantsHarmony.harmony.ts +17 -0
- package/Libraries/Utilities/Platform.harmony.ts +38 -13
- package/Libraries/Vibration/delegates/VibrationDelegate.harmony.ts +14 -0
- package/NOTICE.md +846 -0
- package/README.md +2 -2
- package/index.js +53 -63
- package/jest.config.js +0 -7
- package/metro.config.d.ts +17 -0
- package/metro.config.js +398 -115
- package/package.json +58 -37
- package/react-native.config.js +57 -9
- package/react_native_openharmony.har +0 -0
- package/tsconfig.json +10 -4
- package/types/index.harmony.d.ts +99 -0
- package/Libraries/Alert/Alert.harmony.js +0 -77
- package/Libraries/Animated/NativeAnimatedHelper.harmony.js +0 -601
- package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.harmony.js +0 -441
- package/Libraries/Components/Button/Button.harmony.js +0 -451
- package/Libraries/Components/Image/Image.flow.harmony.js +0 -53
- package/Libraries/Components/Image/Image.harmony.js +0 -317
- package/Libraries/Components/Image/NativeImageLoaderHarmony.js +0 -38
- package/Libraries/Components/Keyboard/KeyboardAvoidingView.harmony.js +0 -256
- package/Libraries/Components/RefreshControl/RefreshControl.harmony.js +0 -210
- package/Libraries/Components/ScrollView/ScrollView.harmony.js +0 -1951
- package/Libraries/Components/ScrollView/processDecelerationRate.harmony.js +0 -24
- package/Libraries/Components/StatusBar/NativeStatusBarManagerHarmony.js +0 -71
- package/Libraries/Components/StatusBar/StatusBar.harmony.js +0 -447
- package/Libraries/Components/TextInput/TextInput.harmony.js +0 -1716
- package/Libraries/Components/TextInput/TextInputState.harmony.js +0 -220
- package/Libraries/Components/Touchable/TouchableHighlight.harmony.js +0 -396
- package/Libraries/Components/Touchable/TouchableNativeFeedback.harmony.js +0 -364
- package/Libraries/Components/Touchable/TouchableWithoutFeedback.harmony.js +0 -227
- package/Libraries/Components/View/View.harmony.js +0 -149
- package/Libraries/Core/setUpReactDevTools.harmony.js +0 -93
- package/Libraries/ReactNative/I18nManager.harmony.js +0 -78
- package/Libraries/ReactNative/UIManager.harmony.js +0 -210
- package/Libraries/Settings/Settings.harmony.js +0 -15
- package/Libraries/Share/Share.harmony.js +0 -174
- package/Libraries/StyleSheet/NativePlatformColor.ts +0 -8
- package/Libraries/Utilities/BackHandler.harmony.js +0 -109
- package/Libraries/Utilities/NativePlatformConstants.harmony.ts +0 -8
- package/Libraries/Utilities/Platform.d.ts +0 -117
- package/Libraries/Utilities/createPerformanceLogger.harmony.js +0 -328
- package/Libraries/Vibration/Vibration.harmony.js +0 -88
- package/harmony/.keep +0 -0
- package/harmony/rnoh-hvigor-plugin-0.2.0.tgz +0 -0
- package/react_native_openharmony_release.har +0 -0
- package/types/index.d.ts +0 -108
|
@@ -1,317 +0,0 @@
|
|
|
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
|
|
8
|
-
* @format
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type {ImageStyleProp} from 'react-native/Libraries/StyleSheet/StyleSheet';
|
|
12
|
-
import type {RootTag} from 'react-native/Libraries/Types/RootTagTypes';
|
|
13
|
-
import type {ImageHarmony} from './Image.flow.harmony';
|
|
14
|
-
import type {ImageProps as ImagePropsType} from 'react-native/Libraries/Image/ImageProps';
|
|
15
|
-
|
|
16
|
-
import flattenStyle from 'react-native/Libraries/StyleSheet/flattenStyle';
|
|
17
|
-
import StyleSheet from 'react-native/Libraries/StyleSheet/StyleSheet';
|
|
18
|
-
import ImageAnalyticsTagContext from 'react-native/Libraries/Image/ImageAnalyticsTagContext';
|
|
19
|
-
import ImageInjection from 'react-native/Libraries/Image/ImageInjection';
|
|
20
|
-
import {getImageSourcesFromImageProps} from 'react-native/Libraries/Image/ImageSourceUtils';
|
|
21
|
-
import {convertObjectFitToResizeMode} from 'react-native/Libraries/Image/ImageUtils';
|
|
22
|
-
import ImageViewNativeComponent from 'react-native/Libraries/Image/ImageViewNativeComponent';
|
|
23
|
-
import NativeImageLoaderHarmony from './NativeImageLoaderHarmony';
|
|
24
|
-
import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource';
|
|
25
|
-
import * as React from 'react';
|
|
26
|
-
|
|
27
|
-
let _requestId = 1;
|
|
28
|
-
function generateRequestId() {
|
|
29
|
-
return _requestId++;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function getSize(
|
|
33
|
-
uri: string,
|
|
34
|
-
success: (width: number, height: number) => void,
|
|
35
|
-
failure?: (error: any) => void,
|
|
36
|
-
) {
|
|
37
|
-
NativeImageLoaderHarmony.getSize(uri)
|
|
38
|
-
.then(([width, height]) => success(width, height))
|
|
39
|
-
.catch(
|
|
40
|
-
failure ||
|
|
41
|
-
function () {
|
|
42
|
-
console.warn('Failed to get size for image ' + uri);
|
|
43
|
-
},
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function getSizeWithHeaders(
|
|
48
|
-
uri: string,
|
|
49
|
-
headers: {[string]: string, ...},
|
|
50
|
-
success: (width: number, height: number) => void,
|
|
51
|
-
failure?: (error: any) => void,
|
|
52
|
-
): any {
|
|
53
|
-
return NativeImageLoaderHarmony.getSizeWithHeaders(uri, headers)
|
|
54
|
-
.then(function (sizes) {
|
|
55
|
-
success(sizes.width, sizes.height);
|
|
56
|
-
})
|
|
57
|
-
.catch(
|
|
58
|
-
failure ||
|
|
59
|
-
function () {
|
|
60
|
-
console.warn('Failed to get size for image: ' + uri);
|
|
61
|
-
},
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function prefetchWithMetadata(
|
|
66
|
-
url: string,
|
|
67
|
-
queryRootName: string,
|
|
68
|
-
rootTag?: ?RootTag,
|
|
69
|
-
): any {
|
|
70
|
-
if (NativeImageLoaderHarmony.prefetchImageWithMetadata) {
|
|
71
|
-
// number params like rootTag cannot be nullable before TurboModules is available
|
|
72
|
-
return NativeImageLoaderHarmony.prefetchImageWithMetadata(
|
|
73
|
-
url,
|
|
74
|
-
queryRootName,
|
|
75
|
-
// NOTE: RootTag type
|
|
76
|
-
// $FlowFixMe[incompatible-call] RootTag: number is incompatible with RootTag
|
|
77
|
-
rootTag ? rootTag : 0,
|
|
78
|
-
);
|
|
79
|
-
} else {
|
|
80
|
-
const requestId = generateRequestId();
|
|
81
|
-
return NativeImageLoaderHarmony.prefetchImage(url, requestId);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function prefetch(url: string, callback: ?(requestId: number) => void): any {
|
|
86
|
-
const requestId = generateRequestId();
|
|
87
|
-
callback && callback(requestId);
|
|
88
|
-
return NativeImageLoaderHarmony.prefetchImage(url, requestId);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function abortPrefetch(requestId: number): void {
|
|
92
|
-
NativeImageLoaderHarmony.abortPrefetch(requestId);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
async function queryCache(
|
|
96
|
-
urls: Array<string>,
|
|
97
|
-
): Promise<{[string]: 'memory' | 'disk' | 'disk/memory', ...}> {
|
|
98
|
-
return await NativeImageLoaderHarmony.queryCache(urls);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export type ImageComponentStatics = $ReadOnly<{|
|
|
102
|
-
getSize: typeof getSize,
|
|
103
|
-
getSizeWithHeaders: typeof getSizeWithHeaders,
|
|
104
|
-
prefetch: typeof prefetch,
|
|
105
|
-
prefetchWithMetadata: typeof prefetchWithMetadata,
|
|
106
|
-
queryCache: typeof queryCache,
|
|
107
|
-
resolveAssetSource: typeof resolveAssetSource,
|
|
108
|
-
abortPrefetch: typeof abortPrefetch,
|
|
109
|
-
|}>;
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* A React component for displaying different types of images,
|
|
113
|
-
* including network images, static resources, temporary local images, and
|
|
114
|
-
* images from local disk, such as the camera roll.
|
|
115
|
-
*
|
|
116
|
-
* See https://reactnative.dev/docs/image
|
|
117
|
-
*/
|
|
118
|
-
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
|
|
119
|
-
* LTI update could not be added via codemod */
|
|
120
|
-
const BaseImage = (props: ImagePropsType, forwardedRef) => {
|
|
121
|
-
const source = getImageSourcesFromImageProps(props) || {
|
|
122
|
-
uri: undefined,
|
|
123
|
-
width: undefined,
|
|
124
|
-
height: undefined,
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
let sources;
|
|
128
|
-
let style: ImageStyleProp;
|
|
129
|
-
if (Array.isArray(source)) {
|
|
130
|
-
// $FlowFixMe[underconstrained-implicit-instantiation]
|
|
131
|
-
style = flattenStyle([styles.base, props.style]) || {};
|
|
132
|
-
sources = source;
|
|
133
|
-
} else {
|
|
134
|
-
// $FlowFixMe[incompatible-type]
|
|
135
|
-
const {width = props.width, height = props.height, uri} = source;
|
|
136
|
-
// $FlowFixMe[underconstrained-implicit-instantiation]
|
|
137
|
-
style = flattenStyle([{width, height}, styles.base, props.style]) || {};
|
|
138
|
-
sources = [source];
|
|
139
|
-
|
|
140
|
-
if (uri === '') {
|
|
141
|
-
console.warn('source.uri should not be an empty string');
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const objectFit =
|
|
146
|
-
// $FlowFixMe[prop-missing]
|
|
147
|
-
style && style.objectFit
|
|
148
|
-
? convertObjectFitToResizeMode(style.objectFit)
|
|
149
|
-
: null;
|
|
150
|
-
const resizeMode =
|
|
151
|
-
// $FlowFixMe[prop-missing]
|
|
152
|
-
objectFit || props.resizeMode || (style && style.resizeMode) || 'cover';
|
|
153
|
-
// $FlowFixMe[prop-missing]
|
|
154
|
-
const tintColor = props.tintColor || style.tintColor;
|
|
155
|
-
|
|
156
|
-
if (props.children != null) {
|
|
157
|
-
throw new Error(
|
|
158
|
-
'The <Image> component cannot contain children. If you want to render content on top of the image, consider using the <ImageBackground> component or absolute positioning.',
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
const {
|
|
162
|
-
'aria-busy': ariaBusy,
|
|
163
|
-
'aria-checked': ariaChecked,
|
|
164
|
-
'aria-disabled': ariaDisabled,
|
|
165
|
-
'aria-expanded': ariaExpanded,
|
|
166
|
-
'aria-selected': ariaSelected,
|
|
167
|
-
height,
|
|
168
|
-
src,
|
|
169
|
-
width,
|
|
170
|
-
...restProps
|
|
171
|
-
} = props;
|
|
172
|
-
|
|
173
|
-
const _accessibilityState = {
|
|
174
|
-
busy: ariaBusy ?? props.accessibilityState?.busy,
|
|
175
|
-
checked: ariaChecked ?? props.accessibilityState?.checked,
|
|
176
|
-
disabled: ariaDisabled ?? props.accessibilityState?.disabled,
|
|
177
|
-
expanded: ariaExpanded ?? props.accessibilityState?.expanded,
|
|
178
|
-
selected: ariaSelected ?? props.accessibilityState?.selected,
|
|
179
|
-
};
|
|
180
|
-
const accessibilityLabel = props['aria-label'] ?? props.accessibilityLabel;
|
|
181
|
-
|
|
182
|
-
return (
|
|
183
|
-
<ImageAnalyticsTagContext.Consumer>
|
|
184
|
-
{analyticTag => {
|
|
185
|
-
if (props.accessibilityLabelledBy == undefined &&
|
|
186
|
-
props.accessibilityActions == undefined &&
|
|
187
|
-
props.accessbilityState == undefined &&
|
|
188
|
-
props.accessibilityRole == undefined &&
|
|
189
|
-
props.accessible == undefined &&
|
|
190
|
-
props.accessibilityLabel == undefined) {
|
|
191
|
-
return (
|
|
192
|
-
<ImageViewNativeComponent
|
|
193
|
-
{...restProps}
|
|
194
|
-
ref={forwardedRef}
|
|
195
|
-
style={style}
|
|
196
|
-
resizeMode={resizeMode}
|
|
197
|
-
tintColor={tintColor}
|
|
198
|
-
source={sources}
|
|
199
|
-
internal_analyticTag={analyticTag}
|
|
200
|
-
/>
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
return (
|
|
204
|
-
<ImageViewNativeComponent
|
|
205
|
-
accessibilityState={_accessibilityState}
|
|
206
|
-
{...restProps}
|
|
207
|
-
accessible={props.alt !== undefined ? true : props.accessible}
|
|
208
|
-
accessibilityLabel={accessibilityLabel ?? props.alt}
|
|
209
|
-
ref={forwardedRef}
|
|
210
|
-
style={style}
|
|
211
|
-
resizeMode={resizeMode}
|
|
212
|
-
tintColor={tintColor}
|
|
213
|
-
source={sources}
|
|
214
|
-
internal_analyticTag={analyticTag}
|
|
215
|
-
/>
|
|
216
|
-
);
|
|
217
|
-
}}
|
|
218
|
-
</ImageAnalyticsTagContext.Consumer>
|
|
219
|
-
);
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
const ImageForwardRef = React.forwardRef<
|
|
223
|
-
ImagePropsType,
|
|
224
|
-
React.ElementRef<typeof ImageViewNativeComponent>,
|
|
225
|
-
>(BaseImage);
|
|
226
|
-
|
|
227
|
-
let Image = ImageForwardRef;
|
|
228
|
-
if (ImageInjection.unstable_createImageComponent != null) {
|
|
229
|
-
Image = ImageInjection.unstable_createImageComponent(Image);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
Image.displayName = 'Image';
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Retrieve the width and height (in pixels) of an image prior to displaying it.
|
|
236
|
-
*
|
|
237
|
-
* See https://reactnative.dev/docs/image#getsize
|
|
238
|
-
*/
|
|
239
|
-
/* $FlowFixMe[prop-missing] (>=0.89.0 site=react_native_ios_fb) This comment
|
|
240
|
-
* suppresses an error found when Flow v0.89 was deployed. To see the error,
|
|
241
|
-
* delete this comment and run Flow. */
|
|
242
|
-
Image.getSize = getSize;
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Retrieve the width and height (in pixels) of an image prior to displaying it
|
|
246
|
-
* with the ability to provide the headers for the request.
|
|
247
|
-
*
|
|
248
|
-
* See https://reactnative.dev/docs/image#getsizewithheaders
|
|
249
|
-
*/
|
|
250
|
-
/* $FlowFixMe[prop-missing] (>=0.89.0 site=react_native_ios_fb) This comment
|
|
251
|
-
* suppresses an error found when Flow v0.89 was deployed. To see the error,
|
|
252
|
-
* delete this comment and run Flow. */
|
|
253
|
-
Image.getSizeWithHeaders = getSizeWithHeaders;
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Prefetches a remote image for later use by downloading it to the disk
|
|
257
|
-
* cache.
|
|
258
|
-
*
|
|
259
|
-
* See https://reactnative.dev/docs/image#prefetch
|
|
260
|
-
*/
|
|
261
|
-
/* $FlowFixMe[prop-missing] (>=0.89.0 site=react_native_ios_fb) This comment
|
|
262
|
-
* suppresses an error found when Flow v0.89 was deployed. To see the error,
|
|
263
|
-
* delete this comment and run Flow. */
|
|
264
|
-
Image.prefetch = prefetch;
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Prefetches a remote image for later use by downloading it to the disk
|
|
268
|
-
* cache, and adds metadata for queryRootName and rootTag.
|
|
269
|
-
*
|
|
270
|
-
* See https://reactnative.dev/docs/image#prefetch
|
|
271
|
-
*/
|
|
272
|
-
/* $FlowFixMe[prop-missing] (>=0.89.0 site=react_native_ios_fb) This comment
|
|
273
|
-
* suppresses an error found when Flow v0.89 was deployed. To see the error,
|
|
274
|
-
* delete this comment and run Flow. */
|
|
275
|
-
Image.prefetchWithMetadata = prefetchWithMetadata;
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Performs cache interrogation.
|
|
279
|
-
*
|
|
280
|
-
* See https://reactnative.dev/docs/image#querycache
|
|
281
|
-
*/
|
|
282
|
-
/* $FlowFixMe[prop-missing] (>=0.89.0 site=react_native_ios_fb) This comment
|
|
283
|
-
* suppresses an error found when Flow v0.89 was deployed. To see the error,
|
|
284
|
-
* delete this comment and run Flow. */
|
|
285
|
-
Image.queryCache = queryCache;
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* Resolves an asset reference into an object.
|
|
289
|
-
*
|
|
290
|
-
* See https://reactnative.dev/docs/image#resolveassetsource
|
|
291
|
-
*/
|
|
292
|
-
/* $FlowFixMe[prop-missing] (>=0.89.0 site=react_native_ios_fb) This comment
|
|
293
|
-
* suppresses an error found when Flow v0.89 was deployed. To see the error,
|
|
294
|
-
* delete this comment and run Flow. */
|
|
295
|
-
Image.resolveAssetSource = resolveAssetSource;
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Abort prefetch request.
|
|
299
|
-
*
|
|
300
|
-
* See https://reactnative.dev/docs/image#abortprefetch
|
|
301
|
-
*/
|
|
302
|
-
// $FlowFixMe[incompatible-use] This property isn't writable but we're actually defining it here for the first time.
|
|
303
|
-
Image.abortPrefetch = abortPrefetch;
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Switch to `deprecated-react-native-prop-types` for compatibility with future
|
|
307
|
-
* releases. This is deprecated and will be removed in the future.
|
|
308
|
-
*/
|
|
309
|
-
Image.propTypes = require('deprecated-react-native-prop-types').ImagePropTypes;
|
|
310
|
-
|
|
311
|
-
const styles = StyleSheet.create({
|
|
312
|
-
base: {
|
|
313
|
-
overflow: 'hidden',
|
|
314
|
-
},
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
module.exports = ((Image: any): ImageHarmony);
|
|
@@ -1,38 +0,0 @@
|
|
|
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
|
|
8
|
-
* @format
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type {RootTag} from 'react-native/Libraries/TurboModule/RCTExport';
|
|
12
|
-
import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
|
|
13
|
-
|
|
14
|
-
import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
|
|
15
|
-
|
|
16
|
-
export interface Spec extends TurboModule {
|
|
17
|
-
+getConstants: () => {||};
|
|
18
|
-
// Return [width, height] of image uri
|
|
19
|
-
+getSize: (uri: string) => Promise<$ReadOnlyArray<number>>;
|
|
20
|
-
+getSizeWithHeaders: (
|
|
21
|
-
uri: string,
|
|
22
|
-
headers: Object,
|
|
23
|
-
) => Promise<{
|
|
24
|
-
width: number,
|
|
25
|
-
height: number,
|
|
26
|
-
...
|
|
27
|
-
}>;
|
|
28
|
-
+prefetchImage: (uri: string, requestId: number) => Promise<boolean>;
|
|
29
|
-
+prefetchImageWithMetadata?: (
|
|
30
|
-
uri: string,
|
|
31
|
-
queryRootName: string,
|
|
32
|
-
rootTag: RootTag,
|
|
33
|
-
) => Promise<boolean>;
|
|
34
|
-
+queryCache: (uris: Array<string>) => Promise<Object>;
|
|
35
|
-
+abortPrefetch: (requestId: number) => void;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export default (TurboModuleRegistry.getEnforcing<Spec>('ImageLoader'): Spec);
|
|
@@ -1,256 +0,0 @@
|
|
|
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
|
-
* @format
|
|
8
|
-
* @flow strict-local
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type {ViewStyleProp} from 'react-native/Libraries/Components/Keyboard/../../StyleSheet/StyleSheet';
|
|
12
|
-
import type {
|
|
13
|
-
ViewLayout,
|
|
14
|
-
ViewLayoutEvent,
|
|
15
|
-
ViewProps,
|
|
16
|
-
} from 'react-native/Libraries/Components/Keyboard/../View/ViewPropTypes';
|
|
17
|
-
import type {KeyboardEvent, KeyboardMetrics} from 'react-native/Libraries/Components/Keyboard/Keyboard';
|
|
18
|
-
|
|
19
|
-
import LayoutAnimation from 'react-native/Libraries/Components/Keyboard/../../LayoutAnimation/LayoutAnimation';
|
|
20
|
-
import StyleSheet from 'react-native/Libraries/Components/Keyboard/../../StyleSheet/StyleSheet';
|
|
21
|
-
import Platform from '../../Utilities/Platform';
|
|
22
|
-
import {type EventSubscription} from 'react-native/Libraries/Components/Keyboard/../../vendor/emitter/EventEmitter';
|
|
23
|
-
import AccessibilityInfo from 'react-native/Libraries/Components/Keyboard/../AccessibilityInfo/AccessibilityInfo';
|
|
24
|
-
import View from 'react-native/Libraries/Components/Keyboard/../View/View';
|
|
25
|
-
import Keyboard from 'react-native/Libraries/Components/Keyboard/Keyboard';
|
|
26
|
-
import * as React from 'react';
|
|
27
|
-
|
|
28
|
-
type Props = $ReadOnly<{|
|
|
29
|
-
...ViewProps,
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Specify how to react to the presence of the keyboard.
|
|
33
|
-
*/
|
|
34
|
-
behavior?: ?('height' | 'position' | 'padding'),
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Style of the content container when `behavior` is 'position'.
|
|
38
|
-
*/
|
|
39
|
-
contentContainerStyle?: ?ViewStyleProp,
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Controls whether this `KeyboardAvoidingView` instance should take effect.
|
|
43
|
-
* This is useful when more than one is on the screen. Defaults to true.
|
|
44
|
-
*/
|
|
45
|
-
enabled?: ?boolean,
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Distance between the top of the user screen and the React Native view. This
|
|
49
|
-
* may be non-zero in some cases. Defaults to 0.
|
|
50
|
-
*/
|
|
51
|
-
keyboardVerticalOffset?: number,
|
|
52
|
-
|}>;
|
|
53
|
-
|
|
54
|
-
type State = {|
|
|
55
|
-
bottom: number,
|
|
56
|
-
|};
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* View that moves out of the way when the keyboard appears by automatically
|
|
60
|
-
* adjusting its height, position, or bottom padding.
|
|
61
|
-
*/
|
|
62
|
-
class KeyboardAvoidingView extends React.Component<Props, State> {
|
|
63
|
-
_frame: ?ViewLayout = null;
|
|
64
|
-
_keyboardEvent: ?KeyboardEvent = null;
|
|
65
|
-
_subscriptions: Array<EventSubscription> = [];
|
|
66
|
-
viewRef: {current: React.ElementRef<typeof View> | null, ...};
|
|
67
|
-
_initialFrameHeight: number = 0;
|
|
68
|
-
|
|
69
|
-
constructor(props: Props) {
|
|
70
|
-
super(props);
|
|
71
|
-
this.state = {bottom: 0};
|
|
72
|
-
this.viewRef = React.createRef();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async _relativeKeyboardHeight(
|
|
76
|
-
keyboardFrame: KeyboardMetrics,
|
|
77
|
-
): Promise<number> {
|
|
78
|
-
const frame = this._frame;
|
|
79
|
-
if (!frame || !keyboardFrame
|
|
80
|
-
|| this.props.enabled === false) { // RNOH patch
|
|
81
|
-
return 0;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// On iOS when Prefer Cross-Fade Transitions is enabled, the keyboard position
|
|
85
|
-
// & height is reported differently (0 instead of Y position value matching height of frame)
|
|
86
|
-
if (
|
|
87
|
-
Platform.OS === 'ios' &&
|
|
88
|
-
keyboardFrame.screenY === 0 &&
|
|
89
|
-
(await AccessibilityInfo.prefersCrossFadeTransitions())
|
|
90
|
-
) {
|
|
91
|
-
return 0;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const keyboardY =
|
|
95
|
-
keyboardFrame.screenY - (this.props.keyboardVerticalOffset ?? 0);
|
|
96
|
-
|
|
97
|
-
if (this.props.behavior === 'height') {
|
|
98
|
-
return Math.max(
|
|
99
|
-
this.state.bottom + frame.y + frame.height - keyboardY,
|
|
100
|
-
0,
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Calculate the displacement needed for the view such that it
|
|
105
|
-
// no longer overlaps with the keyboard
|
|
106
|
-
return Math.max(frame.y + frame.height - keyboardY, 0);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
_onKeyboardChange = (event: ?KeyboardEvent) => {
|
|
110
|
-
this._keyboardEvent = event;
|
|
111
|
-
// $FlowFixMe[unused-promise]
|
|
112
|
-
this._updateBottomIfNecessary();
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
_onLayout = async (event: ViewLayoutEvent) => {
|
|
116
|
-
const wasFrameNull = this._frame == null;
|
|
117
|
-
this._frame = event.nativeEvent.layout;
|
|
118
|
-
if (!this._initialFrameHeight) {
|
|
119
|
-
// save the initial frame height, before the keyboard is visible
|
|
120
|
-
this._initialFrameHeight = this._frame.height;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (wasFrameNull) {
|
|
124
|
-
await this._updateBottomIfNecessary();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (this.props.onLayout) {
|
|
128
|
-
this.props.onLayout(event);
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
_updateBottomIfNecessary = async () => {
|
|
133
|
-
if (this._keyboardEvent == null) {
|
|
134
|
-
this.setState({bottom: 0});
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const {duration, easing, endCoordinates} = this._keyboardEvent;
|
|
139
|
-
const height = await this._relativeKeyboardHeight(endCoordinates);
|
|
140
|
-
|
|
141
|
-
if (this.state.bottom === height) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (duration && easing) {
|
|
146
|
-
LayoutAnimation.configureNext({
|
|
147
|
-
// We have to pass the duration equal to minimal accepted duration defined here: RCTLayoutAnimation.m
|
|
148
|
-
duration: duration > 10 ? duration : 10,
|
|
149
|
-
update: {
|
|
150
|
-
duration: duration > 10 ? duration : 10,
|
|
151
|
-
type: LayoutAnimation.Types[easing] || 'keyboard',
|
|
152
|
-
},
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
this.setState({bottom: height});
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
componentDidMount(): void {
|
|
159
|
-
if (Platform.OS === 'ios') {
|
|
160
|
-
this._subscriptions = [
|
|
161
|
-
Keyboard.addListener('keyboardWillChangeFrame', this._onKeyboardChange),
|
|
162
|
-
];
|
|
163
|
-
} else {
|
|
164
|
-
this._subscriptions = [
|
|
165
|
-
Keyboard.addListener('keyboardDidHide', this._onKeyboardChange),
|
|
166
|
-
Keyboard.addListener('keyboardDidShow', this._onKeyboardChange),
|
|
167
|
-
];
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
componentWillUnmount(): void {
|
|
172
|
-
this._subscriptions.forEach(subscription => {
|
|
173
|
-
subscription.remove();
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
render(): React.Node {
|
|
178
|
-
const {
|
|
179
|
-
behavior,
|
|
180
|
-
children,
|
|
181
|
-
contentContainerStyle,
|
|
182
|
-
enabled = true,
|
|
183
|
-
// eslint-disable-next-line no-unused-vars
|
|
184
|
-
keyboardVerticalOffset = 0,
|
|
185
|
-
style,
|
|
186
|
-
onLayout,
|
|
187
|
-
...props
|
|
188
|
-
} = this.props;
|
|
189
|
-
const bottomHeight = enabled === true ? this.state.bottom : 0;
|
|
190
|
-
switch (behavior) {
|
|
191
|
-
case 'height':
|
|
192
|
-
let heightStyle;
|
|
193
|
-
if (this._frame != null && this.state.bottom > 0) {
|
|
194
|
-
// Note that we only apply a height change when there is keyboard present,
|
|
195
|
-
// i.e. this.state.bottom is greater than 0. If we remove that condition,
|
|
196
|
-
// this.frame.height will never go back to its original value.
|
|
197
|
-
// When height changes, we need to disable flex.
|
|
198
|
-
heightStyle = {
|
|
199
|
-
height: this._initialFrameHeight - bottomHeight,
|
|
200
|
-
flex: 0,
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
/* RNOH: patch */
|
|
204
|
-
return (
|
|
205
|
-
<View
|
|
206
|
-
ref={this.viewRef}
|
|
207
|
-
style={StyleSheet.compose(style, heightStyle)}
|
|
208
|
-
onLayout={this._onLayout}
|
|
209
|
-
{...props}>
|
|
210
|
-
{React.Children.map(children, child => child && React.cloneElement(child, {__keyboardAvoidingViewBottomHeight: bottomHeight}))}
|
|
211
|
-
</View>
|
|
212
|
-
);
|
|
213
|
-
|
|
214
|
-
case 'position':
|
|
215
|
-
return (
|
|
216
|
-
<View
|
|
217
|
-
ref={this.viewRef}
|
|
218
|
-
style={style}
|
|
219
|
-
onLayout={this._onLayout}
|
|
220
|
-
{...props}>
|
|
221
|
-
<View
|
|
222
|
-
style={StyleSheet.compose(contentContainerStyle, {
|
|
223
|
-
bottom: bottomHeight,
|
|
224
|
-
})}>
|
|
225
|
-
{children}
|
|
226
|
-
</View>
|
|
227
|
-
</View>
|
|
228
|
-
);
|
|
229
|
-
|
|
230
|
-
case 'padding':
|
|
231
|
-
/* RNOH: patch */
|
|
232
|
-
return (
|
|
233
|
-
<View
|
|
234
|
-
ref={this.viewRef}
|
|
235
|
-
style={StyleSheet.compose(style, {paddingBottom: bottomHeight})}
|
|
236
|
-
onLayout={this._onLayout}
|
|
237
|
-
{...props}>
|
|
238
|
-
{React.Children.map(children, child => child && React.cloneElement(child, {__keyboardAvoidingViewBottomHeight: bottomHeight}))}
|
|
239
|
-
</View>
|
|
240
|
-
);
|
|
241
|
-
|
|
242
|
-
default:
|
|
243
|
-
return (
|
|
244
|
-
<View
|
|
245
|
-
ref={this.viewRef}
|
|
246
|
-
onLayout={this._onLayout}
|
|
247
|
-
style={style}
|
|
248
|
-
{...props}>
|
|
249
|
-
{children}
|
|
250
|
-
</View>
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
export default KeyboardAvoidingView;
|