Skip to content

Commit b750120

Browse files
committed
[change] Image - extract ImageLoadingProps
Update types to match RN and actual code - we don't call `onLoadStart` and `onLoadEnd` with any arguments
1 parent 78d9651 commit b750120

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

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

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

11-
import type { ImageProps, Source } from './types';
11+
import type { ImageProps, Source, ImageLoadingProps } from './types';
1212

1313
import * as React from 'react';
1414
import createElement from '../createElement';
@@ -301,21 +301,14 @@ ImageWithStatics.queryCache = function (uris) {
301301
return ImageLoader.queryCache(uris);
302302
};
303303

304-
type UseSourceParams = {
305-
onLoad?: Function,
306-
onLoadStart?: Function,
307-
onLoadEnd?: Function,
308-
onError?: Function
309-
};
310-
311304
/**
312305
* Image loading/state management hook
313306
* @param params
314307
* @param source
315308
* @returns {{state: string, uri: string}}
316309
*/
317310
const useSource = (
318-
{ onLoad, onLoadStart, onLoadEnd, onError }: UseSourceParams,
311+
{ onLoad, onLoadStart, onLoadEnd, onError }: ImageLoadingProps,
319312
source: ?Source
320313
): { state: string, loadedUri: string } => {
321314
const lastLoadedSource = React.useRef();

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,21 @@ export type ImageStyle = {
102102
tintColor?: ColorValue
103103
};
104104

105+
export type ImageLoadingProps = {|
106+
onLoad?: (e: any) => void,
107+
onLoadStart?: () => void,
108+
onLoadEnd?: () => void,
109+
onError?: ({ nativeEvent: { error: string } }) => void,
110+
onProgress?: (e: any) => void
111+
|};
112+
105113
export type ImageProps = {
106-
...ViewProps,
114+
...$Exact<ViewProps>,
115+
...ImageLoadingProps,
107116
blurRadius?: number,
108117
defaultSource?: Source,
109118
draggable?: boolean,
110-
onError?: (e: any) => void,
111119
onLayout?: (e: any) => void,
112-
onLoad?: (e: any) => void,
113-
onLoadEnd?: (e: any) => void,
114-
onLoadStart?: (e: any) => void,
115-
onProgress?: (e: any) => void,
116120
resizeMode?: ResizeMode,
117121
source?: Source,
118122
style?: GenericStyleProp<ImageStyle>

0 commit comments

Comments
 (0)