Skip to content

Commit

Permalink
chore(#67): Changed documentation. Made code more readable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sibtain Ali committed Dec 22, 2019
1 parent 756e30b commit 1d4d858
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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<any> | 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

Expand Down
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const defaultProps = {
customSelector: undefined,
initSelectedKeys: [],
multiple: false,
renderCheckbox: undefined,
renderCheckbox: () => {},
};

export default class ModalSelector extends React.Component {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 1d4d858

Please sign in to comment.