• Stars
    star
    201
  • Rank 194,491 (Top 4 %)
  • Language
    TypeScript
  • Created over 5 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An unified React Native Picker Modal component for iOS and Android.


React Native Picker Modal View

React Native Module to select item picker modal.

Maintainability Test Coverage npm version npm downloads per month dependencies Status dev-dependencies Status Build Status Meercode CI Score


Created by Pankod

An alternative to Picker and PickerIOS components with an unified API and consistent look & feel on both plaforms. It's fully configurable and includes built-in support for text search and alphabetical index. Ideal for longer lists not suitable for "wheel-pickers".

Getting started

$ npm install react-native-picker-modal-view --save

or

$ yarn add react-native-picker-modal-view

Live Demo with Expo

Explore with Expo Snack

Example

import * as React from 'react';
import { Button, SafeAreaView, Text, View } from 'react-native';

import PickerModal from 'react-native-picker-modal-view';

import data from '../../../top20.json';

export default class Main extends React.Component<{}, { selectedItem: {} }> {

	constructor(props: {}) {
		super(props);

		this.state = {
			selectedItem: {}
		};
	}

	public render(): JSX.Element {
		const { selectedItem } = this.state;

		return (
			<SafeAreaView style={{ flex: 1, justifyContent: 'center', marginHorizontal: 20 }}>
				<PickerModal
					renderSelectView={(disabled, selected, showModal) =>
						<Button disabled={disabled} title={'Show me!'} onPress={showModal} />
					}
					onSelected={this.onSelected.bind(this)}
					onClosed={this.onClosed.bind(this)}
					onBackButtonPressed={this.onBackButtonPressed.bind(this)}
					items={data}
					sortingLanguage={'tr'}
					showToTopButton={true}
					selected={selectedItem}
					showAlphabeticalIndex={true}
					autoGenerateAlphabeticalIndex={true}
					selectPlaceholderText={'Choose one...'}
					onEndReached={() => console.log('list ended...')}
					searchPlaceholderText={'Search...'}
					requireSelection={false}
					autoSort={false}
				/>
				<View style={{ padding: 10, alignItems: 'center', backgroundColor: '#ddd' }}>
					<Text>Chosen: </Text>
					<Text>{JSON.stringify(selectedItem)}</Text>
				</View>
			</SafeAreaView>
		);
	}

	private onClosed(): void {
		console.log('close key pressed');
	}

	private onSelected(selected: any): void {
		this.setState({ selectedItem: selected });

		return selected;
	}

	private onBackButtonPressed(): void {
		console.log('back key pressed');
	}
}

Options


Properties Type Description Default
modalAnimationType string The RN Modal show/hide animation type "slide"
showAlphabeticalIndex boolean Hides alphabetical index "true"
onClosed Function Fired when the modal is closed
onBackButtonPressed Function Fired when the back key is pressed
onSelected
*required
Function Returns selected item object "{Id, Name, Value, [key: string]: any}"
items
*required
array Array of list items "[{Id, Name, Value, [key: string]: any}]"
renderSelectView Element Render Select Component <SelectBoxComponent (built-in)>
renderListItem Element Render List item <ListItemComponent (built-in)/>
alphabeticalIndexChars array Chracters array for the alphabetical index <Turkish alphabet chracters>
searchInputTextColor string Search input placeholder text color "#252525"
keyExtractor Function Flatlist defined {key} function <Predefined return map index>
autoGenerateAlphabeticalIndex boolean Auto-generates alphabetical index from list items data "false"
sortingLanguage string Country ISO (Alpha 2) Code for localeCompare "tr"
showToTopButton boolean Button for scroll to offset 0 "true"
onEndReached Function Fired when the list reaches the end
selectPlaceholderText string Select box placeholder text "Choose one..."
searchPlaceholderText string Search input placeholder text "Search..."
selected object Default selected item
autoSort boolean Auto-sort data list "false"
disabled boolean Disable Select box
requireSelection boolean Require at least one list item is selected "false"
backButtonDisabled boolean Hide to back button "false"
renderSearch Function Render custom search input ``

Core Props of React Native


Properties Type Description Default
ModalProps object React Native Modal Props
FlatListProps object React Native Flatlist Props
SearchInputProps object React Native TextInput Props


