Skip to content

Instantly share code, notes, and snippets.

@Chiamaka
Created February 8, 2018 21:53
Show Gist options
  • Save Chiamaka/ccfa5256b0c671ab738482c4d47810b9 to your computer and use it in GitHub Desktop.
Save Chiamaka/ccfa5256b0c671ab738482c4d47810b9 to your computer and use it in GitHub Desktop.
import React, { PureComponent } from 'react';
import { View, Text, Animated, TouchableWithoutFeedback } from 'react-native';
import Icon from 'react-native-vector-icons/Ionicons';
import PropTypes from 'prop-types';
export default class MinusButton extends PureComponent {
render() {
const translateMinusCircle = this.props.animationValue.interpolate({
inputRange: [0, 1],
outputRange: [60, 0]
});
const scaleDownCircle = this.props.animationValue.interpolate({
inputRange: [0, 1],
outputRange: [1, 0.7]
});
const decrementCircleTransforms = {
transform: [
{ scale: scaleDownCircle },
{ translateX: translateMinusCircle }
]
};
return (
<TouchableWithoutFeedback onPress={this.props.decreaseNumber}>
<Animated.View style={[styles.counterDecrementStyle, decrementCircleTransforms]}> // <---- Add decrementCircleTransforms to tie the interpolations to the style
<Icon name="ios-remove" size={30} color={'rgb(130, 130, 130)'} />
</Animated.View>
</TouchableWithoutFeedback>
);
}
}
MinusButton.propTypes = {
decreaseNumber: PropTypes.func,
animationValue: PropTypes.object
};
const styles = {
counterDecrementStyle: {
borderRadius: 30,
width: 60,
height: 60,
alignItems: 'center',
justifyContent: 'center',
shadowOpacity: 0.3,
shadowOffset: { x: 0, y: 2 },
shadowColor: 'black',
backgroundColor: 'white',
borderColor: 'rgb(130, 130, 130)',
borderWidth: 3
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment