-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAetherImage.tsx
More file actions
53 lines (43 loc) · 1.58 KB
/
AetherImage.tsx
File metadata and controls
53 lines (43 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use client'
import React, { useMemo, forwardRef } from 'react'
import { Image, ImageSource } from 'expo-image'
// Types
import { AetherImageType } from './AetherImage.types'
// Context
import { useAetherContext } from '../../context/AetherContextManager'
// Hooks
import { useAetherStyles } from '../../hooks'
// Utils
import { getAssetKey } from '../../utils'
/* --- <AetherImage/> -------------------------------------------------------------------------- */
const AetherImage = forwardRef<Image, AetherImageType>((props, ref) => {
// Context
const { assets } = useAetherContext()
// Props
const source = useMemo(() => {
if (!props.src) return props.source
if (props.src.includes('http')) return props.src
return assets[getAssetKey(props.src)] as unknown as ImageSource
}, [props.source, props.src])
// -- Styles --
const { src: _, ...componentProps } = props
const bindStyles = useAetherStyles<typeof Image>(props)
// -- Render --
return (
<Image
{...componentProps}
ref={ref}
source={source!}
{...bindStyles} // @ts-ignore
alt={componentProps.alt || componentProps.accessibilityLabel || ''}
accessibilityLabel={componentProps.alt || componentProps.accessibilityLabel || ''}
accessibilityHint={componentProps.accessibilityHint || ''}
accessibilityIgnoresInvertColors
/>
)
})
AetherImage.displayName = 'AetherImage'
/* --- Exports --------------------------------------------------------------------------------- */
export default Object.assign(AetherImage, {
TYPE: undefined as unknown as AetherImageType,
})