Created
November 14, 2020 10:46
-
-
Save teramuza/ac7c5fab5468e44ee9d5c31a6c087255 to your computer and use it in GitHub Desktop.
Avatar Component. Make an avatar image (rounded) using Image component.
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
// @flow | |
import React from 'react'; | |
import { Image } from 'react-native'; | |
import type ImageStylePropTypes from 'react-native/Libraries/DeprecatedPropTypes/DeprecatedImageStylePropTypes'; | |
import { Styles } from './Avatar.component.style'; | |
type Props = { | |
source: {uri: string} | number, | |
size: number, | |
resizeMode?: ('stretch' | 'cover' | 'center' | 'contain'), | |
style?: ImageStylePropTypes | |
} | |
export default ({ | |
source, | |
size, | |
style, | |
resizeMode = 'contain' | |
}: Props) => ( | |
<Image source={source} style={[Styles.avatar(size, resizeMode), style]} /> | |
); |
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
//@flow | |
import { StyleSheet } from 'react-native'; | |
import { responsiveWidth as rw } from '../../Utils/Layout.utils'; | |
export const Styles = StyleSheet.create({ | |
avatar: (size: number, resizeMode: string) => ({ | |
width: rw(size), | |
height: rw(size), | |
borderRadius: size, | |
resizeMode | |
}) | |
}); |
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
//@flow | |
import React from 'react'; | |
import { View } from 'react-native'; | |
import { Styles } from './Example.screen.style'; | |
import { Avatar } from '../../../Components'; | |
type ScreenProps = {} | |
export default (props: ScreenProps) => { | |
return ( | |
<View style={Styles.container}> | |
<Avatar | |
resizeMode="stretch" | |
size={50} | |
source={ | |
{ uri: 'image_url' } | |
} | |
style={Styles.avatar} | |
/> | |
</View> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
good explanation