Giter VIP home page Giter VIP logo

react-native-search-bar's Introduction

React Native Search Bar

The high-quality native search bar for react native.

npm version npm downloads code style: prettier


Getting Started

This is a native library. It does not work with expo or create-react-native-app.

Installation

# npm
npm install react-native-search-bar --save

# yarn
yarn add react-native-search-bar

Pods

If using CocoaPods or React Native version >= 0.60.0

cd ios && pod install && cd ..

Linking

For React Native <= 0.59 only

react-native link react-native-search-bar

If linking fails, follow the manual linking steps

Usage

import SearchBar from 'react-native-search-bar';
<SearchBar
  ref="searchBar"
  placeholder="Search"
  onChangeText={...}
  onSearchButtonPress={...}
  onCancelButtonPress={...}
/>

Managing the keyboard

  • Show - this.refs.searchBar.focus();
  • Hide
    • this.refs.searchBar.blur(); - uses the iOS endEditing:true method on the underlying UISearchBar view.
    • this.refs.searchBar.unFocus(); - calls resignFirstResponder on the UITextField used by the UISearchBar.

Examples

  • Show the keyboard when the view loads:
componentDidMount() {
  this.refs.searchBar.focus();
}
  • Hide the keyboard when the user searches:
...
onSearchButtonPress={this.refs.searchBar.unFocus}
...

For a full list of props check out the typescript definitions file.

There is also an example project in the example directory.

Contribution

For now, only some of the features of UISearchBar are implemented.

Feel free to send a pull request to the next branch. To get started, you can read the "Native UI Components (iOS)" guide on the React Native website.

Along with code contribution, you are welcomed to answer questions asked in the Issues.

License

MIT

react-native-search-bar's People

Contributors

alpha0010 avatar cancan101 avatar chengs avatar chirag04 avatar considerate avatar dependabot[bot] avatar dozoisch avatar freddy03h avatar haibinyu avatar hilzu avatar ionutlepi avatar iroachie avatar jesster2k10 avatar juankiz avatar michaelhelvey avatar migue1s avatar mokto avatar oxydesign avatar oxyii avatar rmdort avatar robertbiehl avatar samsel avatar skv-headless avatar spencercarli avatar tamarous avatar umhan35 avatar venepe avatar zedman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-search-bar's Issues

Can't remove top border

I'm trying to imitate the behavior where you click the Search Bar and it moves to the top of the screen, which is working for me so far, but how do you remove the top border?
ios_simulator_-iphone_5s-iphone_5s___ios_8_4__12h141

Cancel button appears on open

The cancel button appears on app launch, but the text is not tinted. Tapping the bar after tints the text. Anyone know what may be causing this?

Delay on Keyboard Hide

Do you guys see a little delay while dismissing the keyboard?
I don't see this while dismissing with keyboardDismissMode='on-drag'

<ScrollView style={styles.container}  automaticallyAdjustContentInsets={false} keyboardDismissMode='on-drag' keyboardShouldPersistTaps={false}>
            <SearchBar
                ref='searchBar'
                placeholder='Buscar'
                onSearchButtonPress={(event)=>{
                  this.refs.searchBar.unFocus()
                  this.refs.searchBar.blur()
                }}/>
            <View>
              <Text>Test</Text>
            </View>
          </ScrollView>

Also, when I search for something, tap on X, I cant unfocus from it, since my Search button is disabled.

Custom cancel button

Hello,

it would really be nice to be able to set a custom cancel button text via JS wrapper.

Regards
Philipp

Programmatically blur search bar

Similar to #24, it would be valuable to be able to .blur() the search bar to hide the keyboard, as you can with the React Native TextInput component.

Build Failing with RN 0.15

Receiving this error:

RNSearchBarManager.m:71:6: Incompatible block pointer types sending 'void (^)(RCTUIManager *__strong, NSDictionary *__strong)' to parameter of type 'RCTViewManagerUIBlock' (aka 'void (^)(RCTUIManager *__strong, RCTSparseArray *__strong)')

Maybe I should be using this PR?
#43

React.requireNativeComponent undefined

It seems that React.requireNativeComponent is undefined. Do I need to include other libraries as well? Could you please go into detail which files need to be linked?

KeyboardDismissMode

Hi, may I know what can I do to dismiss the keyboard other than click on the "cancel" button? I tried to use TouchableWithoutFeedback, but it failed to work as expected.

How can I style the search bar ?

Can you provide me with an example of styling the search bar because when try to use style={{ backroundColor: '#FAFAFA' }} then, search bar disappears.

Cannot read property "componentHeight" of undefined

Getting an error when including a basic example of the search bar in my project.

It's not finding "NativeModules.RNSearchBarManager.ComponentHeight".

Line 40: SearchBar.js

<SearchBar placeholder='Search' onChangeText={this.createEvent}/>

Issue with react-native-0.15.0

Hi, there,

As of 0.15.0, the signature of RCTEventDispatcher sendTextEventWithType has changed. See this commit.

As a workaround, I have modified RNSearchBar.m to pass a key of nil, as you aren't listening for the onKeyPress event, and this has got things working for me. But, if you want to implement this in the future, you might need to send back the text events being sent from UISearchBar.

showsCancelButton not working with false value

Hi,

I don't know if this is a bug or if this is normal.

showsCancelButton={false} has a wrong behavious. In my opinion :

  • no attribute : should show cancel only on focus => OK
  • showsCancelButton={true} : should show the cancel button even if not focus => OK
  • showsCancelButton={false} : should never show the cancel button => NOT OK.

What do you think ?

how to set caret color?

Right now it's white, I need to change it to a different color. Throughout my app it's blue...

Clear text button not working with large widths

