generated from codinsonn/universal-app-router
-
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.
- Loading branch information
Showing
7 changed files
with
129 additions
and
86 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
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 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,97 @@ | ||
import { Image as ExpoImage } from 'expo-image' | ||
import { UniversalImageProps, UniversalImageMethods } from './Image.types' | ||
import { Platform } from 'react-native' | ||
|
||
/* --- <Image/> -------------------------------------------------------------------------------- */ | ||
|
||
const Image = (props: UniversalImageProps): JSX.Element => { | ||
// Props | ||
const { | ||
/* - Universal - */ | ||
src, | ||
alt, | ||
width, | ||
height, | ||
style, | ||
priority, | ||
onError, | ||
onLoadEnd, | ||
/* - Split - */ | ||
expoPlaceholder, | ||
/* - Next.js - */ | ||
onLoad, | ||
fill, | ||
/* - Expo - */ | ||
accessibilityLabel, | ||
accessible, | ||
allowDownscaling, | ||
autoplay, | ||
blurRadius, | ||
cachePolicy, | ||
contentFit, | ||
contentPosition, | ||
enableLiveTextInteraction, | ||
focusable, | ||
onLoadStart, | ||
onProgress, | ||
placeholderContentFit, | ||
recyclingKey, | ||
responsivePolicy, | ||
} = props | ||
|
||
// -- Overrides -- | ||
|
||
// @ts-ignore | ||
const finalStyle = { width, height, ...style } | ||
if (fill) finalStyle.height = '100%' | ||
if (fill) finalStyle.width = '100%' | ||
|
||
// -- Render -- | ||
|
||
return ( | ||
<ExpoImage | ||
/* - Universal - */ | ||
source={src as any} | ||
alt={alt || accessibilityLabel} // @ts-ignore | ||
style={finalStyle} | ||
priority={priority} | ||
onError={onError} | ||
onLoadEnd={onLoadEnd || onLoad as any} | ||
/* - Split - */ | ||
placeholder={expoPlaceholder} | ||
/* - Expo - */ | ||
accessibilityLabel={alt || accessibilityLabel} | ||
accessible={accessible} | ||
blurRadius={blurRadius} | ||
cachePolicy={cachePolicy} | ||
contentFit={contentFit} | ||
contentPosition={contentPosition} | ||
focusable={focusable} | ||
onLoadStart={onLoadStart} | ||
onProgress={onProgress} | ||
placeholderContentFit={placeholderContentFit} | ||
recyclingKey={recyclingKey} | ||
responsivePolicy={responsivePolicy} | ||
/* - Platform diffs - */ | ||
{...(Platform.select({ | ||
web: {}, | ||
native: { | ||
autoplay, | ||
enableLiveTextInteraction, | ||
allowDownscaling, | ||
}, | ||
}))} | ||
/> | ||
) | ||
} | ||
|
||
/* --- Static Methods -------------------------------------------------------------------------- */ | ||
|
||
Image.clearDiskCache = ExpoImage.clearDiskCache as UniversalImageMethods['clearDiskCache'] | ||
Image.clearMemoryCache = ExpoImage.clearMemoryCache as UniversalImageMethods['clearMemoryCache'] | ||
Image.getCachePathAsync = ExpoImage.getCachePathAsync as UniversalImageMethods['getCachePathAsync'] | ||
Image.prefetch = ExpoImage.prefetch as UniversalImageMethods['prefetch'] | ||
|
||
/* --- Exports --------------------------------------------------------------------------------- */ | ||
|
||
export { Image } |
File renamed without changes.
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 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 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