4.0.0 • Published 26 days ago

react-native-bouncy-checkbox v4.0.0

Weekly downloads
759
License
MIT
Repository
github
Last release
26 days ago

Battle Tested ✅

Fully customizable animated bouncy checkbox for React Native

npm version npm Platform - Android and iOS License: MIT styled with prettier

Installation

Add the dependency:

Zero Dependency 🥳

React Native

npm i react-native-bouncy-checkbox

🥳 Version 4.0.0 is here 🚀

  • Complete re-written with Modern Functional Component
  • Fully Refactored with React Hooks
  • Imperative Handle Support
  • Checkbox is controllable with isChecked prop
  • onLongPress support
  • testID support
  • Finally, get rid of disableBuiltInState prop
  • Cool customizable animation options
  • Typescript
  • Community Supported Stable Version

Import

import BouncyCheckbox from "react-native-bouncy-checkbox";

Usage

Basic Usage

<BouncyCheckbox onPress={(isChecked: boolean) => {}} />

Advanced Custom Usage

<BouncyCheckbox
  size={25}
  fillColor="red"
  unFillColor="#FFFFFF"
  text="Custom Checkbox"
  iconStyle={{ borderColor: "red" }}
  innerIconStyle={{ borderWidth: 2 }}
  textStyle={{ fontFamily: "JosefinSans-Regular" }}
  onPress={(isChecked: boolean) => {console.log(isChecked)}}
/>

Configuration - Props

PropertyTypeDefaultDescription
isCheckedbooleanundefinedif you want to control check state yourself, you can use isChecked prop now!
onPressfunctionnullset your own onPress functionality after the bounce effect, callback receives the next isChecked boolean if disableBuiltInState is false
onLongPressfunctionnullset your own onLongPress functionality after the bounce effect, callback receives the next isChecked boolean if disableBuiltInState is false
textstringundefinedset the checkbox's text
textComponentcomponentundefinedset the checkbox's text by a React Component
disableTextbooleanfalseif you want to use checkbox without text, you can enable it
sizenumber25size of width and height of the checkbox
stylestyledefaultset/override the container style
textStylestyledefaultset/override the text style
iconStylestyledefaultset/override the outer icon container style
innerIconStylestyledefaultset/override the inner icon container style
fillColorcolor#f09f48change the checkbox's filled color
unfillColorcolortransparentchange the checkbox's un-filled color when it's not checked
iconComponentcomponentIconset your own icon component
checkIconImageSourceimagedefaultset your own check icon image
textContainerStyleViewStyledefaultset/override the text container style
ImageComponentcomponentImageset your own Image component instead of RN's default Image
TouchableComponentComponentPressableset/override the main TouchableOpacity component with any Touchable Component like Pressable

Animation Configurations

PropertyTypeDefaultDescription
bounceEffectInnumber0.9change the bounce effect when press in
bounceEffectOutnumber1change the bounce effect when press out
bounceVelocityInnumber0.1change the bounce velocity when press in
bounceVelocityOutnumber0.4change the bounce velocity when press out
bouncinessInnumber20change the bounciness when press in
bouncinessOutnumber20change the bounciness when press out

Synthetic Press Functionality with Manual Controlling State

Please check the example runnable project to how to make it work on a real project.

  • The onPress callback WILL RECEIVE the next isChecked when using ref is used.
  • You MUST set the isChecked prop to use your own check state manually.

Here is the basic implementation:

import React from "react";
import {
  SafeAreaView,
  StyleSheet,
  Text,
  TouchableOpacity,
  View,
} from "react-native";
import BouncyCheckbox from "./lib/BouncyCheckbox";
import RNBounceable from "@freakycoder/react-native-bounceable";

