-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refactor] Lint and enable flow for BackgroundImage component.
- Loading branch information
Showing
1 changed file
with
43 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,52 @@ | ||
// @flow | ||
|
||
import React from 'react'; | ||
import { Image } from 'react-native'; | ||
import { MediaQueryStyleSheet } from 'react-native-responsive'; | ||
|
||
import AssetsImages from '../../global/AssetsImages'; | ||
|
||
type Props = { | ||
/** | ||
* @desc Custom style to apply to component on top of default. | ||
*/ | ||
style?: any, | ||
/** | ||
* @desc Source of image to be shown instead of default background. | ||
*/ | ||
source?: number, | ||
}; | ||
|
||
/** | ||
* @desc Component that renders common background image. You should use it instead of placing background image on your own. | ||
* @type React.Component | ||
* @desc Component that renders common background image. | ||
* You should use it instead of placing background image on your own. | ||
* @return {React.Component} A component. | ||
*/ | ||
export default class BackgroundImage extends React.Component { | ||
render() { | ||
return ( | ||
<Image | ||
style={[styles.background, this.props.style]} | ||
source={this.props.source || AssetsImages.background} | ||
resizeMode='cover' | ||
{...this.props} | ||
/> | ||
); | ||
} | ||
} | ||
const BackgroundImage = ({ style, source, ...props }: Props) => { | ||
const styles = MediaQueryStyleSheet.create({ | ||
background: { | ||
position: 'absolute', | ||
left: 0, | ||
bottom: 0, | ||
right: 0, | ||
top: 0, | ||
width: '100%', | ||
height: '100%', | ||
zIndex: -1, | ||
}, | ||
}); | ||
|
||
return (<Image | ||
style={[styles.background, style]} | ||
source={source} | ||
resizeMode='cover' | ||
{...props} | ||
/>); | ||
}; | ||
|
||
BackgroundImage.defaultProps = { | ||
style: undefined, | ||
source: AssetsImages.background, | ||
}; | ||
|
||
const styles = MediaQueryStyleSheet.create({ | ||
background: { | ||
position: 'absolute', | ||
left: 0, | ||
bottom: 0, | ||
right: 0, | ||
top: 0, | ||
width: '100%', | ||
height: '100%', | ||
zIndex: -1, | ||
}, | ||
}); | ||
export default BackgroundImage; |