• Stars
    star
    104
  • Rank 330,604 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 3 years ago

Reviews

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

Repository Details

Cross-platform modal picker for React Native which supports keyword filtering, custom rendering, etc

react-native-modal-filter-picker

npm Join the chat at https://discord.gg/bYt4tWB Follow on Twitter

Demo

A cross-platform (iOS, Android) modal picker for React Native.

Features:

  • Cross-platform (iOS, Android)
  • Default styling works well
  • Extensively customisable styling and rendering
  • Built-in search filter for long lists
  • Uses React Native FlatList for lazy-loading and high performance
  • Compatible with React Native 0.40+
  • Successfully used in production apps

Installation

Use NPM/Yarn to install package: react-native-modal-filter-picker

Usage

A basic demo:

import { Component, View, Text, TouchableOpacity } from 'react-native'

import ModalFilterPicker from 'react-native-modal-filter-picker'


export default class App extends Component {
  constructor (props, ctx) {
    super(props, ctx);

    this.state = {
      visible: false,
      picked: null,
    };
  }

  render() {
    const { visible, picked } = this.state;

    const options = [
      {
        key: 'kenya',
        label: 'Kenya',
      },
      {
        key: 'uganda',
        label: 'Uganda',
      },
      {
        key: 'libya',
        label: 'Libya',
      },
      {
        key: 'morocco',
        label: 'Morocco',
      },
      {
        key: 'estonia',
        label: 'Estonia',
      },
    ];

    return (
      <View style={styles.container}>
        <TouchableOpacity style={styles.buttonContainer} onPress={this.onShow}>
          <Text>Select country</Text>
        </TouchableOpacity>      
        <Text style={appStyles.label}>Selected:</Text>
        <Text>{picked}</Text>
        <ModalFilterPicker
          visible={visible}
          onSelect={this.onSelect}
          onCancel={this.onCancel}
          options={options}
        />
      </View>
    );
  }

  onShow = () => {
    this.setState({ visible: true });
  }

  onSelect = (picked) => {
    this.setState({
      picked: picked,
      visible: false
    })
  }

  onCancel = () => {
    this.setState({
      visible: false
    });
  }
}

Options

The following functionality props can be passed to the component:

Prop name Type Default Description
options Array of { key, label } (required) The options to display in the list
onSelect function (key) {} (required) Callback for when an option is chosen
onCancel function () {} (required) Callback for when the cancel button is pressed
placeholderText String "Filter..." Placeholder text for filter input text field
placeholderTextColor String "#ccc" Color of placeholder text for filter input text field
androidUnderlineColor String "rgba(0,0,0,0)" Android text underline color of filter input text field
cancelButtonText String "Cancel" Cancel button text
title String null Title text which appears above options list
noResultsText String "No matches" Text to show when there are no results for filter
visible Boolean true Whether to show modal or not. This allows you to control when the picker is shown and/or hidden.
showFilter Boolean true Whether to show filter text field field or not
modal Object null Options to pass to native Modal component
selectedOption String null The currently selected option, to visually differentiate it from others
flatListProps Object null Properties to pass to the rendered FlatList
renderOption function (option, isSelected) {} null Custom option renderer
renderList function () {} null Custom option list renderer
renderCancelButton function () {} null Custom cancel button renderer
keyboardShouldPersistTaps never/always/handle never Determines when the keyboard should stay visible after a tap. If never, tapping outside of the focused text input when the keyboard is up dismisses the keyboard. When this happens, children won't receive the tap. If always, the keyboard will not dismiss automatically, and the scroll view will not catch taps, but children of the scroll view can catch taps. If handled, the keyboard will not dismiss automatically when the tap was handled by a children, (or captured by an ancestor).
autoFocus Boolean false If true, focuses the input on componentDidMount().

In addition, the following styling props (each of which must be an Object consisting of styles) can be passed in:

Prop name Description
overlayStyle Style for the background modal overlay
listContainerStyle Style for the View wrapping the options list
filterTextInputContainerStyle Style for the View wrapping the filter input text field
filterTextInputStyle Style for the filter input text field
cancelContainerStyle Style for the View wrapping the cancel button
cancelButtonStyle Style for the cancel button button face
cancelButtonTextStyle Style for the cancel button text
titleTextStyle Style for the title text
optionTextStyle Style for the option text

Advanced filtering

