Skip to content

Commit f0b3ea2

Browse files
committed
feat: version 3.0.0 🚀
1 parent be637ac commit f0b3ea2

File tree

6 files changed

+116
-69
lines changed

6 files changed

+116
-69
lines changed

README.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,18 @@ Add the dependency:
3535
npm i react-native-bouncy-checkbox
3636
```
3737

38-
## Version 2.0.0 is Here 🥳
38+
## Version 3.0.0 is here 🚀
3939

4040
- Typescript
4141
- **Zero Dependency**
42-
- More Customization Options
43-
- New customization props are available:
44-
- `iconStyle`
45-
- `bounceEffect`
46-
- `bounceFriction`
47-
- `textComponent`
42+
- **New** and More Customizable Animation
43+
- `bounceEffectIn`
44+
- `bounceEffectOut`
45+
- `bounceVelocityIn`
46+
- `bounceVelocityOut`
47+
- `bouncinessIn`
48+
- `bouncinessOut`
49+
- Community Supported Stable Version
4850

4951
## Import
5052

@@ -69,6 +71,7 @@ import BouncyCheckbox from "react-native-bouncy-checkbox";
6971
unfillColor="#FFFFFF"
7072
text="Custom Checkbox"
7173
iconStyle={{ borderColor: "red" }}
74+
iconInnerStyle={{ borderWidth: 2 }}
7275
textStyle={{ fontFamily: "JosefinSans-Regular" }}
7376
onPress={(isChecked: boolean) => {}}
7477
/>
@@ -85,20 +88,30 @@ import BouncyCheckbox from "react-native-bouncy-checkbox";
8588
| size | number | 25 | size of `width` and `height` of the checkbox |
8689
| style | style | default | set/override the container style |
8790
| textStyle | style | default | set/override the text style |
88-
| iconStyle | style | default | set/override the icon style |
91+
| iconStyle | style | default | set/override the outer icon container style |
92+
| innerIconStyle | style | default | set/override the inner icon container style |
8993
| isChecked | boolean | false | set the default checkbox value |
9094
| fillColor | color | #f09f48 | change the checkbox's filled color |
9195
| unfillColor | color | transparent | change the checkbox's un-filled color when it's not checked |
9296
| useNativeDriver | boolean | true | enable/disable the useNativeDriver for animation |
9397
| iconComponent | component | Icon | set your own icon component |
9498
| checkIconImageSource | image | default | set your own check icon image |
9599
| ImageComponent | component | Image | set your own Image component instead of RN's default Image |
96-
| bounceEffect | number | 1 | change the bounce effect |
97-
| bounceFriction | number | 3 | change the bounce friction |
98100
| disableBuiltInState | boolean | false | if you want to manually handle the `isChecked` prop and disable built in handling |
99101
| textContainerStyle | ViewStyle | default | set/override the text container style |
100102
| TouchableComponent | Component | TouchableOpacity | set/override the main TouchableOpacity component with any Touchable Component like Pressable |
101103

104+
### Animation Configurations
105+
106+
| Property | Type | Default | Description |
107+
| ----------------- | :----: | :-----: | ----------------------------------------- |
108+
| bounceEffectIn | number | 0.9 | change the bounce effect when press in |
109+
| bounceEffectOut | number | 1 | change the bounce effect when press out |
110+
| bounceVelocityIn | number | 0.1 | change the bounce velocity when press in |
111+
| bounceVelocityOut | number | 0.4 | change the bounce velocity when press out |
112+
| bouncinessIn | number | 20 | change the bounciness when press in |
113+
| bouncinessOut | number | 20 | change the bounciness when press out |
114+
102115
## Synthetic Press Functionality with Manual Check State
103116

104117
<div>
@@ -218,6 +231,7 @@ iconStyle={{
218231
- [x] ~~Synthetic Press Functionality~~
219232
- [x] ~~Disable built-in check state~~
220233
- [x] ~~React Native Bouncy Checkbox Group Library Extension~~
234+
- [x] ~~New Animation and More Customizable Animation~~
221235
- [ ] Better Documentation | Separation of Documentation
222236
- [ ] Write an article about the lib on Medium
223237

example/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import {View, Text, StatusBar, SafeAreaView, Pressable} from 'react-native';
33
import AppleHeader from 'react-native-apple-header';
44
import BottomSearchBar from 'react-native-bottom-search-bar';
5-
import BouncyCheckbox from 'react-native-bouncy-checkbox';
5+
import BouncyCheckbox from './build/dist/BouncyCheckbox';
66

77
export default class App extends React.Component {
88
render() {

lib/BouncyCheckbox.style.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import { ViewStyle, TextStyle, ImageStyle, StyleSheet } from "react-native";
2-
3-
interface Style {
4-
container: ViewStyle;
5-
textContainer: ViewStyle;
6-
iconImageStyle: ImageStyle;
7-
}
1+
import { ViewStyle, TextStyle, StyleSheet } from "react-native";
82

93
export const _iconContainer = (
104
size: number,
@@ -15,8 +9,6 @@ export const _iconContainer = (
159
return {
1610
width: size,
1711
height: size,
18-
borderWidth: 1,
19-
borderColor: fillColor,
2012
borderRadius: size / 2,
2113
alignItems: "center",
2214
justifyContent: "center",
@@ -32,7 +24,7 @@ export const _textStyle = (checked: boolean): TextStyle => {
3224
};
3325
};
3426

35-
export default StyleSheet.create<Style>({
27+
export default StyleSheet.create<any>({
3628
container: {
3729
alignItems: "center",
3830
flexDirection: "row",
@@ -44,4 +36,24 @@ export default StyleSheet.create<Style>({
4436
textContainer: {
4537
marginLeft: 16,
4638
},
39+
iconContainer: (
40+
size: number,
41+
checked: boolean,
42+
fillColor: string,
43+
unfillColor: string,
44+
) => ({
45+
width: size,
46+
height: size,
47+
borderRadius: size / 2,
48+
backgroundColor: checked ? fillColor : unfillColor,
49+
}),
50+
innerIconContainer: (size: number, fillColor: string) => ({
51+
width: size,
52+
height: size,
53+
borderWidth: 1,
54+
borderColor: fillColor,
55+
borderRadius: size / 2,
56+
alignItems: "center",
57+
justifyContent: "center",
58+
}),
4759
});

lib/BouncyCheckbox.tsx

Lines changed: 66 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ import {
33
Text,
44
View,
55
Image,
6-
Easing,
76
Animated,
87
StyleProp,
98
ViewStyle,
109
TextStyle,
11-
TouchableOpacity,
10+
Pressable,
1211
ImageSourcePropType,
1312
TouchableWithoutFeedbackProps,
1413
} from "react-native";
15-
import styles, { _textStyle, _iconContainer } from "./BouncyCheckbox.style";
14+
import styles, { _textStyle } from "./BouncyCheckbox.style";
1615

1716
type CustomStyleProp = StyleProp<ViewStyle> | Array<StyleProp<ViewStyle>>;
1817
type CustomTextStyleProp = StyleProp<TextStyle> | Array<StyleProp<TextStyle>>;
@@ -24,20 +23,27 @@ type BaseTouchableProps = Pick<
2423
export interface IBouncyCheckboxProps extends BaseTouchableProps {
2524
size?: number;
2625
text?: string;
27-
iconStyle?: any;
2826
fillColor?: string;
2927
isChecked?: boolean;
3028
unfillColor?: string;
3129
disableText?: boolean;
32-
ImageComponent?: any;
3330
bounceEffect?: number;
3431
bounceFriction?: number;
3532
useNativeDriver?: boolean;
3633
disableBuiltInState?: boolean;
34+
ImageComponent?: any;
3735
TouchableComponent?: any;
36+
bounceEffectIn?: number;
37+
bounceEffectOut?: number;
38+
bounceVelocityIn?: number;
39+
bounceVelocityOut?: number;
40+
bouncinessIn?: number;
41+
bouncinessOut?: number;
3842
iconComponent?: React.ReactNode;
3943
textComponent?: React.ReactNode;
40-
style?: StyleProp<ViewStyle>;
44+
iconStyle?: CustomStyleProp;
45+
innerIconStyle?: CustomStyleProp;
46+
style?: CustomStyleProp;
4147
textStyle?: CustomTextStyleProp;
4248
iconImageStyle?: CustomStyleProp;
4349
textContainerStyle?: CustomStyleProp;
@@ -48,6 +54,7 @@ export interface IBouncyCheckboxProps extends BaseTouchableProps {
4854
interface IState {
4955
checked: boolean;
5056
springValue: Animated.Value;
57+
bounceValue: Animated.Value;
5158
}
5259

5360
const defaultCheckImage = require("./check.png");
@@ -58,44 +65,26 @@ class BouncyCheckbox extends React.Component<IBouncyCheckboxProps, IState> {
5865
this.state = {
5966
checked: false,
6067
springValue: new Animated.Value(1),
68+
bounceValue: new Animated.Value(1),
6169
};
6270
}
6371

6472
componentDidMount() {
6573
this.setState({ checked: this.props.isChecked || false });
6674
}
6775

68-
onPress = () => {
69-
const {
70-
disableBuiltInState = false,
71-
useNativeDriver = true,
72-
bounceEffect = 1,
73-
bounceFriction = 3,
74-
} = this.props;
75-
const { checked, springValue } = this.state;
76-
if (!disableBuiltInState) {
77-
this.setState({ checked: !checked }, () => {
78-
springValue.setValue(0.7);
79-
Animated.spring(springValue, {
80-
toValue: bounceEffect,
81-
friction: bounceFriction,
82-
useNativeDriver,
83-
}).start();
84-
this.props.onPress && this.props.onPress(this.state.checked);
85-
});
86-
} else {
87-
springValue.setValue(0.7);
88-
Animated.spring(springValue, {
89-
toValue: bounceEffect,
90-
friction: bounceFriction,
91-
useNativeDriver,
92-
}).start();
93-
this.props.onPress && this.props.onPress(this.state.checked);
94-
}
76+
bounceEffect = (value: number, velocity: number, bounciness: number) => {
77+
const { useNativeDriver = true } = this.props;
78+
Animated.spring(this.state.bounceValue, {
79+
toValue: value,
80+
velocity,
81+
bounciness,
82+
useNativeDriver,
83+
}).start();
9584
};
9685

9786
renderCheckIcon = () => {
98-
const { checked, springValue } = this.state;
87+
const { checked } = this.state;
9988
const {
10089
size = 25,
10190
iconStyle,
@@ -106,25 +95,30 @@ class BouncyCheckbox extends React.Component<IBouncyCheckboxProps, IState> {
10695
unfillColor = "transparent",
10796
disableBuiltInState,
10897
isChecked,
98+
innerIconStyle,
10999
checkIconImageSource = defaultCheckImage,
110100
} = this.props;
111101

112102
const checkStatus = disableBuiltInState ? isChecked! : checked;
113103
return (
114104
<Animated.View
115105
style={[
116-
{ transform: [{ scale: springValue }] },
117-
_iconContainer(size, checkStatus, fillColor, unfillColor),
106+
{ transform: [{ scale: this.state.bounceValue }] },
107+
styles.iconContainer(size, checkStatus, fillColor, unfillColor),
118108
iconStyle,
119109
]}
120110
>
121-
{iconComponent ||
122-
(checkStatus && (
123-
<ImageComponent
124-
source={checkIconImageSource}
125-
style={[styles.iconImageStyle, iconImageStyle]}
126-
/>
127-
))}
111+
<View
112+
style={[styles.innerIconContainer(size, fillColor), innerIconStyle]}
113+
>
114+
{iconComponent ||
115+
(checkStatus && (
116+
<ImageComponent
117+
source={checkIconImageSource}
118+
style={[styles.iconImageStyle, iconImageStyle]}
119+
/>
120+
))}
121+
</View>
128122
</Animated.View>
129123
);
130124
};
@@ -158,13 +152,40 @@ class BouncyCheckbox extends React.Component<IBouncyCheckboxProps, IState> {
158152
);
159153
};
160154

155+
handleCheck = () => {
156+
const { disableBuiltInState = false } = this.props;
157+
const { checked } = this.state;
158+
if (!disableBuiltInState) {
159+
this.setState({ checked: !checked }, () => {
160+
this.props.onPress && this.props.onPress(this.state.checked);
161+
});
162+
} else {
163+
this.props.onPress && this.props.onPress(this.state.checked);
164+
}
165+
};
166+
161167
render() {
162-
const { style, TouchableComponent = TouchableOpacity } = this.props;
168+
const {
169+
style,
170+
bounceEffectIn = 0.9,
171+
bounceEffectOut = 1,
172+
bounceVelocityIn = 0.1,
173+
bounceVelocityOut = 0.4,
174+
bouncinessIn = 20,
175+
bouncinessOut = 20,
176+
TouchableComponent = Pressable,
177+
} = this.props;
163178
return (
164179
<TouchableComponent
165180
{...this.props}
166181
style={[styles.container, style]}
167-
onPress={this.onPress.bind(this, Easing.bounce)}
182+
onPressIn={() => {
183+
this.bounceEffect(bounceEffectIn, bounceVelocityIn, bouncinessIn);
184+
}}
185+
onPressOut={() => {
186+
this.bounceEffect(bounceEffectOut, bounceVelocityOut, bouncinessOut);
187+
this.handleCheck();
188+
}}
168189
>
169190
{this.renderCheckIcon()}
170191
{this.renderCheckboxText()}

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.

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

0 commit comments

Comments
 (0)