Skip to content

Commit

Permalink
Merge pull request #38766 from jsdev2547/imageflicker
Browse files Browse the repository at this point in the history
resolve flicker
  • Loading branch information
srikarparsi authored Mar 25, 2024
2 parents 959135c + 8bc4f79 commit ad49908
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/Image/BaseImage.native.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import {Image as ExpoImage} from 'expo-image';
import type {ImageLoadEventData} from 'expo-image';
import {useCallback} from 'react';
import {useCallback, useRef} from 'react';
import type {BaseImageProps} from './types';

function BaseImage({onLoad, ...props}: BaseImageProps) {
const isLoadedRef = useRef(false);
const imageLoadedSuccessfully = useCallback(
(event: ImageLoadEventData) => {
if (!onLoad) {
return;
}
if (isLoadedRef.current === true) {
return;
}

// We override `onLoad`, so both web and native have the same signature
const {width, height} = event.source;
isLoadedRef.current = true;
onLoad({nativeEvent: {width, height}});
},
[onLoad],
Expand Down

0 comments on commit ad49908

Please sign in to comment.