Skip to content

Instantly share code, notes, and snippets.

@kaueDM
Created June 9, 2019 17:15
Show Gist options
  • Select an option

  • Save kaueDM/752a92e054fd57a06e547d6a7984217f to your computer and use it in GitHub Desktop.

Select an option

Save kaueDM/752a92e054fd57a06e547d6a7984217f to your computer and use it in GitHub Desktop.
import React from 'react'
import Thumbnail from './Thumbnail'
import { withTheme } from 'styled-components'
import styled from 'styled-components/native'
import Animated from 'react-native-reanimated'
import ImageLoaderInterface from './ImageLoaderInterface'
import { coverParent, roundImageEdges } from '@utils/styleBuilder'
const imageOpacity = new Animated.Value(0)
const _imagefadeIn = () => imageOpacity.setValue(1)
const ImageContainer = styled.View<{ theme: Record<string, any> }>`
background-color: ${({ theme }) => theme.colors.secondary.dark}
`
const ImageLoader: React.FC<ImageLoaderInterface> = (props) => {
const borderRadiusStyles = props.roundedEdges
? roundImageEdges({
theme: props.theme,
edges: props.roundedEdges,
radius: props.edgeRadius || 'regular'
})
: {}
const containerStyle = Object.assign({
width: '100%',
height: '100%',
overflow: 'hidden',
...borderRadiusStyles
})
return (
<ImageContainer style={{ ...containerStyle, ...props.style }}>
{props.thumbnailSource && <Thumbnail {...props} />}
<Animated.Image
source={props.source}
resizeMode='cover'
onLoad={_imagefadeIn}
style={coverParent({ ...props.imageStyle, ...borderRadiusStyles })}
/>
</ImageContainer>
)
}
export default withTheme(ImageLoader)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment