Skip to content

Commit d27f240

Browse files
committed
onPress has a callback of the checked status now
1 parent e28bb0a commit d27f240

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

example/App.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ const App = () => {
2424
}
2525
text="Custom Icon Example"
2626
/>
27-
<BouncyCheckbox fontFamily="JosefinSans-Regular" />
27+
<BouncyCheckbox
28+
fontFamily="JosefinSans-Regular"
29+
onPress={checked => {
30+
alert(checked);
31+
}}
32+
/>
2833
<BouncyCheckbox
2934
text="Get groceries"
3035
fontFamily="JosefinSans-Regular"

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.0.3",
18+
"react-native-bouncy-checkbox": "0.0.5",
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: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,18 @@ class BouncyCheckbox extends Component {
1717
this.setState({ checked: this.props.isChecked });
1818
}
1919

20-
setChecked = () => {
21-
const { checked } = this.state;
22-
this.setState({ checked: !checked });
23-
};
24-
2520
spring = () => {
26-
this.setChecked();
27-
const { springValue } = this.state;
28-
const { onPress } = this.props;
29-
springValue.setValue(0.7);
30-
Animated.spring(springValue, {
31-
toValue: 1,
32-
friction: 3
33-
}).start();
34-
// Outside of the onPress function
35-
if (onPress) onPress(this.state.checked);
21+
const { checked, springValue } = this.state;
22+
this.setState({ checked: !checked }, () => {
23+
springValue.setValue(0.7);
24+
Animated.spring(springValue, {
25+
toValue: 1,
26+
friction: 3
27+
}).start();
28+
// Outside of the onPress function
29+
const { onPress } = this.props;
30+
if (onPress) onPress(this.state.checked);
31+
});
3632
};
3733

3834
renderCheckIcon = () => {

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.0.4",
3+
"version": "0.0.5",
44
"description": "Fully customizable animated bouncy checkbox for React Native",
55
"keywords": [
66
"bouncy",

0 commit comments

Comments
 (0)