Giter VIP home page Giter VIP logo

Comments (1)

rinku-k avatar rinku-k commented on July 4, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.