From 1d4d8588e0cd513ac85b16f1d4e75411d7ba4809 Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Sun, 22 Dec 2019 21:02:20 +0500 Subject: [PATCH] chore(#67): Changed documentation. Made code more readable. --- README.md | 8 +++++++- index.js | 8 +++++--- package.json | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f4e96202..404cbdc3 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,12 @@ If you have an urgent problem, hire a mentor for a 1:1 live session on Git-Start Help others in paid 1:1 live sessions to get started. [![Give paid 1:1 live support.](https://git-start.com/assets/git-start-mentor-banner-medium.svg?sanitize=true)](https://git-start.com/help-request/overview/peacechen%2Freact-native-modal-selector) +## Breaking changes + +Version 2.0.0 onwards support multi-select feature. As such, following properties from the versions before have changed. + +1) `selectedKey` is now `initSelectedKeys`. It accepts an array of keys. +2) `getSelectedItem` is now `getSelectedItems`. It returns an array of selected items. ## Usage @@ -181,7 +187,7 @@ Prop | Type | Optional | Default | Description `customSelector` | node | Yes | undefined | Render a custom node instead of the built-in select box. `initSelectedKeys` | array | Yes | [] | Key of the items to be initially selected. Should contain only one key if `multiple` is selected as false. `multiple` | bool | No | false | Adds the ability to select multiple options. -`renderCheckbox` | function | No | (checked, onPress) => {} | Function that returns a checkbox element. Arguments of the function include `checked` state and `onPress` function that gets executed when the element is pressed. +`renderCheckbox` | function | Yes | (checked, onPress) => {} | Function that returns a checkbox element. Arguments of the function include `checked` state and `onPress` function that gets executed when the element is pressed. Required only if multiple option is selected. ### Methods diff --git a/index.js b/index.js index 924cc4d9..de86ea71 100644 --- a/index.js +++ b/index.js @@ -128,7 +128,7 @@ const defaultProps = { customSelector: undefined, initSelectedKeys: [], multiple: false, - renderCheckbox: undefined, + renderCheckbox: () => {}, }; export default class ModalSelector extends React.Component { @@ -186,12 +186,14 @@ export default class ModalSelector extends React.Component { onChange = (item, checked = false) => { let { selected } = this.state; const itemKey = this.props.keyExtractor(item); - if (this.props.multiple) + if (this.props.multiple) { checked ? selected.push(itemKey) : selected.indexOf(itemKey) >= 0 && delete selected[selected.indexOf(itemKey)]; - else selected = [itemKey]; + } else { + selected = [itemKey]; + } if ( Platform.OS === "android" || (Modal.propTypes !== undefined && !Modal.propTypes.onDismiss) diff --git a/package.json b/package.json index 63128b39..244c28f9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-modal-selector", - "version": "1.1.3", + "version": "2.0.0", "description": "A cross-platform (iOS / Android), selector/picker component for React Native that is highly customizable and supports sections.", "main": "index.js", "typings": "index.d.ts",