1.0.0 • Published 6 years ago

rn-searchbox v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

rn-searchbox

A simple Search Bar with Flatlist Component for handling huge and large data.

With simple search capability which can be utilised by handing the component data to Flatlist Component and providing a onClick function which will receive the item selected of the data array.

The search function uses a Dice Algorithm to traverse the data and looks for an indexOf the user input within all strings, numbers, and boolean values in the data.

Build for React Native App and works on both Android and iOS.

Install

npm install --save rn-searchbox

or

yarn add rn-searchbox

Component props

PropertyTypeDefaultDescription
onClick(item)functionnullFires after each Click and return item data.
itemsStylesarray[]The array of styles of data to be displayed in FlatList.
dataarray[] required*The array of data to be searched
placeholderstringSearchThe placeholder for the search bar.
onFocusfunctionnullFires when the search bar receives focus.
onBlurfunctionnullFires when the search bar loses focus.
closeButtonComponentMaterialIconSets the close button component.
closeButtonAccessibilityLabelstringClear search textAccessibility label for the close button.
heightAdjustnumber0Adjust the height of the search bar.
backgroundColorstringwhiteThe background colour of the search bar.
iconColorstringgrayThe color of the back and X icons.
textColorstringgrayThe color of the search bar text.
selectionColorstringlightskyblueThe color of the the search bar cursor and text selection.
placeholderTextColorstringlightgrayThe color of the placeholder text.
showOnLoadbooleanfalseShow the search bar when it is first rendered.
clearOnShowbooleanfalseClear input when the search bar is shown.
clearOnHidebooleantrueClear input when the search bar is hidden.
clearOnBlurbooleanfalseClear input when the search bar is blurred.
focusOnLayoutbooleantrueFocus the text input box whenever it is shown.
autoCorrectbooleantrueAutoCorrect the search bar text.
autoCapitalizestringsentencesAuto capitialize behaviour of the text input - enum('none', 'sentences', 'words', 'characters')
keyboardAppearancestring'default'Determines the color of the keyboard.
fontFamilystringSystemThe font family to be used.
fontSizenumber20Sets the font size.

Usage

import React, { Component } from 'react' 
import { StyleSheet, Alert } from 'react-native' 
import SearchBox from 'rn-searchbox' 

export default class Example extends Component {
    
    onClick(item) {
        Alert.alert('Item: '+JSON.stringify(item)) 
    }
    render() {
        return (
            <SearchBox
                data={data.users}
                showOnLoad
                onClick={(item) => this.onClick(item)}
                itemsStyles={itemsStyle()}
            />
        ) 
    }
}

const itemsStyle = () => {
    return {
        name: {
            fontSize: 18
        },
        email: {
            color: 'red'
        },
        phone: {
            fontSize: 16,
            color: 'blue'
        }
    }
}

const data = {
    "users":
        [
            {
                "key": "0",
                "name": "Proxima Midnight",
                "phone": "+216 54 548 216"
            },
            {
                "key": "1",
                "name": "Ebony Maw",
                "email": "ebony@appdividend.com",
            },
            {
                "key": "2",
                "name": "Black Dwarf",
            },
            {
                "key": "3",
                "name": "Mad Titan",
                "email": "thanos@appdividend.com",
                "phone": "+216 54 548 100",
                "adress": "Sousse, Tunis"
            },
            {...}
        ]
}

Next Step:

  • Possibility to add a custom icon/image to the ListView
  • New Algorithm for String Matching
  • Update docs for Box component
  • Update react, react-native & other dependencies

Questions?

Feel free to contact me or create an issue.

Author

kerim selmi karimation

License

This project is licensed under the MIT License