[FIX] Hardcoded backdrop opacity on loading component (#3255)
* Added withTheme and themes to Loading * Added animation to backdrop opacity * Minor tweak * Fix internal image impacted by opacity Co-authored-by: Diego Mello <diegolmello@gmail.com> Co-authored-by: Levy Costa <levycosta471@gmail.com>
This commit is contained in:
parent
1c43c78cf4
commit
14fd12ce64
|
@ -1,15 +1,16 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import {
|
import {
|
||||||
StyleSheet, View, Modal, Animated
|
StyleSheet, Modal, Animated, View
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
|
import { withTheme } from '../theme';
|
||||||
|
import { themes } from '../constants/colors';
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {
|
container: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center'
|
||||||
backgroundColor: 'rgba(0, 0, 0, 0.25)'
|
|
||||||
},
|
},
|
||||||
image: {
|
image: {
|
||||||
width: 100,
|
width: 100,
|
||||||
|
@ -18,9 +19,10 @@ const styles = StyleSheet.create({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export default class Loading extends React.PureComponent {
|
class Loading extends React.PureComponent {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
visible: PropTypes.bool.isRequired
|
visible: PropTypes.bool,
|
||||||
|
theme: PropTypes.string
|
||||||
}
|
}
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
|
@ -36,7 +38,7 @@ export default class Loading extends React.PureComponent {
|
||||||
opacity,
|
opacity,
|
||||||
{
|
{
|
||||||
toValue: 1,
|
toValue: 1,
|
||||||
duration: 1000,
|
duration: 200,
|
||||||
useNativeDriver: true
|
useNativeDriver: true
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -91,23 +93,39 @@ export default class Loading extends React.PureComponent {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { opacity, scale } = this.state;
|
const { opacity, scale } = this.state;
|
||||||
const { visible } = this.props;
|
const { visible, theme } = this.props;
|
||||||
|
|
||||||
const scaleAnimation = scale.interpolate({
|
const scaleAnimation = scale.interpolate({
|
||||||
inputRange: [0, 0.5, 1],
|
inputRange: [0, 0.5, 1],
|
||||||
outputRange: [1, 1.1, 1]
|
outputRange: [1, 1.1, 1]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const opacityAnimation = opacity.interpolate({
|
||||||
|
inputRange: [0, 1],
|
||||||
|
outputRange: [0, themes[theme].backdropOpacity],
|
||||||
|
extrapolate: 'clamp'
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
visible={visible}
|
visible={visible}
|
||||||
transparent
|
transparent
|
||||||
onRequestClose={() => {}}
|
onRequestClose={() => {}}
|
||||||
>
|
>
|
||||||
<View style={styles.container} testID='loading'>
|
<View
|
||||||
|
style={styles.container}
|
||||||
|
testID='loading'
|
||||||
|
>
|
||||||
|
<Animated.View
|
||||||
|
style={[{
|
||||||
|
...StyleSheet.absoluteFill,
|
||||||
|
backgroundColor: themes[theme].backdropColor,
|
||||||
|
opacity: opacityAnimation
|
||||||
|
}]}
|
||||||
|
/>
|
||||||
<Animated.Image
|
<Animated.Image
|
||||||
source={require('../static/images/logo.png')}
|
source={require('../static/images/logo.png')}
|
||||||
style={[styles.image, {
|
style={[styles.image, {
|
||||||
opacity,
|
|
||||||
transform: [{
|
transform: [{
|
||||||
scale: scaleAnimation
|
scale: scaleAnimation
|
||||||
}]
|
}]
|
||||||
|
@ -118,3 +136,5 @@ export default class Loading extends React.PureComponent {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default (withTheme(Loading));
|
||||||
|
|
Loading…
Reference in New Issue