Comments (1)
Its working fine with below example:
import React, { Component } from 'react';
import CheckboxList from '../src/checkList';
import {
View,
Text,
ActivityIndicator,
SafeAreaView,
Platform,
Image,
} from 'react-native';
import Emojis from './images';
const data = Emojis;
const renderItem = ({ item }) => {
return (
<View
style={{ flexDirection: 'row', alignItems: 'center' }}
key={item.name}>
<Image source={item.src} style={{ width: 50, height: 50 }} />
<Text
numberOfLines={1}
style={{
fontSize: 20,
color: '#626262',
margin: 10,
}}>
{item.name}
</Text>
</View>
);
};
class Selector extends Component {
constructor(props) {
super(props);
this.preSelectedItems = data.slice(0, 4);
this.state = {
loader: true,
selectedItems1: [],
selectedItems2: [],
};
}
componentDidMount() {
setTimeout(() => {
this.setState({ loader: false });
this.setState({ selectedItems1: this.preSelectedItems });
this.setState({ selectedItems2: this.preSelectedItems });
}, 500);
}
render() {
const theme = 'red';
const border = 'grey';
return (
<SafeAreaView style={{ flex: 1 }}>
<View style={{ flex: 1 }}>
<CheckboxList
headerName="Emojis"
theme={theme}
listItems={this.state.loader ? [] : data}
onChange={({ ids, items }) => {
// eslint-disable-next-line no-console
console.log('My updated list 1 :: ', ids, items);
this.setState({ selectedItems1: items });
}}
onLoading={() => (
<View
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}}>
<ActivityIndicator size="large" color="red" />
<Text style={{ fontSize: 16, color: '#555555' }}>
Loading....
</Text>
</View>
)}
selectedListItems={data.slice(0, 4)}
checkboxProp={Platform.select({
// Optional
ios: {
// iOS (supported from v0.3.0)
boxType: 'square',
tintColor: border,
onTintColor: theme,
onCheckColor: '#fff',
onFillColor: theme,
},
android: {
tintColors: {
true: theme,
false: border,
},
},
})}
renderItem={renderItem}
/>
</View>
<View style={{ flex: 1 }}>
<CheckboxList
headerName="Emojis"
theme={theme}
listItems={this.state.loader ? [] : data}
onChange={({ ids, items }) => {
// eslint-disable-next-line no-console
console.log('My updated list 2 :: ', ids, items);
this.setState({ selectedItems2: items });
}}
onLoading={() => (
<View
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}}>
<ActivityIndicator size="large" color="red" />
<Text style={{ fontSize: 16, color: '#555555' }}>
Loading....
</Text>
</View>
)}
selectedListItems={data.slice(0, 4)}
checkboxProp={Platform.select({
// Optional
ios: {
// iOS (supported from v0.3.0)
boxType: 'square',
tintColor: border,
onTintColor: theme,
onCheckColor: '#fff',
onFillColor: theme,
},
android: {
tintColors: {
true: theme,
false: border,
},
},
})}
renderItem={renderItem}
/>
</View>
<View
style={{
position: 'absolute',
top: 8,
right: 10,
height: 20,
borderRadius: 4,
}}>
<Text style={{ color: 'black' }}>
Total selected1 : {this.state.selectedItems1.length}
</Text>
</View>
<View
style={{
position: 'absolute',
top: 20,
right: 10,
height: 20,
borderRadius: 4,
}}>
<Text style={{ color: 'black' }}>
Total selected2 : {this.state.selectedItems2.length}
</Text>
</View>
</SafeAreaView>
);
}
}
export default Selector;
Please share your code snippet if you are still facing issue
from rn-checkbox-list.
Related Issues (17)
- error headerName HOT 2
- requireNativeComponent "androidCheckbox" was not found in the UI manager HOT 1
- rn-checkbox-list mandatory dependency is not part of installation instruction HOT 1
- Add TypeScript definition file
- line break support for checkbox text
- headerStyle doesnt handle header text style
- select only "count" out of all - new functionality
- How to get selected values HOT 1
- checkbox text customization
- Ability to change list items order
- custom render component support
- selected item issue HOT 1
- Getting infinite rendering loop when setting state in the onChange callback
- not visible on ios HOT 4
- can i see example of selectedListItems for select HOT 1
- Elements in the list disappear HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rn-checkbox-list.