Skip to content

Commit a31d911

Browse files
committed
[add] ImageLoader extract types.js
1 parent b750120 commit a31d911

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

packages/react-native-web/src/exports/Image/types.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* @flow
99
*/
1010

11+
import type { ImageResult } from '../../modules/ImageLoader';
1112
import type { ColorValue, GenericStyleProp } from '../../types';
1213
import type { ViewProps } from '../View/types';
1314

@@ -103,7 +104,7 @@ export type ImageStyle = {
103104
};
104105

105106
export type ImageLoadingProps = {|
106-
onLoad?: (e: any) => void,
107+
onLoad?: (e: ImageResult) => void,
107108
onLoadStart?: () => void,
108109
onLoadEnd?: () => void,
109110
onError?: ({ nativeEvent: { error: string } }) => void,

packages/react-native-web/src/modules/ImageLoader/index.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77
* @flow
88
*/
99

10+
import type { ImageSource, ImageResult } from './types';
11+
1012
const dataUriPattern = /^data:/;
1113

1214
export class ImageUriCache {
1315
static _maximumEntries: number = 256;
1416
static _entries = {};
1517

16-
static has(uri: string): boolean {
18+
static has(uri: ?string): boolean {
19+
if (uri == null) return false;
20+
1721
const entries = ImageUriCache._entries;
1822
const isDataUri = dataUriPattern.test(uri);
1923
return isDataUri || Boolean(entries[uri]);
@@ -118,7 +122,7 @@ const ImageLoader = {
118122
clearInterval(interval);
119123
}
120124
},
121-
has(uri: string): boolean {
125+
has(uri: ?string): boolean {
122126
return ImageUriCache.has(uri);
123127
},
124128
load(
@@ -205,13 +209,6 @@ const ImageLoader = {
205209
}
206210
};
207211

208-
type ImageSource = { uri: string, headers?: { [key: string]: string } };
209-
210-
type ImageResult = {
211-
uri: string,
212-
width: number,
213-
height: number,
214-
nativeEvent: Event
215-
};
212+
export { ImageSource, ImageResult } from './types';
216213

217214
export default ImageLoader;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Copyright (c) Nicolas Gallagher.
3+
* Copyright (c) Meta Platforms, Inc. and 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+
* @flow
9+
*/
10+
11+
export type ImageSource = {|
12+
uri: string,
13+
headers?: { [key: string]: string }
14+
|};
15+
16+
export type ImageResult = {|
17+
uri: string,
18+
width: number,
19+
height: number,
20+
nativeEvent: Event
21+
|};

0 commit comments

Comments
 (0)