0.2.0 • Published 3 years ago

@nghinv/react-native-search-bar v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@nghinv/react-native-search-bar

React Native SearchBar Component use reanimated 2 library


CircleCI Version MIT License All Contributors PRs Welcome

Installation

yarn add @nghinv/react-native-search-bar

or

npm install @nghinv/react-native-search-bar
  • peerDependencies
yarn add react-native-gesture-handler react-native-reanimated

Usage

import React, { useState, useCallback } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import SearchBar from '@nghinv/react-native-search-bar';

function App() {
  const [text, setText] = useState('');

  const onChangeText = useCallback((value) => {
    setText(value);
  }, []);

  return (
    <View style={styles.container}>
      <SearchBar
        placeholder='Search'
        containerStyle={styles.textInput}
        cancelTitle='Huỷ'
        value={text}
        onChangeText={onChangeText}
        // theme={theme.textInput}
      />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    paddingVertical: 24,
  },
  textInput: {
    marginTop: 40,
    paddingHorizontal: 16,
    paddingVertical: 8,
  },
});

export default App;

Property

PropertyTypeDefaultDescription
containerStyleViewStyleundefined
textInputStyleTextStyleundefined
widthnumber \| stringundefined
heightnumber44
borderRadiusnumber12
cancelButtonbooleantrueShow, hide cancel button
cancelTitlestringCancel
cancelTitleStyleTextStyleundefined
onFocus() => voidundefined
onBlur() => voidundefined
onSubmitEditing() => voidundefined
valuestringundefined
onChangeText(value: string) => voidundefined
isDarkThemebooleanfalse
themeInputThemeType
clearIconReact.ReactNodenull
searchIconReact.ReactNodenull
  • InputThemeType
PropertyTypeDefaultDescription
backgroundColorstring
placeholderColorstring
textInputBackgroundstring
textColorstring
selectionColorstring
clearIconColorstring
textButtonColorstringCancel title color
TextInputThemeDefault = {
  dark: {
    backgroundColor: 'transparent',
    placeholderColor: '#636366',
    textInputBackground: 'rgba(44,44,46,0.8)',
    textColor: 'white',
    selectionColor: '#2979ff',
    clearIconColor: '#c7c7cc',
    searchIconColor: '#b0b0b2',
    textButtonColor: '#2979ff',
  },
  light: {
    backgroundColor: 'transparent',
    placeholderColor: '#8e8e93',
    textInputBackground: 'rgba(142,142,147,0.12)',
    textColor: 'black',
    selectionColor: '#2979ff',
    clearIconColor: '#c7c7cc',
    searchIconColor: '#8e8e93',
    textButtonColor: '#2979ff',
  },
};

Credits