@@ -2,6 +2,7 @@ import React, { Component } from "react";
22import PropTypes from "prop-types" ;
33import { Animated , Easing , Text , TouchableOpacity , View } from "react-native" ;
44import Icon from "react-native-dynamic-vector-icons" ;
5+ import { iconContainer } from "./BouncyCheckbox.style" ;
56
67class BouncyCheckbox extends Component {
78 constructor ( props ) {
@@ -12,6 +13,10 @@ class BouncyCheckbox extends Component {
1213 } ;
1314 }
1415
16+ componentDidMount ( ) {
17+ this . setState ( { checked : this . props . isChecked } ) ;
18+ }
19+
1520 setChecked = ( ) => {
1621 const { checked } = this . state ;
1722 this . setState ( { checked : ! checked } ) ;
@@ -20,38 +25,53 @@ class BouncyCheckbox extends Component {
2025 spring = ( ) => {
2126 this . setChecked ( ) ;
2227 const { springValue } = this . state ;
28+ const { onPress } = this . props ;
2329 springValue . setValue ( 0.7 ) ;
2430 Animated . spring ( springValue , {
2531 toValue : 1 ,
2632 friction : 3
2733 } ) . start ( ) ;
34+ // Outside of the onPress function
35+ if ( onPress ) onPress ( ) ;
2836 } ;
2937
3038 renderCheckIcon = ( ) => {
3139 const { checked, springValue } = this . state ;
40+ const { checkboxSize, borderColor, fillColor, unfillColor } = this . props ;
3241 return (
3342 < Animated . View
3443 style = { [
35- {
36- width : 35 ,
37- height : 35 ,
38- borderWidth : 1 ,
39- borderRadius : 35 ,
40- borderColor : "orange" ,
41- alignItems : "center" ,
42- justifyContent : "center" ,
43- backgroundColor : checked ? "orange" : "transparent"
44- } ,
44+ iconContainer (
45+ checkboxSize ,
46+ checked ,
47+ borderColor ,
48+ fillColor ,
49+ unfillColor
50+ ) ,
4551 { transform : [ { scale : springValue } ] }
4652 ] }
4753 >
48- < Icon name = "check" type = "Entypo" size = { 20 } color = "white" />
54+ < Icon
55+ { ...this . props }
56+ name = "check"
57+ type = "Entypo"
58+ size = { 15 }
59+ color = "white"
60+ />
4961 </ Animated . View >
5062 ) ;
5163 } ;
5264
5365 render ( ) {
54- const { text, onPress } = this . props ;
66+ const {
67+ text,
68+ size,
69+ isChecked,
70+ borderColor,
71+ fillColor,
72+ unfillColor,
73+ onPress
74+ } = this . props ;
5575
5676 return (
5777 < TouchableOpacity
@@ -66,12 +86,13 @@ class BouncyCheckbox extends Component {
6686 < View style = { { marginLeft : 16 } } >
6787 < Text
6888 style = { {
89+ fontSize : 16 ,
6990 color : "#757575" ,
70- fontSize : 18 ,
71- fontFamily : "JosefinSans-Regular "
91+ fontFamily : "JosefinSans-Regular" ,
92+ textDecorationLine : this . state . checked ? "line-through" : "none "
7293 } }
7394 >
74- Call my mom
95+ { text }
7596 </ Text >
7697 </ View >
7798 </ TouchableOpacity >
@@ -80,11 +101,21 @@ class BouncyCheckbox extends Component {
80101}
81102
82103BouncyCheckbox . propTypes = {
83- example : PropTypes . number
104+ text : PropTypes . string ,
105+ isChecked : PropTypes . bool ,
106+ checkboxSize : PropTypes . number ,
107+ borderColor : PropTypes . string ,
108+ fillColor : PropTypes . string ,
109+ unfillColor : PropTypes . string
84110} ;
85111
86112BouncyCheckbox . defaultProps = {
87- example : 5
113+ checkboxSize : 25 ,
114+ isChecked : false ,
115+ text : "Call my mom" ,
116+ fillColor : "#f09f48" ,
117+ borderColor : "#f09f48" ,
118+ unfillColor : "transparent"
88119} ;
89120
90121export default BouncyCheckbox ;
0 commit comments