I don't know why, but when I set the width larger than 100px, the clear button (the one with the 'x' icon) doesn't work. This is very frustrating.
The search bar is inside a navigator component.
Any ideas?

Warning when ScrollView with keyboardDissmode

I have a ScrollView below the Search bar as below

<ScrollView style={style.container}
          keyboardShouldPersistTaps={true}
          keyboardDismissMode='on-drag'
        />
</ScrollView>

When the search box is focussed and i drag the ScrollView, i am getting the following warning on Xcode. Cant seem to figure out how to fix it. I think it has something to do with searchBarTextDidEndEditing

2016-07-20 22:30:05.427 App[92773:15460947] -[UIWindow endDisablingInterfaceAutorotationAnimated:] called on <UITextEffectsWindow: 0x7fc42d007220; frame = (0 0; 375 667); opaque = NO; autoresize = W+H; layer = <UIWindowLayer: 0x7fc42adeeb60>> without matching -beginDisablingInterfaceAutorotation. Ignoring.

image

Searchbar not showing inside a Drawer

I've installed the search bar with no error using:
npm install react-native-search-bar@latest --save
rnpm link

And when I use the SearchBar inside a Drawer like this:

<Drawer ref="drawer" content={<MenuContent />}>
          <NavigationBar title={titleConfig} statusBar={statusBarConfig} />
          <View style={styles.container}>
             <SearchBar
                ref='searchBar'
                placeholder='Search'
                onChangeText={...}
                onSearchButtonPress={...}
                onCancelButtonPress={...}
               />
              <ListView .. />
          </View>
</Drawer>

There is only a space above the ListViewand no SearchBar, but when I move the SearchBar out of the Drawer it works.

Hide keyboard on search and cancel.

Hi,

i'm struggling with keyboard that is not hidden when search is tapped on keyboard and also when cancel button (X) is tapped withing search bar.

I've googled out how to hide keyboard on search, by adding
[searchBar resignFirstResponder]; into searchBarSearchButtonClicked method,

but adding same line to searchBarCancelButtonClicked doesn't hide the keyboard.

cancel button doesn't show on the second time

I set showsCancelButton={true} and it works correctly at the first time.
But after I click cancel and focus again, the cancel button doesn't show up. The value in UISearchBar is overwritten by [self setShowsCancelButton:NO animated:YES];

Let other people help you

Hi @umhan35,

I see there are a lot of on-going issues and pull requests on this great plugin.

Would you mind giving someone (I can do it if you want) write access to help you with it ?

Thanks !

Problem to position UISearchBar

Hello,

I have some troubles when I want to integrate this package to my project. For some reasons, I have to specify marginTop and height properties searchBar's style otherwise the bar doesn't show up.

screen shot 2015-10-09 at 11 24 55

The problem is the marginTop property move down my ListView component. I don't understand my I need to specify marginTop and height properties.

Here is my code:

import React, { View, Component, StyleSheet, ListView, PropTypes, Text } from 'react-native';

import SearchBar from 'react-native-search-bar';

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  searchBar: {
    marginTop: 64,
    height: 44,
    backgroundColor: 'green',
  },
  listView: {
    backgroundColor: 'red',
  },
});

export default class ContactsComponent extends Component {
  static propTypes = { dataSource: PropTypes.object.isRequired }
  static defaultProps = { dataSource: new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}) }
  state = { dataSource: this.props.dataSource.cloneWithRows(['User 1', 'User 2', 'User 3', 'User 4', 'User 5']) }

  render() {
    return (
      <View style={styles.container}>
        <SearchBar placeholder="Search"
          style={styles.searchBar}
          barTintColor="#87D3D3"
          textFieldBackgroundColor="#D5EFEF"
          tintColor="#D5EFEF" />
        <ListView style={styles.listView} dataSource={this.state.dataSource}
        renderRow={(rowData) => <Text>{rowData}</Text>} />
      </View>
    );
  }
}

Any suggestion?

Best,
Jean

Programmatically clear the input?

Is it possible to programmatically clear the search bar input field? Something similar to setNativeProps({text: ''}) for TextInput component?

Blur away keyboard

Hello,

I'm using the search bar to filter a listview on change of the search bar text. Is there currently any way implemented to hide the keyboard the moment I press something in the listview - like a blur() function?

Thanks
Philipp

Search Bar not appearing

The search bar component appears to be rendered in the DOM, but I can't see anything. Here's my code.

import React from 'react'
import {
  View,
  Text,
} from 'react-native'
import SearchBar from 'react-native-search-bar'
import styles from './Topbar.styles'

class Topbar extends React.Component {
  componentDidMount() {
    this.refs.searchBar.focus()
  }

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.text}>Topbar</Text>
        <SearchBar
          ref="searchBar"
          placeholder="Search..."
        />
      </View>
    )
  }
}
export default Topbar

I double checked that I linked the dependencies, tried deleting and re-adding the project. Any ideas?

Element type is invalid

I am trying to use the component search-bar https://github.com/umhan35/react-native-search-bar

I have followed the instructions and installed it correctly what I am confused about is how to use it as everything I am trying is throwing errors.

To test it I am using it on a program called testingReact which is just the starting react program.

I added the searchBar so the imports look like this.

'use strict'; import React, { AppRegistry, Component, StyleSheet, Text, View, SearchBar } from 'react-native';

Now if I run it still does not throw an error

Now I add the following code (taken straight from the example

<View> 
  <SearchBar
    placeholder='Search'
    textFieldBackgroundColor='blue'
    />
</View>

When I run I get the following error "Element type is invalid : expected string(for built in components) or a class/function (for composite components) but got: undefined. Check the render method of 'testingReact'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.