A highly customizable and animated checkbox component for React Native applications with built-in label support and smooth animations.
- ✅ Animated Interactions - Smooth bounce and scale animations
- 🎨 Highly Customizable - Full control over colors, sizes, and styling
- 📝 Label Support - Built-in text label with custom styling options
- 🎯 Flexible State Management - Controlled and uncontrolled modes
- ♿ Accessibility Ready - Screen reader support and proper semantics
- 🔧 TypeScript Support - Full type safety and IntelliSense
npm install rn-base-component
# or
yarn add rn-base-componentimport React from 'react'
import {Checkbox} from 'rn-base-component'
export default function App() {
return (
<Checkbox label="Accept terms and conditions" onChange={checked => console.log('Checked:', checked)} />
)
}import React, {useState} from 'react'
import {Checkbox} from 'rn-base-component'
export default function ControlledCheckbox() {
const [isChecked, setIsChecked] = useState(false)
return <Checkbox label="Subscribe to newsletter" isChecked={isChecked} onChange={setIsChecked} />
}<Checkbox
label="Custom styled checkbox"
size={30}
borderRadius={15}
fillColor="#4CAF50"
unfillColor="#E0E0E0"
checkMarkColor="#FFFFFF"
borderWidth={2}
onChange={handleChange}
/><Checkbox
label="Brand colored checkbox"
fillColor="#007AFF"
unfillColor="transparent"
checkMarkColor="white"
onChange={handleChange}
/><Checkbox label="Disabled checkbox" disabled disableOpacity={0.3} onChange={handleChange} />import {Icon} from 'react-native-vector-icons/MaterialIcons'
;<Checkbox
label="Custom icon checkbox"
iconComponent={<Icon name="star" size={16} color="gold" />}
onChange={handleChange}
/>;<Checkbox
textComponent={
<View style={styles.customTextContainer}>
<Text style={styles.planTitle}>Premium Plan</Text>
<Text style={styles.planPrice}>$9.99/month</Text>
</View>
}
onChange={handleChange}
/>
const styles = StyleSheet.create({
customTextContainer: {
marginLeft: 12,
},
planTitle: {
fontWeight: 'bold',
},
planPrice: {
color: '#666',
fontSize: 12,
},
})<Checkbox label="Animated checkbox" bounceEffectIn={0.9} bounceEffectOut={1.0} onChange={handleChange} />| Prop | Type | Default | Description |
|---|---|---|---|
size |
number |
Theme default | Size of the checkbox |
label |
string |
undefined |
Text label for the checkbox |
borderRadius |
number |
undefined |
Border radius of the checkbox |
borderWidth |
number |
undefined |
Border width of the checkbox |
fillColor |
string |
'#ffc484' |
Color when checkbox is checked |
isChecked |
boolean |
undefined |
Controlled checked state |
unfillColor |
string |
'transparent' |
Color when checkbox is unchecked |
checkMarkColor |
string |
'white' |
Color of the check mark |
disableOpacity |
number |
0.5 |
Opacity when disabled |
disableText |
boolean |
false |
Disable the text label |
disableBuiltInState |
boolean |
false |
Disable built-in state management |
bounceEffectIn |
number |
0.8 |
Scale value when pressed |
bounceEffectOut |
number |
1.0 |
Scale value when released |
iconComponent |
React.ReactNode |
undefined |
Custom icon component |
textComponent |
React.ReactNode |
undefined |
Custom text component |
iconStyle |
StyleProp<ViewStyle> |
undefined |
Style for the icon container |
innerIconStyle |
StyleProp<ViewStyle> |
undefined |
Style for the inner icon |
style |
StyleProp<ViewStyle> |
undefined |
Style for the container |
labelStyle |
StyleProp<TextStyle> |
undefined |
Style for the label text |
iconImageStyle |
StyleProp<ImageStyle> |
undefined |
Style for the icon image |
textContainerStyle |
StyleProp<ViewStyle> |
undefined |
Style for text container |
checkIconImageSource |
ImageSourcePropType |
Images.check |
Custom check mark image |
onChange |
(checked: boolean) => void |
undefined |
Callback when state changes |
disabled |
boolean |
false |
Disable the checkbox |
import React, {useState} from 'react'
import {View} from 'react-native'
import {Checkbox, Button} from 'rn-base-component'
export default function SimpleForm() {
const [acceptTerms, setAcceptTerms] = useState(false)
const [subscribe, setSubscribe] = useState(false)
const handleSubmit = () => {
if (!acceptTerms) {
alert('Please accept terms and conditions')
return
}
// Submit form
}
return (
<View style={styles.formContainer}>
<Checkbox
label="I accept the terms and conditions"
isChecked={acceptTerms}
onChange={setAcceptTerms}
style={styles.checkboxMargin}
/>
<Checkbox
label="Subscribe to our newsletter"
isChecked={subscribe}
onChange={setSubscribe}
style={styles.checkboxLargeMargin}
/>
<Button disabled={!acceptTerms} onPress={handleSubmit}>
Submit
</Button>
</View>
)
}
const styles = StyleSheet.create({
formContainer: {
padding: 20,
},
checkboxMargin: {
marginBottom: 16,
},
checkboxLargeMargin: {
marginBottom: 24,
},
})const [selectedItems, setSelectedItems] = useState<string[]>([])
const toggleItem = (itemId: string) => {
setSelectedItems(prev => (prev.includes(itemId) ? prev.filter(id => id !== itemId) : [...prev, itemId]))
}
return (
<View>
{items.map(item => (
<Checkbox
key={item.id}
label={item.title}
isChecked={selectedItems.includes(item.id)}
onChange={() => toggleItem(item.id)}
style={styles.listItem}
/>
))}
</View>
)
const styles = StyleSheet.create({
listItem: {
marginBottom: 12,
},
});<View style={styles.settingsContainer}>
<Checkbox
label="Enable notifications"
isChecked={notificationsEnabled}
onChange={setNotificationsEnabled}
fillColor="#007AFF"
style={styles.settingItem}
/>
<Checkbox
label="Dark mode"
isChecked={darkModeEnabled}
onChange={setDarkModeEnabled}
fillColor="#007AFF"
style={styles.settingItem}
/>
</View>
const styles = StyleSheet.create({
settingsContainer: {
padding: 16,
},
settingItem: {
marginBottom: 16,
},
});<View style={styles.cartItem}>
<Checkbox
size={20}
isChecked={item.selected}
onChange={() => toggleItemSelection(item.id)}
fillColor="#4CAF50"
style={styles.cartCheckbox}
/>
<View style={styles.itemDetails}>
<Text style={styles.itemName}>{item.name}</Text>
<Text style={styles.itemPrice}>${item.price}</Text>
</View>
</View>
const styles = StyleSheet.create({
cartItem: {
flexDirection: 'row',
alignItems: 'center',
padding: 12,
},
cartCheckbox: {
marginRight: 12,
},
itemDetails: {
flex: 1,
},
itemName: {
fontSize: 16,
fontWeight: '600',
},
itemPrice: {
fontSize: 14,
color: '#666',
marginTop: 4,
},
});<Checkbox
label={todo.text}
isChecked={todo.completed}
onChange={() => toggleTodo(todo.id)}
fillColor="#28A745"
labelStyle={[styles.todoLabel, todo.completed && styles.todoCompleted]}
/>
const styles = StyleSheet.create({
todoLabel: {
color: '#333',
},
todoCompleted: {
textDecorationLine: 'line-through',
color: '#999',
},
})<Checkbox label="Subtle animation" bounceEffectIn={0.95} bounceEffectOut={1.0} onChange={handleChange} /><Checkbox label="Bouncy animation" bounceEffectIn={0.7} bounceEffectOut={1.1} onChange={handleChange} /><Checkbox label="No animation" bounceEffectIn={1.0} bounceEffectOut={1.0} onChange={handleChange} /><Checkbox
label="Enable accessibility features"
accessibilityLabel="Enable accessibility features checkbox"
accessibilityHint="Toggles accessibility features for the app"
onChange={handleChange}
/><Checkbox
textComponent={<Text accessibilityRole="text">Custom accessible text</Text>}
accessibilityRole="checkbox"
accessibilityState={{checked: isChecked}}
onChange={handleChange}
/>The Checkbox component integrates with the theme system:
// Theme configuration
const theme = {
components: {
Checkbox: {
size: 24,
fillColor: '#007AFF',
unfillColor: 'transparent',
checkMarkColor: '#FFFFFF',
borderWidth: 2,
borderRadius: 4,
},
},
}- Label Clarity - Use clear, concise labels that describe the action
- Visual Feedback - Ensure sufficient color contrast for accessibility
- Touch Targets - Maintain adequate size for easy interaction
- State Management - Use controlled components for complex forms
- Animation Timing - Keep animations quick and subtle
- Error Handling - Provide clear validation feedback
- Use React.memo for checkbox lists with many items
- Avoid frequent state updates during animations
- Consider virtualization for very long checkbox lists
- Optimize custom icon components for smooth animations
Checkbox not responding to touch
- Ensure
onChangecallback is provided - Check if the checkbox is disabled
- Verify there are no overlapping touchable components
Custom icon not showing
- Verify the
iconComponentprop is correctly formatted - Check if custom icons are properly imported
- Ensure icon component dimensions fit within the checkbox
Animation issues
- Check React Native Reanimated installation
- Verify animation values are within reasonable ranges
- Test on different devices for performance
Styling conflicts
- Use specific style props instead of generic
stylewhen possible - Check theme configuration for default values
- Ensure parent container styles don't interfere