Skip to content

Commit cca595b

Browse files
committed
feat: useBuiltinState prop to disable the builtin state control and let it control fully on dev
1 parent 9949893 commit cca595b

File tree

11 files changed

+25433
-59666
lines changed

11 files changed

+25433
-59666
lines changed

.eslintrc.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
module.exports = {
22
root: true,
3-
extends: [
4-
"eslint:recommended",
5-
"plugin:react/recommended",
6-
"plugin:@typescript-eslint/recommended",
7-
"@react-native-community",
8-
"prettier",
9-
],
3+
extends: "@react-native",
104
ignorePatterns: [
115
"**/*/*.js",
126
"*.js",
@@ -25,13 +19,11 @@ module.exports = {
2519
"react-hooks",
2620
"@typescript-eslint",
2721
"promise",
28-
"jest",
2922
"unused-imports",
3023
],
3124
env: {
3225
browser: true,
3326
es2021: true,
34-
"jest/globals": true,
3527
"react-native/react-native": true,
3628
},
3729
settings: {

README.md

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

38-
## 🥳 <i> Version 4.0.0 is here</i> 🚀
38+
## 🥳 <i> Version 4.1.0 is here</i> 🚀
3939

4040
- **Complete re-written with Modern Functional Component**
4141
- Fully Refactored with React Hooks
@@ -45,6 +45,7 @@ npm i react-native-bouncy-checkbox
4545
- `testID` support
4646
- Finally, get rid of `disableBuiltInState` prop
4747
- Cool customizable animation options
48+
- Control your own check state with `useBuiltInState` to disable
4849
- Typescript
4950
- Community Supported Stable Version
5051

@@ -77,16 +78,42 @@ import BouncyCheckbox from "react-native-bouncy-checkbox";
7778
/>
7879
```
7980

81+
## Disable Built-In State
82+
83+
To fully control checkbox state outside with your own state, just set `useBuiltInState` to `false` and send your state value to `isChecked` prop
84+
85+
```tsx
86+
87+
const [localChecked, setLocalChecked] = React.useState(false);
88+
89+
<BouncyCheckbox
90+
isChecked={localChecked}
91+
disableText
92+
fillColor="green"
93+
size={50}
94+
useBuiltInState
95+
iconImageStyle={styles.iconImageStyle}
96+
iconStyle={{borderColor: 'green'}}
97+
onPress={(checked: boolean) => {
98+
// These two should be same value
99+
console.log('::Checked::', checked);
100+
console.log('::LocalChecked::', localChecked);
101+
setLocalChecked(!localChecked);
102+
}}
103+
/>
104+
```
105+
80106
### Configuration - Props
81107

82108
| Property | Type | Default | Description |
83109
|----------------------| :-------: |:-------------:|------------------------------------------------------------------------------------------------------------------------------------------------|
84-
| **isChecked** | **boolean** | **undefined** | **if you want to control check state yourself, you can use `isChecked` prop now!** |
110+
| **isChecked** | **boolean** | **undefined** | **if you want to control check state yourself, you can use `isChecked` prop now!** |
85111
| onPress | function | null | set your own onPress functionality after the bounce effect, callback receives the next `isChecked` boolean if disableBuiltInState is false |
86112
| onLongPress | function | null | set your own onLongPress functionality after the bounce effect, callback receives the next `isChecked` boolean if disableBuiltInState is false |
87113
| text | string | undefined | set the checkbox's text |
88114
| textComponent | component | undefined | set the checkbox's text by a React Component |
89115
| disableText | boolean | false | if you want to use checkbox without text, you can enable it |
116+
| useBuiltInState | boolean | false | to fully control the checkbox itself outside with your own state, just set to `false` and send your state value to `isChecked` prop |
90117
| size | number | 25 | size of `width` and `height` of the checkbox |
91118
| style | style | default | set/override the container style |
92119
| textStyle | style | default | set/override the text style |

example/App.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@ import {
1111
import AppleHeader from 'react-native-apple-header';
1212
import BottomSearchBar from 'react-native-bottom-search-bar';
1313
import RNBounceable from '@freakycoder/react-native-bounceable';
14-
import BouncyCheckbox, {
15-
BouncyCheckboxHandle,
16-
} from 'react-native-bouncy-checkbox';
14+
import BouncyCheckbox, {BouncyCheckboxHandle} from './build/dist';
1715

1816
const profilePicUri = {
1917
uri: 'https://images.unsplash.com/photo-1519865885898-a54a6f2c7eea?q=80&w=1358&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D',
2018
};
2119

2220
const App: React.FC = () => {
2321
const bouncyCheckboxRef = useRef<BouncyCheckboxHandle>(null);
22+
const [localChecked, setLocalChecked] = React.useState(false);
2423

2524
const renderCheckboxes = () => (
2625
<View style={styles.checkboxesContainer}>
@@ -133,13 +132,19 @@ const App: React.FC = () => {
133132
}}
134133
/>
135134
<BouncyCheckbox
136-
isChecked
135+
isChecked={localChecked}
137136
disableText
138137
fillColor="green"
139138
size={50}
139+
useBuiltInState
140140
iconImageStyle={styles.iconImageStyle}
141141
iconStyle={{borderColor: 'green'}}
142-
onPress={() => {}}
142+
onPress={(checked: boolean) => {
143+
// These two should be same value
144+
console.log('::Checked::', checked);
145+
console.log('::LocalChecked::', localChecked);
146+
setLocalChecked(!localChecked);
147+
}}
143148
/>
144149
</View>
145150
</View>

0 commit comments

Comments
 (0)