Skip to content

Commit 920105b

Browse files
authored
feat(ui): toggle component. closes #235
1 parent 553d043 commit 920105b

File tree

10 files changed

+2085
-100
lines changed

10 files changed

+2085
-100
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import React from 'react';
2+
import {
3+
View,
4+
Animated,
5+
StyleSheet,
6+
} from 'react-native';
7+
8+
interface CheckMarkProps {
9+
size: number;
10+
color: Animated.AnimatedDiffClamp | string;
11+
isAnimated?: boolean;
12+
}
13+
14+
export class CheckMark extends React.Component<CheckMarkProps> {
15+
16+
static defaultProps = {
17+
isAnimated: false,
18+
};
19+
20+
private getStyle = (size: number, color: Animated.AnimatedDiffClamp | string) => ({
21+
checkMarkContainer: {
22+
width: size,
23+
height: size,
24+
},
25+
// the dependence of the variables was determined experimentally. Changes may be needed later.
26+
heartShape: {
27+
width: size * 0.25,
28+
height: size * 0.833,
29+
borderTopLeftRadius: size * 0.333,
30+
borderTopRightRadius: size * 0.333,
31+
},
32+
leftHeart: {
33+
height: size * 0.667,
34+
left: size * 0.167,
35+
top: size * 0.167,
36+
},
37+
rightHeart: {
38+
right: size * 0.167,
39+
},
40+
});
41+
42+
render() {
43+
const {
44+
size,
45+
color,
46+
isAnimated,
47+
} = this.props;
48+
const componentStyles = this.getStyle(size, color);
49+
const Component = isAnimated ? Animated.View : View;
50+
51+
return (
52+
<Component style={[styles.checkMarkContainer, componentStyles.checkMarkContainer]}>
53+
<Component style={[
54+
styles.heartShape,
55+
componentStyles.heartShape,
56+
styles.leftHeart,
57+
componentStyles.leftHeart,
58+
{ backgroundColor: this.props.color },
59+
]}/>
60+
<Component style={[
61+
styles.heartShape,
62+
componentStyles.heartShape,
63+
styles.rightHeart,
64+
componentStyles.rightHeart,
65+
{ backgroundColor: this.props.color },
66+
]}/>
67+
</Component>
68+
);
69+
}
70+
}
71+
72+
const styles = StyleSheet.create({
73+
checkMarkContainer: {
74+
transform: [{ rotate: '-5deg' }],
75+
},
76+
heartShape: {
77+
position: 'absolute',
78+
top: 0,
79+
},
80+
leftHeart: {
81+
transform: [{ rotate: '-35deg' }],
82+
},
83+
rightHeart: {
84+
transform: [{ rotate: '45deg' }],
85+
},
86+
});

src/framework/ui/index.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import {
1111
Layout as LayoutComponent,
1212
Props as LayoutProps,
1313
} from './layout/layout.component';
14+
import {
15+
Toggle as ToggleComponent,
16+
Props as ToggleProps,
17+
} from './toggle/toggle.component';
1418
import {
1519
CheckBox as CheckBoxComponent,
1620
Props as CheckBoxProps,
@@ -35,21 +39,25 @@ import {
3539
const Radio = styled<RadioComponent, RadioProps>(RadioComponent);
3640
const RadioGroup = styled<RadioGroupComponent, RadioGroupProps>(RadioGroupComponent);
3741
const Layout = styled<LayoutComponent, LayoutProps>(LayoutComponent);
42+
const Toggle = styled<ToggleComponent, ToggleProps>(ToggleComponent);
3843
const CheckBox = styled<CheckBoxComponent, CheckBoxProps>(CheckBoxComponent);
3944
const Tab = styled<TabComponent, TabProps>(TabComponent);
4045
const TabBar = styled<TabBarComponent, TabBarProps>(TabBarComponent);
4146

4247
export {
43-
Layout, LayoutProps,
48+
Layout,
49+
LayoutProps,
4450
Radio,
51+
RadioProps,
4552
RadioGroup,
53+
RadioGroupProps,
54+
Toggle,
55+
ToggleProps,
4656
CheckBox,
4757
Tab,
4858
TabBar,
4959
ViewPager,
5060
TabView,
51-
RadioProps,
52-
RadioGroupProps,
5361
CheckBoxProps,
5462
TabProps,
5563
TabBarProps,

0 commit comments

Comments
 (0)