Running example project

  1. You should have React Expo CLI to be installed in order to run example. Follow this instructions if you need to install Expo CLI.

  1. Install the dependencies:
npm install
  1. Once the installation is done, you can run the following command:

npm

npm start

You can also use:

expo

expo start

yarn

expo start

Notes

  • Auto-alphabetical index supported for Turkish and English languages.

Releases

  • 1.3.2 - Added renderSearch feature #54 Thanks to @murilo-campaner
  • 1.3.1 - Fixed #44 Thanks to @fnando
  • 1.3.0 - No back button support #42 Thanks to @ChildishForces
  • 1.2.8 - Fixed #37
  • 1.2.6 - Deprecated lifecycle methods fix
  • 1.2.5 - Flatlist initialNumToRender property hotfix
  • 1.2.3 - Refactor and code coverage
  • 1.2.2 - Fixed #5
  • 1.2.0 - Added renderSelectView and renderListItem properties.
  • 1.0.0 - Initial release

More Repositories

1

superplate

A well-structured production-ready frontend boilerplate with Typescript, React Testing Library, styled-component, React Query, .env, Axios, Bundle Analyzer, Prettier and 30+ plugins. superplate creates projects for React.js, Next.js, and refine. https://pankod.github.io/superplate/
TypeScript
2,601
star
2

next-boilerplate

A well-structured production ready Next.js boilerplate with Typescript, Redux, Jest, Enzyme, Express.js, Sass, Css, EnvConfig, Fetch, Reverse Proxy, Bundle Analyzer and Built-in Project CLI. https://pankod.github.io/next-boilerplate/
TypeScript
1,558
star
3

svelte-boilerplate

Svelte application boilerplate with Webpack, Babel, PostCSS, Sass, Fetch, Jest, .Env, EsLint.
JavaScript
288
star
4

canvas2video

canvas2video is a backend solution for creating and rendering dynamic videos.
TypeScript
244
star
5

moleculerjs-boilerplate

A well-structured Moleculer JS Boilerplate with Typescript, CLI, Service Helpers, Swagger, Jest support and everything you'll ever need to deploy rock solid projects. https://pankod.github.io/moleculerjs-boilerplate/
TypeScript
188
star
6

react-native-boilerplate

A well-structured React Native Boilerplate with Typescript, Redux, Jest & Enzyme support and everything you'll ever need to deploy rock solid apps.
TypeScript
83
star
7

react-native-store-rating

Ratings and reviews influence how your app ranks in search results, and can affect whether someone downloads your app. Users can rate your app on a scale of desired amount of stars.
TypeScript
81
star
8

superplate-core-plugins

TypeScript
46
star
9

frontend-challenge

The recruitment test to apply for an Front-End developer role at Pankod
40
star
10

pankod-cli

Save a lot of time by generating services, components, tests for Pankod Boilerplate projects.
TypeScript
29
star
11

react-hooks-example

React Hooks Example
JavaScript
23
star
12

react-hooks-screen-type

Determining screen size type for Bootstrap 4 grid.
JavaScript
15
star
13

react-typescript-npm-package-boilerplate

TypeScript
12
star
14

typescript-enum-helper

typescript enum helper example
TypeScript
7
star
15

sapper-boilerplate

JavaScript
7
star
16

docusaurus-boilerplate

Thanks to this project, itโ€™ll be too easy to add documentation site to pankod open source projects.
JavaScript
7
star
17

react-checkbox

React checkbox component
JavaScript
7
star
18

react-native-photo-gallery-view

6
star
19

superplate-react-core-plugins

TypeScript
6
star
20

project-splash

Thanks to this component, itโ€™ll be too easy to add splash to pankod open source projects.
HTML
6
star
21

cli-boilerplate

Thanks to this project, itโ€™ll be too easy to add CLI to Pankod projects.
TypeScript
5
star
22

expo-boilerplate

Thanks to this project, itโ€™ll be too easy to add example to Pankod open source projects.
HTML
4
star
23

react-hooks-show-more-text

Handle showing more text / less text with react hooks
JavaScript
4
star
24

react-rating-star

3
star
25

react-native-rating-modal

TypeScript
2
star
26

typescript-npm-package-boilerplate

TypeScript
2
star
27

next-html

Import html in Next.js
JavaScript
1
star