By default the filter input field allows you to filter by the option label that's displayed on the screen.

But you can also attach a searchKey attribute to each option for the filtering algorithm to use. For example, we can allow the user to filter by continent as well as country name, even though we don't display the continent name:

render() {
  const { visible } = this.state;

  const options = [
    {
      key: 'kenya',
      label: 'Kenya',
      searchKey: 'Africa',
    },
    {
      key: 'uganda',
      label: 'Uganda',
      searchKey: 'Africa',
    },
    {
      key: 'libya',
      label: 'Libya',
      searchKey: 'Africa',
    },
    {
      key: 'japan',
      label: 'Japan',
      searchKey: 'Asia',
    },
    {
      key: 'estonia',
      label: 'Estonia',
      searchKey: 'Europe',
    },
  ];

  return (
    <View style={styles.container}>
      <ModalFilterPicker
        onSelect={this.onSelect}
        onCancel={this.onCancel}
        options={options}
      />
    </View>
  );
}

If you run the above example, you will be able to type africa into the filter input field to see all the countries within Africa.

Note: Filtering is case-insensitive

License

MIT

More Repositories

1

squel

🏒 SQL query string builder for Javascript
CoffeeScript
1,566
star
2

fast-levenshtein

Efficient Javascript implementation of Levenshtein algorithm with locale-specific collator support.
JavaScript
580
star
3

google-tts

Javascript API for the Google Text-to-Speech engine
JavaScript
312
star
4

robe

MongoDB ODM for Node.js using ES6 generators. Supports schema validation, raw querying, oplog tailing, etc.
JavaScript
178
star
5

linear-algebra

Efficient, high-performance linear algebra for node.js and browsers
JavaScript
162
star
6

melkor

Wiki powered by Node.js and Git
JavaScript
149
star
7

ansijet

Ansible playbook automation server
CSS
110
star
8

gulp-server-livereload

Gulp plugin to run a local webserver with livereload enabled via socket.io. Also comes with standalone command-line interface.
JavaScript
92
star
9

cordova-plugin-filepath

Resolve native file paths from content URLs for Cordova platforms
Java
66
star
10

geth-private

Quickly setup a local, private Ethereum blockchain.
JavaScript
60
star
11

ethereum-abi-ui

Auto-generate UI form field definitions and associated validators from an Ethereum contract ABI
JavaScript
58
star
12

ethereum-event-logs

Ethereum event logs parser
JavaScript
48
star
13

browsermail

Javascript IMAP email client for browsers
JavaScript
47
star
14

mailmask

Mailmask - easy stop unwanted email. Unlimited, free temporary email addresses, all forwarding to your real email address. Beat spam, protect your privacy.
JavaScript
39
star
15

lzw-async

Asynchronous Javascript implementation of LZW compression algorithm
HTML
38
star
16

wp-flickr-embed

Insert Flickr images into your Wordpress posts using an interactive interface
PHP
19
star
17

gulp-bench

Gulp plugin for running performance benchmarks
JavaScript
17
star
18

react-image-holder

React image component with offline placeholder fallbacks
JavaScript
17
star
19

koa-session-mongo

MongoDB storage layer for Koa session middleware
JavaScript
16
star
20

ethval

Easier calculation and formatting of Ethereum values
JavaScript
16
star
21

weber

Compile scripts, stylesheets and templates on-the-fly for rapid iterations
CoffeeScript
14
star
22

ethereum-contracts

Robust Ethereum contracts wrapper for easier deployment, method invocation and automatic type conversion.
JavaScript
14
star
23

clockmaker

Flexible Javascript timers which can be paused and modified on-the-fly
JavaScript
13
star
24

react-native-advanced-forms

Flexible React Native architecture for building and managing forms
JavaScript
13
star
25

koa-session-store

Session middleware for Koa with a pluggable storage layer
JavaScript
12
star
26

simple-mongo-schema

DEPRECATED. An easy-to-write schema validator for Mongo JSON objects
JavaScript
12
star
27

sjv

🚦 An easy-to-write schema and deep validator for JSON documents
JavaScript
11
star
28

ethereum-blocks

Process blocks from Ethereum client nodes robustly. Catch-up on restart, auto-reconnect to node, etc.
JavaScript
11
star
29

git-pull-cron