const App = () => {
  let bouncyCheckboxRef: BouncyCheckbox | null = null;
  const [checkboxState, setCheckboxState] = React.useState(false);

  return (
    <SafeAreaView
      style={{
        flex: 1,
        alignItems: "center",
        justifyContent: "center",
      }}
    >
      <View style={styles.checkboxesContainer}>
        <Text style={styles.titleSynthetic}>Synthetic Checkbox</Text>
        <Text style={styles.checkboxSyntheticSubtitle}>
          Control Checkbox with Another Button
        </Text>
        <View style={styles.checkboxSyntheticContainer}>
          <BouncyCheckbox
                  ref={bouncyCheckboxRef}
                  disableText
                  fillColor="#9342f5"
                  size={50}
                  iconImageStyle={styles.iconImageStyle}
                  iconStyle={{borderColor: '#9342f5'}}
                  onPress={isChecked => {
                    Alert.alert(`Checked:: ${isChecked}`);
                  }}
          />
          <RNBounceable
                  style={styles.syntheticButton}
                  onPress={() => {
                    if (bouncyCheckboxRef.current) {
                      bouncyCheckboxRef.current.onCheckboxPress();
                    }
                  }}>
            <Text style={{color: '#fff', fontWeight: '600'}}>
              Change Checkbox
            </Text>
          </RNBounceable>
        </View>
      </View>
    </SafeAreaView>
  );
};

const styles = StyleSheet.create({});

export default App;

Another example with isChecked prop:

import React, {useRef} from 'react';
import {ImageBackground, StyleSheet, Text, View} from 'react-native';
import RNBounceable from '@freakycoder/react-native-bounceable';
import BouncyCheckbox, {BouncyCheckboxHandle} from './build/dist';

const App = () => {
  const bouncyCheckboxRef = useRef<BouncyCheckboxHandle>(null);

  const [checkboxState, setCheckboxState] = React.useState(false);

  return (
    <ImageBackground
      style={styles.container}
      source={require('./assets/bg.jpg')}>
      <View
        style={[
          styles.stateContainer,
          {
            backgroundColor: checkboxState ? '#34eb83' : '#eb4034',
          },
        ]}>
        <Text
          style={
            styles.stateTextStyle
          }>{`Check Status: ${checkboxState.toString()}`}</Text>
      </View>
      <BouncyCheckbox
        size={50}
        textStyle={styles.textStyle}
        style={{marginTop: 16}}
        iconImageStyle={styles.iconImageStyle}
        fillColor={'#00C0EE'}
        unFillColor={'transparent'}
        ref={bouncyCheckboxRef}
        isChecked={checkboxState}
        text="Synthetic Checkbox"
        onPress={() => setCheckboxState(!checkboxState)}
      />
      <RNBounceable
        style={styles.syntheticButton}
        onPress={() => {
          bouncyCheckboxRef.current?.onCheckboxPress();
        }}>
        <Text style={{color: '#fff'}}>Synthetic Checkbox Press</Text>
      </RNBounceable>
    </ImageBackground>
  );
};

const styles = 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',
  },
});

export default App;

React Native Bouncy Checkbox Group

We have also this library's checkbox group library as well 🍻 Please take a look 😍

FAQ

How to disable strikethrough?

  • Simply use the textStyle prop and set the textDecorationLine to none
textStyle={{
  textDecorationLine: "none",
}}

How to make square checkbox?

  • Simply use the iconStyle prop and set the borderRadius to 0
innerIconStyle={{
  borderRadius: 0, // to make it a little round increase the value accordingly
}}

Future Plans

  • LICENSE
  • Typescript Challange!
  • Version 2.0.0 is alive 🥳
  • Synthetic Press Functionality
  • Disable built-in check state
  • React Native Bouncy Checkbox Group Library Extension
  • New Animation and More Customizable Animation
  • Version 3.0.0 is alive 🚀
  • Better Documentation
  • Version 4.0.0 is alive 🚀
  • Get rid of disableBuiltInState prop
  • Write an article about the lib on Medium

Credits

Photo by Milad Fakurian on Unsplash

Author

FreakyCoder, kurayogun@gmail.com

License

React Native Bouncy Checkbox is available under the MIT license. See the LICENSE file for more info.

4.0.0

26 days ago

3.0.7

1 year ago

3.0.6

1 year ago

3.0.5

2 years ago

3.0.4

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.1.12

2 years ago

2.1.13

2 years ago

2.1.11

2 years ago

2.1.8

2 years ago

2.1.9

2 years ago

2.1.10

2 years ago

2.1.6

3 years ago

2.1.5

3 years ago

2.1.7

3 years ago

2.1.4

3 years ago

2.1.3

3 years ago

2.1.2

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.0-beta.1

3 years ago

2.0.0

3 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

5 years ago

0.0.1

5 years ago