Created
June 9, 2019 17:15
-
-
Save kaueDM/752a92e054fd57a06e547d6a7984217f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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