Skip to content

Commit 5d67c50

Browse files
committed
New props: useNativeDriver & textStyle 🥳
1 parent c52abe8 commit 5d67c50

File tree

7 files changed

+54
-44
lines changed

7 files changed

+54
-44
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ import BouncyCheckbox from "react-native-bouncy-checkbox";
103103
| iconType | string | Entypo | change the react-native-vector-icons' type |
104104
| iconColor | string | #fdfdfd | change the react-native-vector-icons' color |
105105
| disableTextDecoration | boolean | false | enable/disable text decoration for Text |
106+
| useNativeDriver | boolean | true | enable/disable the useNativeDriver for animation |
107+
| textStyle | style | default | set your own text style |
106108

107109
### Future Plans
108110

example/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const App = () => {
2626
/>
2727
<BouncyCheckbox
2828
fontFamily="JosefinSans-Regular"
29-
onPress={checked => {
29+
onPress={(checked) => {
3030
alert(checked);
3131
}}
3232
/>

example/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* @format
33
*/
44

5-
import {AppRegistry} from 'react-native';
6-
import App from './App';
7-
import {name as appName} from './app.json';
5+
import { AppRegistry } from "react-native";
6+
import App from "./App";
7+
import { name as appName } from "./app.json";
88

99
AppRegistry.registerComponent(appName, () => App);

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"react": "16.12.0",
1616
"react-native": "0.61.5",
1717
"react-native-bottom-search-bar": "0.1.1",
18-
"react-native-bouncy-checkbox": "0.1.1",
18+
"react-native-bouncy-checkbox": "0.1.2",
1919
"react-native-dynamic-vector-icons": "^0.2.1",
2020
"react-native-iphone-x-helper": "^1.2.1",
2121
"react-native-vector-icons": "^6.6.0"

lib/src/BouncyCheckbox.js

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import React, { Component } from "react";
22
import PropTypes from "prop-types";
33
import { Animated, Easing, Text, TouchableOpacity, View } from "react-native";
44
import Icon from "react-native-dynamic-vector-icons";
5-
import styles, { iconContainer, textStyle } from "./BouncyCheckbox.style";
5+
import styles, { _iconContainer, _textStyle } from "./BouncyCheckbox.style";
66

77
class BouncyCheckbox extends Component {
88
constructor(props) {
99
super(props);
1010
this.state = {
1111
checked: false,
12-
springValue: new Animated.Value(1)
12+
springValue: new Animated.Value(1),
1313
};
1414
}
1515

@@ -18,12 +18,14 @@ class BouncyCheckbox extends Component {
1818
}
1919

2020
spring = () => {
21+
const { useNativeDriver } = this.props;
2122
const { checked, springValue } = this.state;
2223
this.setState({ checked: !checked }, () => {
2324
springValue.setValue(0.7);
2425
Animated.spring(springValue, {
2526
toValue: 1,
26-
friction: 3
27+
friction: 3,
28+
useNativeDriver,
2729
}).start();
2830
// Outside of the onPress function
2931
const { onPress } = this.props;
@@ -34,29 +36,29 @@ class BouncyCheckbox extends Component {
3436
renderCheckIcon = () => {
3537
const { checked, springValue } = this.state;
3638
const {
37-
checkboxSize,
38-
borderColor,
39-
fillColor,
40-
borderRadius,
41-
unfillColor,
42-
iconComponent,
4339
iconName,
4440
iconSize,
4541
iconType,
46-
iconColor
42+
iconColor,
43+
fillColor,
44+
borderColor,
45+
unfillColor,
46+
checkboxSize,
47+
borderRadius,
48+
iconComponent,
4749
} = this.props;
4850
return (
4951
<Animated.View
5052
style={[
51-
iconContainer(
53+
_iconContainer(
5254
checkboxSize,
5355
checked,
5456
borderRadius,
5557
borderColor,
5658
fillColor,
5759
unfillColor
5860
),
59-
{ transform: [{ scale: springValue }] }
61+
{ transform: [{ scale: springValue }] },
6062
]}
6163
>
6264
{iconComponent || (
@@ -74,10 +76,11 @@ class BouncyCheckbox extends Component {
7476
render() {
7577
const {
7678
text,
79+
fontSize,
7780
textColor,
81+
textStyle,
7882
fontFamily,
79-
fontSize,
80-
disableTextDecoration
83+
disableTextDecoration,
8184
} = this.props;
8285

8386
return (
@@ -88,13 +91,16 @@ class BouncyCheckbox extends Component {
8891
{this.renderCheckIcon()}
8992
<View style={styles.textContainer}>
9093
<Text
91-
style={textStyle(
92-
this.state.checked,
93-
textColor,
94-
fontFamily,
95-
fontSize,
96-
disableTextDecoration
97-
)}
94+
style={
95+
textStyle ||
96+
_textStyle(
97+
this.state.checked,
98+
textColor,
99+
fontFamily,
100+
fontSize,
101+
disableTextDecoration
102+
)
103+
}
98104
>
99105
{text}
100106
</Text>
@@ -106,20 +112,21 @@ class BouncyCheckbox extends Component {
106112

107113
BouncyCheckbox.propTypes = {
108114
text: PropTypes.string,
109-
textColor: PropTypes.string,
110-
fontFamily: PropTypes.string,
111-
borderRadius: PropTypes.number,
112-
fontSize: PropTypes.number,
113115
isChecked: PropTypes.bool,
114-
checkboxSize: PropTypes.number,
115-
borderColor: PropTypes.string,
116-
fillColor: PropTypes.string,
117-
unfillColor: PropTypes.string,
116+
fontSize: PropTypes.number,
118117
iconName: PropTypes.string,
119-
iconSize: PropTypes.number,
120118
iconType: PropTypes.string,
119+
iconSize: PropTypes.number,
121120
iconColor: PropTypes.string,
122-
disableTextDecoration: PropTypes.bool
121+
textColor: PropTypes.string,
122+
fillColor: PropTypes.string,
123+
fontFamily: PropTypes.string,
124+
unfillColor: PropTypes.string,
125+
borderColor: PropTypes.string,
126+
borderRadius: PropTypes.number,
127+
checkboxSize: PropTypes.number,
128+
useNativeDriver: PropTypes.bool,
129+
disableTextDecoration: PropTypes.bool,
123130
};
124131

125132
BouncyCheckbox.defaultProps = {
@@ -135,8 +142,9 @@ BouncyCheckbox.defaultProps = {
135142
iconColor: "#fdfdfd",
136143
text: "Call my mom 😇",
137144
borderColor: "#ffc484",
145+
useNativeDriver: true,
138146
unfillColor: "transparent",
139-
disableTextDecoration: false
147+
disableTextDecoration: false,
140148
};
141149

142150
export default BouncyCheckbox;

lib/src/BouncyCheckbox.style.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const iconContainer = (
1+
export const _iconContainer = (
22
size,
33
checked,
44
borderRadius,
@@ -14,11 +14,11 @@ export const iconContainer = (
1414
borderWidth: 1,
1515
alignItems: "center",
1616
justifyContent: "center",
17-
backgroundColor: checked ? fillColor : unfillColor
17+
backgroundColor: checked ? fillColor : unfillColor,
1818
};
1919
};
2020

21-
export const textStyle = (
21+
export const _textStyle = (
2222
checked,
2323
textColor,
2424
fontFamily,
@@ -30,15 +30,15 @@ export const textStyle = (
3030
fontFamily,
3131
color: textColor,
3232
textDecorationLine:
33-
!disableTextDecoration && checked ? "line-through" : "none"
33+
!disableTextDecoration && checked ? "line-through" : "none",
3434
};
3535
};
3636

3737
export default {
3838
container: {
3939
margin: 8,
4040
alignItems: "center",
41-
flexDirection: "row"
41+
flexDirection: "row",
4242
},
43-
textContainer: { marginLeft: 16 }
43+
textContainer: { marginLeft: 16 },
4444
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-bouncy-checkbox",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "Fully customizable animated bouncy checkbox for React Native",
55
"keywords": [
66
"bouncy",

0 commit comments

Comments
 (0)