Git clone a repo into a folder and then schedule a cronjob to git pull updates
JavaScript
10
star
30

machine-learning

High-performance machine learning library for node.js and browsers
JavaScript
8
star
31

jquery.ajaxprogress

jQuery AJAX Progress plugin
JavaScript
8
star
32

drush_simpletest_command

An improved Drush SimpleTest command which allows you to run a single Drupal test from the command-line
7
star
33

elrond-voting-contract

Commit-reveal voting contract written in Rust for Elrond VM
Rust
6
star
34

page-tagger

A Wordpress plugin which lets you tag your pages just like you do with your posts
PHP
6
star
35

immutable-state-machine

Immutable state machine for Javascript with ability to associate extra data with each state. Useful for React.
JavaScript
6
star
36

askthensa

http://askthensa.com
5
star
37

ethereum-token-sales

Various Ethereum token sale contracts
5
star
38

mongo-replica-set

Command-line tool and API for setting up MongoDB replica sets on localhost
JavaScript
5
star
39

cron-async

Execute something on a schedule, using cron syntax, with async/await support.
TypeScript
4
star
40

patterns2

An improved version of the Drupal Patterns module.
PHP
4
star
41

es6-slides

Slides on the new features in Javascript ES6
JavaScript
4
star
42

react-native-extended-stylesheet-breakpoints

Smart responsive @media query generation for react-native-extended-stylesheets using configurable breakpoints
JavaScript
4
star
43

opengraph_meta

Drupal module which adds Open Graph meta tags to node pages for better social network sharing (e.g. http://developers.facebook.com/docs/share)
PHP
3
star
44

mocha-ci-slack-reporter

Slack reporter for Mocha when running in CI environments
JavaScript
2
star
45

ois-incidents-map

Officer-involved Shootings map of the USA
JavaScript
2
star
46

react-hooks

A collection of useful React hooks for async programming, web3, etc
TypeScript
2
star
47

node-generator-perf-tests

Some performance tests for when using generators in node.js
JavaScript
2
star
48

zhongwen

The source code to the zhongwen.co.uk website
JavaScript
2
star
49

ethanol

Desktop Solidity IDE **Work in progress**
JavaScript
2
star
50

react-native-xcode-packager

Custom XCode packager script for react-native which ensure bundle always gets built
Shell
2
star
51

logarama

Logging for the browser, logging levels, hierarchical child loggers, smart formatting, etc
JavaScript
2
star
52

documentation-lite

Extract JSDoc documentation from ES5/ES6 files into a JSON output structure.
JavaScript
2
star
53

us_latlng_json

JSON dataset of latitude and longitude co-ordinates for USA state counties and cities
2
star
54

abide

Base class with pub-sub and observers for JS object properties using ECMA5 getters/setters
JavaScript
2
star
55

genomatic

Utility methods for working with Generator functions, such as bind(), is(), etc
JavaScript
1
star
56

ethgoal

Goal achievement powered by Ethereum
JavaScript
1
star
57

phonegap-demo-app

CSS
1
star
58

indium

Reactive web framework for Node.js utilising RethinkDB and ReactJS
1
star
59

updates_notifier

Redmine plugin which update notifications to a callback URL when changes are made within Redmine
Ruby
1
star
60

saffronvideo

A Drupal module to make it easy to use Saffron media server assets.
PHP
1
star
61

smart-solidity-docs

Getting to grips with the Solidity programming language for the Ethereum blockchain
1
star
62

docjam

Javascript ES6 documentation extractor using markdown and jsdoc
JavaScript
1
star
63

method-mocks

Works with existing mocking and testing frameworks (e.g. Jest) to make method mocking easier.
JavaScript
1
star
64

hiddentao.com

HiddenTao website
JavaScript
1
star
65

nodejs-intro

Introduction to Node.js - building a chatroom using ExpressJS and Socket.IO
JavaScript
1
star
66

i21n

Tiny internationalization library for Node and the Browser
JavaScript
1
star
67

bulksms

BulkSMS API for TextAnywhere service
PHP
1
star
68

calc

Simple HTML5 calculator
HTML
1
star
69

uc_bulk_stock_updater

This is a Ubercart (Drupal) extension module which enables you to easily product stock levels on one page.
JavaScript
1
star
70

latlong-route-cleaner

Simple PHP script for cleaning out bad lat-long points form a driving route
PHP
1
star