Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork59
Fully customizable animated bouncy checkbox for React Native
License
WrathChaos/react-native-bouncy-checkbox
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
![]() | ![]() |
Add the dependency:
Zero Dependency 🥳
npm i react-native-bouncy-checkbox
- Complete re-written with Modern Functional Component
- Fully Refactored with React Hooks
- Imperative Handle Support
- Checkbox is controllable with
isCheckedprop onLongPresssupporttestIDsupport- Finally, get rid of
disableBuiltInStateprop - Cool customizable animation options
- Control your own check state with
useBuiltInStateto disable - Typescript
- Community Supported Stable Version
importBouncyCheckboxfrom"react-native-bouncy-checkbox";
<BouncyCheckboxonPress={(isChecked:boolean)=>{}}/>
<BouncyCheckboxsize={25}fillColor="red"unFillColor="#FFFFFF"text="Custom Checkbox"iconStyle={{borderColor:"red"}}innerIconStyle={{borderWidth:2}}textStyle={{fontFamily:"JosefinSans-Regular"}}onPress={(isChecked:boolean)=>{console.log(isChecked)}}/>
To fully control checkbox state outside with your own state, just setuseBuiltInState tofalse and send your state value toisChecked prop
const[localChecked,setLocalChecked]=React.useState(false);<BouncyCheckboxisChecked={localChecked}disableTextfillColor="green"size={50}useBuiltInState={false}iconImageStyle={styles.iconImageStyle}iconStyle={{borderColor:'green'}}onPress={(checked:boolean)=>{// These two should be same valueconsole.log('::Checked::',checked);console.log('::LocalChecked::',localChecked);setLocalChecked(!localChecked);}}/>
| Property | Type | Default | Description |
|---|---|---|---|
| isChecked | boolean | undefined | if you want to control check state yourself, you can useisChecked prop now! |
| onPress | function | null | set your own onPress functionality after the bounce effect, callback receives the nextisChecked boolean if disableBuiltInState is false |
| onLongPress | function | null | set your own onLongPress functionality after the bounce effect, callback receives the nextisChecked boolean if disableBuiltInState is false |
| text | string | undefined | set the checkbox's text |
| textComponent | component | undefined | set the checkbox's text by a React Component |
| disableText | boolean | false | if you want to use checkbox without text, you can enable it |
| useBuiltInState | boolean | false | to fully control the checkbox itself outside with your own state, just set tofalse and send your state value toisChecked prop |
| size | number | 25 | size ofwidth andheight of the checkbox |
| style | style | default | set/override the container style |
| textStyle | style | default | set/override the text style |
| iconStyle | style | default | set/override the outer icon container style |
| innerIconStyle | style | default | set/override the inner icon container style |
| fillColor | color | #f09f48 | change the checkbox's filled color |
| unfillColor | color | transparent | change the checkbox's un-filled color when it's not checked |
| iconComponent | component | Icon | set your own icon component |
| checkIconImageSource | image | default | set your own check icon image |
| textContainerStyle | ViewStyle | default | set/override the text container style |
| ImageComponent | component | Image | set your own Image component instead of RN's default Image |
| TouchableComponent | Component | Pressable | set/override the main TouchableOpacity component with any Touchable Component like Pressable |
| Property | Type | Default | Description |
|---|---|---|---|
| bounceEffectIn | number | 0.9 | change the bounce effect when press in |
| bounceEffectOut | number | 1 | change the bounce effect when press out |
| bounceVelocityIn | number | 0.1 | change the bounce velocity when press in |
| bounceVelocityOut | number | 0.4 | change the bounce velocity when press out |
| bouncinessIn | number | 20 | change the bounciness when press in |
| bouncinessOut | number | 20 | change the bounciness when press out |
Please check theexample runnable project to how to make it work on a real project.
- The
onPresscallbackWILL RECEIVE the nextisCheckedwhen usingrefis used. - You MUST set the
isCheckedprop to use your own check state manually.
Here is the basic implementation:
importReactfrom"react";import{SafeAreaView,StyleSheet,Text,TouchableOpacity,View,}from"react-native";importBouncyCheckboxfrom"./lib/BouncyCheckbox";importRNBounceablefrom"@freakycoder/react-native-bounceable";constApp=()=>{letbouncyCheckboxRef:BouncyCheckbox|null=null;const[checkboxState,setCheckboxState]=React.useState(false);return(<SafeAreaViewstyle={{flex:1,alignItems:"center",justifyContent:"center",}}><Viewstyle={styles.checkboxesContainer}><Textstyle={styles.titleSynthetic}>Synthetic Checkbox</Text><Textstyle={styles.checkboxSyntheticSubtitle}> Control Checkbox with Another Button</Text><Viewstyle={styles.checkboxSyntheticContainer}><BouncyCheckboxref={bouncyCheckboxRef}disableTextfillColor="#9342f5"size={50}iconImageStyle={styles.iconImageStyle}iconStyle={{borderColor:'#9342f5'}}onPress={isChecked=>{Alert.alert(`Checked::${isChecked}`);}}/><RNBounceablestyle={styles.syntheticButton}onPress={()=>{if(bouncyCheckboxRef.current){bouncyCheckboxRef.current.onCheckboxPress();}}}><Textstyle={{color:'#fff',fontWeight:'600'}}> Change Checkbox</Text></RNBounceable></View></View></SafeAreaView>);};conststyles=StyleSheet.create({});exportdefaultApp;
Another example withisChecked prop:
importReact,{useRef}from'react';import{ImageBackground,StyleSheet,Text,View}from'react-native';importRNBounceablefrom'@freakycoder/react-native-bounceable';importBouncyCheckbox,{BouncyCheckboxHandle}from'./build/dist';constApp=()=>{constbouncyCheckboxRef=useRef<BouncyCheckboxHandle>(null);const[checkboxState,setCheckboxState]=React.useState(false);return(<ImageBackgroundstyle={styles.container}source={require('./assets/bg.jpg')}><Viewstyle={[styles.stateContainer,{backgroundColor:checkboxState ?'#34eb83' :'#eb4034',},]}><Textstyle={styles.stateTextStyle}>{`Check Status:${checkboxState.toString()}`}</Text></View><BouncyCheckboxsize={50}textStyle={styles.textStyle}style={{marginTop:16}}iconImageStyle={styles.iconImageStyle}fillColor={'#00C0EE'}unFillColor={'transparent'}ref={bouncyCheckboxRef}isChecked={checkboxState}text="Synthetic Checkbox"onPress={()=>setCheckboxState(!checkboxState)}/><RNBounceablestyle={styles.syntheticButton}onPress={()=>{bouncyCheckboxRef.current?.onCheckboxPress();}}><Textstyle={{color:'#fff'}}>Synthetic Checkbox Press</Text></RNBounceable></ImageBackground>);};conststyles=StyleSheet.create({container:{flex:1,alignItems:'center',justifyContent:'center',},stateContainer:{height:45,width:175,alignItems:'center',justifyContent:'center',borderRadius:12,marginBottom:12,},stateTextStyle:{color:'#fff',fontWeight:'bold',},syntheticButton:{height:50,marginTop:64,borderRadius:12,width:'60%',alignItems:'center',justifyContent:'center',backgroundColor:'#00C0EE',},iconImageStyle:{width:20,height:20,},textStyle:{color:'#010101',fontWeight:'600',},});exportdefaultApp;
We have also this library's checkbox group library as well 🍻 Please take a look 😍
How to disable strikethrough?
- Simply use the
textStyleprop and set thetextDecorationLinetonone
textStyle={{textDecorationLine:"none",}}
How to make square checkbox?
- Simply use the
iconStyleprop and set theborderRadiusto0
innerIconStyle={{borderRadius:0,// to make it a little round increase the value accordingly}}
How to use multiple checkbox and control all of them with one checkbox?
- You can use
isCheckedprop to control all of them one by one and with simple handling function to make them all checked or not
constdata=[{id:0,isChecked:false,},{id:1,isChecked:false,},{id:2,isChecked:false,},]const[checkBoxes,setCheckBoxes]=useState(data);consthandleCheckboxPress=(checked:boolean,id:number)=>{if(id===0){setCheckBoxes(checkBoxes.map(item=>({ ...item,isChecked:checked,})),);return;}setCheckBoxes(checkBoxes.map(item=>item.id===id ?{...item,isChecked:checked} :item,),);};
Please check out the example for this:https://github.com/WrathChaos/react-native-bouncy-checkbox-check-all-with-one-checkbox
LICENSETypescript Challange!Version 2.0.0 is alive 🥳Synthetic Press FunctionalityDisable built-in check stateReact Native Bouncy Checkbox Group Library ExtensionNew Animation and More Customizable AnimationVersion 3.0.0 is alive 🚀Better DocumentationVersion 4.0.0 is alive 🚀Get rid ofdisableBuiltInStateprop- Write an article about the lib on Medium
Photo byMilad Fakurian onUnsplash
FreakyCoder,kurayogun@gmail.com
React Native Bouncy Checkbox is available under the MIT license. See the LICENSE file for more info.
About
Fully customizable animated bouncy checkbox for React Native
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Contributors11
Uh oh!
There was an error while loading.Please reload this page.




