forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Image for Web/Desktop with Source Headers
- Introduced `BaseImage` component that branches between native and web implementations. - **Native**: Utilizes `FastImage` directly. - **Web**: Minor adjustments made to the `onLoad` event signature for compatibility. - Eliminated `Image/index.native.js` as both native and web components now leverage a unified high-level implementation for image loading and rendering.
- Loading branch information
Showing
4 changed files
with
50 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React, {useCallback} from 'react'; | ||
import {Image as RNImage} from 'react-native'; | ||
import {defaultProps, imagePropTypes} from './imagePropTypes'; | ||
|
||
function BaseImage({onLoad, ...props}) { | ||
const imageLoadedSuccessfully = useCallback( | ||
({nativeEvent}) => { | ||
// We override `onLoad`, so both web and native have the same signature | ||
const {width, height} = nativeEvent.source; | ||
onLoad({nativeEvent: {width, height}}); | ||
}, | ||
[onLoad], | ||
); | ||
|
||
return ( | ||
<RNImage | ||
// Only subscribe to onLoad when a handler is provided to avoid unnecessary event registrations, optimizing performance. | ||
onLoad={onLoad ? imageLoadedSuccessfully : undefined} | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...props} | ||
/> | ||
); | ||
} | ||
|
||
BaseImage.propTypes = imagePropTypes; | ||
BaseImage.defaultProps = defaultProps; | ||
|
||
export default BaseImage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import RNFastImage from 'react-native-fast-image'; | ||
|
||
export default RNFastImage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.