1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | import * as React from 'react';
|
11 | import {Constructor} from '../../types/private/Utilities';
|
12 | import {AccessibilityProps} from '../Components/View/ViewAccessibility';
|
13 | import {Insets} from '../../types/public/Insets';
|
14 | import {NativeMethods} from '../../types/public/ReactNativeTypes';
|
15 | import {ColorValue, StyleProp} from '../StyleSheet/StyleSheet';
|
16 | import {ImageStyle, ViewStyle} from '../StyleSheet/StyleSheetTypes';
|
17 | import {LayoutChangeEvent, NativeSyntheticEvent} from '../Types/CoreEventTypes';
|
18 | import {ImageResizeMode} from './ImageResizeMode';
|
19 | import {ImageRequireSource, ImageURISource} from './ImageSource';
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | export interface ImageProgressEventDataIOS {
|
25 | loaded: number;
|
26 | total: number;
|
27 | }
|
28 |
|
29 | export interface ImagePropsIOS {
|
30 | |
31 |
|
32 |
|
33 |
|
34 | blurRadius?: number | undefined;
|
35 |
|
36 | |
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | capInsets?: Insets | undefined;
|
43 |
|
44 | |
45 |
|
46 |
|
47 | onProgress?:
|
48 | | ((event: NativeSyntheticEvent<ImageProgressEventDataIOS>) => void)
|
49 | | undefined;
|
50 |
|
51 | /**
|
52 | * Invoked when a partial load of the image is complete. The definition of
|
53 | * what constitutes a "partial load" is loader specific though this is meant
|
54 | * for progressive JPEG loads.
|
55 | * @platform ios
|
56 | */
|
57 | onPartialLoad?: (() => void) | undefined;
|
58 | }
|
59 |
|
60 | interface ImagePropsAndroid {
|
61 | /**
|
62 | * The mechanism that should be used to resize the image when the image's dimensions
|
63 | * differ from the image view's dimensions. Defaults to `auto`.
|
64 | *
|
65 | * - `auto`: Use heuristics to pick between `resize` and `scale`.
|
66 | *
|
67 | * - `resize`: A software operation which changes the encoded image in memory before it
|
68 | * gets decoded. This should be used instead of `scale` when the image is much larger
|
69 | * than the view.
|
70 | *
|
71 | * - `scale`: The image gets drawn downscaled or upscaled. Compared to `resize`, `scale` is
|
72 | * faster (usually hardware accelerated) and produces higher quality images. This
|
73 | * should be used if the image is smaller than the view. It should also be used if the
|
74 | * image is slightly bigger than the view.
|
75 | *
|
76 | * - `none`: No sampling is performed and the image is displayed in its full resolution. This
|
77 | * should only be used in rare circumstances because it is considered unsafe as Android will
|
78 | * throw a runtime exception when trying to render images that consume too much memory.
|
79 | *
|
80 | * More details about `resize` and `scale` can be found at http://frescolib.org/docs/resizing-rotating.html.
|
81 | *
|
82 | * @platform android
|
83 | */
|
84 | resizeMethod?: 'auto' | 'resize' | 'scale' | 'none' | undefined;
|
85 |
|
86 | /**
|
87 | * Duration of fade in animation in ms. Defaults to 300
|
88 | *
|
89 | * @platform android
|
90 | */
|
91 | fadeDuration?: number | undefined;
|
92 | }
|
93 |
|
94 | /**
|
95 | * @see https://reactnative.dev/docs/image#source
|
96 | */
|
97 | export type ImageSourcePropType =
|
98 | | ImageURISource
|
99 | | ImageURISource[]
|
100 | | ImageRequireSource;
|
101 |
|
102 | export interface ImageLoadEventData {
|
103 | source: {
|
104 | height: number;
|
105 | width: number;
|
106 | uri: string;
|
107 | };
|
108 | }
|
109 |
|
110 | export interface ImageErrorEventData {
|
111 | error: any;
|
112 | }
|
113 |
|
114 | /**
|
115 | * @see https://reactnative.dev/docs/image#resolveassetsource
|
116 | */
|
117 | export interface ImageResolvedAssetSource {
|
118 | height: number;
|
119 | width: number;
|
120 | scale: number;
|
121 | uri: string;
|
122 | }
|
123 |
|
124 | /**
|
125 | * @see https://reactnative.dev/docs/image
|
126 | */
|
127 | export interface ImagePropsBase
|
128 | extends ImagePropsIOS,
|
129 | ImagePropsAndroid,
|
130 | AccessibilityProps {
|
131 | /**
|
132 | * Used to reference react managed images from native code.
|
133 | */
|
134 | id?: string | undefined;
|
135 |
|
136 | /**
|
137 | * onLayout function
|
138 | *
|
139 | * Invoked on mount and layout changes with
|
140 | *
|
141 | * {nativeEvent: { layout: {x, y, width, height} }}.
|
142 | */
|
143 | onLayout?: ((event: LayoutChangeEvent) => void) | undefined;
|
144 |
|
145 | /**
|
146 | * Invoked on load error with {nativeEvent: {error}}
|
147 | */
|
148 | onError?:
|
149 | | ((error: NativeSyntheticEvent<ImageErrorEventData>) => void)
|
150 | | undefined;
|
151 |
|
152 | /**
|
153 | * Invoked when load completes successfully
|
154 | * { source: { uri, height, width } }.
|
155 | */
|
156 | onLoad?:
|
157 | | ((event: NativeSyntheticEvent<ImageLoadEventData>) => void)
|
158 | | undefined;
|
159 |
|
160 | /**
|
161 | * Invoked when load either succeeds or fails
|
162 | */
|
163 | onLoadEnd?: (() => void) | undefined;
|
164 |
|
165 | /**
|
166 | * Invoked on load start
|
167 | */
|
168 | onLoadStart?: (() => void) | undefined;
|
169 |
|
170 | progressiveRenderingEnabled?: boolean | undefined;
|
171 |
|
172 | borderRadius?: number | undefined;
|
173 |
|
174 | borderTopLeftRadius?: number | undefined;
|
175 |
|
176 | borderTopRightRadius?: number | undefined;
|
177 |
|
178 | borderBottomLeftRadius?: number | undefined;
|
179 |
|
180 | borderBottomRightRadius?: number | undefined;
|
181 |
|
182 | /**
|
183 | * Determines how to resize the image when the frame doesn't match the raw
|
184 | * image dimensions.
|
185 | *
|
186 | * 'cover': Scale the image uniformly (maintain the image's aspect ratio)
|
187 | * so that both dimensions (width and height) of the image will be equal
|
188 | * to or larger than the corresponding dimension of the view (minus padding).
|
189 | *
|
190 | * 'contain': Scale the image uniformly (maintain the image's aspect ratio)
|
191 | * so that both dimensions (width and height) of the image will be equal to
|
192 | * or less than the corresponding dimension of the view (minus padding).
|
193 | *
|
194 | * 'stretch': Scale width and height independently, This may change the
|
195 | * aspect ratio of the src.
|
196 | *
|
197 | * 'repeat': Repeat the image to cover the frame of the view.
|
198 | * The image will keep it's size and aspect ratio. (iOS only)
|
199 | *
|
200 | * 'center': Scale the image down so that it is completely visible,
|
201 | * if bigger than the area of the view.
|
202 | * The image will not be scaled up.
|
203 | *
|
204 | * 'none': Do not resize the image. The image will be displayed at its intrinsic size.
|
205 | */
|
206 | resizeMode?: ImageResizeMode | undefined;
|
207 |
|
208 | /**
|
209 | * The image source (either a remote URL or a local file resource).
|
210 | *
|
211 | * This prop can also contain several remote URLs, specified together with their width and height and potentially with scale/other URI arguments.
|
212 | * The native side will then choose the best uri to display based on the measured size of the image container.
|
213 | * A cache property can be added to control how networked request interacts with the local cache.
|
214 | *
|
215 | * The currently supported formats are png, jpg, jpeg, bmp, gif, webp (Android only), psd (iOS only).
|
216 | */
|
217 | source?: ImageSourcePropType | undefined;
|
218 |
|
219 | /**
|
220 | * A string representing the resource identifier for the image. Similar to
|
221 | * src from HTML.
|
222 | *
|
223 | * See https://reactnative.dev/docs/image#src
|
224 | */
|
225 | src?: string | undefined;
|
226 |
|
227 | /**
|
228 | * Similar to srcset from HTML.
|
229 | *
|
230 | * See https://reactnative.dev/docs/image#srcset
|
231 | */
|
232 | srcSet?: string | undefined;
|
233 |
|
234 | /**
|
235 | * similarly to `source`, this property represents the resource used to render
|
236 | * the loading indicator for the image, displayed until image is ready to be
|
237 | * displayed, typically after when it got downloaded from network.
|
238 | */
|
239 | loadingIndicatorSource?: ImageURISource | undefined;
|
240 |
|
241 | /**
|
242 | * A unique identifier for this element to be used in UI Automation testing scripts.
|
243 | */
|
244 | testID?: string | undefined;
|
245 |
|
246 | /**
|
247 | * Used to reference react managed images from native code.
|
248 | */
|
249 | nativeID?: string | undefined;
|
250 |
|
251 | /**
|
252 | * A static image to display while downloading the final image off the network.
|
253 | */
|
254 | defaultSource?: ImageURISource | ImageRequireSource | undefined;
|
255 |
|
256 | /**
|
257 | * The text that's read by the screen reader when the user interacts with
|
258 | * the image.
|
259 | *
|
260 | * See https://reactnative.dev/docs/image#alt
|
261 | */
|
262 | alt?: string | undefined;
|
263 |
|
264 | /**
|
265 | * Height of the image component.
|
266 | *
|
267 | * See https://reactnative.dev/docs/image#height
|
268 | */
|
269 | height?: number | undefined;
|
270 |
|
271 | /**
|
272 | * Width of the image component.
|
273 | *
|
274 | * See https://reactnative.dev/docs/image#width
|
275 | */
|
276 | width?: number | undefined;
|
277 |
|
278 | /**
|
279 | * Adds the CORS related header to the request.
|
280 | * Similar to crossorigin from HTML.
|
281 | *
|
282 | * See https://reactnative.dev/docs/image#crossorigin
|
283 | */
|
284 | crossOrigin?: 'anonymous' | 'use-credentials' | undefined;
|
285 |
|
286 | /**
|
287 | * Changes the color of all the non-transparent pixels to the tintColor.
|
288 | *
|
289 | * See https://reactnative.dev/docs/image#tintcolor
|
290 | */
|
291 | tintColor?: ColorValue | undefined;
|
292 |
|
293 | /**
|
294 | * A string indicating which referrer to use when fetching the resource.
|
295 | * Similar to referrerpolicy from HTML.
|
296 | *
|
297 | * See https://reactnative.dev/docs/image#referrerpolicy
|
298 | */
|
299 | referrerPolicy?:
|
300 | | 'no-referrer'
|
301 | | 'no-referrer-when-downgrade'
|
302 | | 'origin'
|
303 | | 'origin-when-cross-origin'
|
304 | | 'same-origin'
|
305 | | 'strict-origin'
|
306 | | 'strict-origin-when-cross-origin'
|
307 | | 'unsafe-url'
|
308 | | undefined;
|
309 | }
|
310 |
|
311 | export interface ImageProps extends ImagePropsBase {
|
312 | /**
|
313 | *
|
314 | * Style
|
315 | */
|
316 | style?: StyleProp<ImageStyle> | undefined;
|
317 | }
|
318 |
|
319 | export interface ImageSize {
|
320 | width: number;
|
321 | height: number;
|
322 | }
|
323 |
|
324 | declare class ImageComponent extends React.Component<ImageProps> {}
|
325 | declare const ImageBase: Constructor<NativeMethods> & typeof ImageComponent;
|
326 | export class Image extends ImageBase {
|
327 | static getSize(uri: string): Promise<ImageSize>;
|
328 | static getSize(
|
329 | uri: string,
|
330 | success: (width: number, height: number) => void,
|
331 | failure?: (error: any) => void,
|
332 | ): void;
|
333 |
|
334 | static getSizeWithHeaders(
|
335 | uri: string,
|
336 | headers: {[index: string]: string},
|
337 | ): Promise<ImageSize>;
|
338 | static getSizeWithHeaders(
|
339 | uri: string,
|
340 | headers: {[index: string]: string},
|
341 | success: (width: number, height: number) => void,
|
342 | failure?: (error: any) => void,
|
343 | ): void;
|
344 | static prefetch(url: string): Promise<boolean>;
|
345 | static prefetchWithMetadata(
|
346 | url: string,
|
347 | queryRootName: string,
|
348 | rootTag?: number,
|
349 | ): Promise<boolean>;
|
350 | static abortPrefetch?(requestId: number): void;
|
351 | static queryCache?(
|
352 | urls: string[],
|
353 | ): Promise<{[url: string]: 'memory' | 'disk' | 'disk/memory'}>;
|
354 |
|
355 | /**
|
356 | * @see https://reactnative.dev/docs/image#resolveassetsource
|
357 | */
|
358 | static resolveAssetSource(
|
359 | source: ImageSourcePropType,
|
360 | ): ImageResolvedAssetSource;
|
361 | }
|
362 |
|
363 | export interface ImageBackgroundProps extends ImagePropsBase {
|
364 | children?: React.ReactNode | undefined;
|
365 | imageStyle?: StyleProp<ImageStyle> | undefined;
|
366 | style?: StyleProp<ViewStyle> | undefined;
|
367 | imageRef?(image: Image): void;
|
368 | }
|
369 |
|
370 | declare class ImageBackgroundComponent extends React.Component<ImageBackgroundProps> {}
|
371 | declare const ImageBackgroundBase: Constructor<NativeMethods> &
|
372 | typeof ImageBackgroundComponent;
|
373 | export class ImageBackground extends ImageBackgroundBase {}
|
374 |
|
\ | No newline at end of file |