-
Notifications
You must be signed in to change notification settings - Fork 958
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): toggle component. closes #235
- Loading branch information
Showing
10 changed files
with
2,085 additions
and
100 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import React from 'react'; | ||
import { | ||
View, | ||
Animated, | ||
StyleSheet, | ||
} from 'react-native'; | ||
|
||
interface CheckMarkProps { | ||
size: number; | ||
color: Animated.AnimatedDiffClamp | string; | ||
isAnimated?: boolean; | ||
} | ||
|
||
export class CheckMark extends React.Component<CheckMarkProps> { | ||
|
||
static defaultProps = { | ||
isAnimated: false, | ||
}; | ||
|
||
private getStyle = (size: number, color: Animated.AnimatedDiffClamp | string) => ({ | ||
checkMarkContainer: { | ||
width: size, | ||
height: size, | ||
}, | ||
// the dependence of the variables was determined experimentally. Changes may be needed later. | ||
heartShape: { | ||
width: size * 0.25, | ||
height: size * 0.833, | ||
borderTopLeftRadius: size * 0.333, | ||
borderTopRightRadius: size * 0.333, | ||
}, | ||
leftHeart: { | ||
height: size * 0.667, | ||
left: size * 0.167, | ||
top: size * 0.167, | ||
}, | ||
rightHeart: { | ||
right: size * 0.167, | ||
}, | ||
}); | ||
|
||
render() { | ||
const { | ||
size, | ||
color, | ||
isAnimated, | ||
} = this.props; | ||
const componentStyles = this.getStyle(size, color); | ||
const Component = isAnimated ? Animated.View : View; | ||
|
||
return ( | ||
<Component style={[styles.checkMarkContainer, componentStyles.checkMarkContainer]}> | ||
<Component style={[ | ||
styles.heartShape, | ||
componentStyles.heartShape, | ||
styles.leftHeart, | ||
componentStyles.leftHeart, | ||
{ backgroundColor: this.props.color }, | ||
]}/> | ||
<Component style={[ | ||
styles.heartShape, | ||
componentStyles.heartShape, | ||
styles.rightHeart, | ||
componentStyles.rightHeart, | ||
{ backgroundColor: this.props.color }, | ||
]}/> | ||
</Component> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
checkMarkContainer: { | ||
transform: [{ rotate: '-5deg' }], | ||
}, | ||
heartShape: { | ||
position: 'absolute', | ||
top: 0, | ||
}, | ||
leftHeart: { | ||
transform: [{ rotate: '-35deg' }], | ||
}, | ||
rightHeart: { | ||
transform: [{ rotate: '45deg' }], | ||
}, | ||
}); |
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
Oops, something went wrong.