0.1.10 • Published 2 years ago

react-native-keyboard-avoiding-input v0.1.10

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

react native keyboard avoiding input 📲

This library allows you to pass the textinput just above the keyboard, thus floating on it, in cases that this is necessary

All the props are passed down to a new TextInput Component.

iOS ExampleAndroid Example
iOS ExampleAndroid Example

Installation

npm install react-native-keyboard-avoiding-input

Usage

import { TextInput } from 'react-native';
import { KeyboardAvoidingInput } from 'react-native-keyboard-avoiding-input';

// ...

 <KeyboardAvoidingInput
    input={TextInput}

    // Rest props a text input
    placeholder="Text me!"
    style={Style.input}
    value={state}
    onChangeText={setState}
      />

Usage with style-components 💅🏾

import { KeyboardAvoidingInput } from 'react-native-keyboard-avoiding-input';
import styled from 'styled-components/native';


// Custon TextInput with styled-components
const InputAwesome = styled.TextInput`
  width: 100%;
  height: 60px;
  font-size: 18px;
  flex: 1;
  color: #010101;
  margin-left: 10px;
`;

// ...

 <KeyboardAvoidingInput
    input={InputAwesome}

    // Rest props a TextInput
    placeholder="Text me!"
      />

Usage with react-hook-form 📋

import { KeyboardAvoidingInput } from 'react-native-keyboard-avoiding-input';
import styled from 'styled-components/native';
import { Controller, useForm } from 'react-hook-form';


// Custon TextInput with styled-components
const InputAwesome = styled.TextInput`
  width: 100%;
  height: 60px;
  font-size: 18px;
  flex: 1;
  color: #010101;
  margin-left: 10px;
`;

// ...
const {control} = useForm();

<Controller
    name="name"
    control={control}
    render={({ field: { onChange, onBlur, value } }) => (
      <KeyboardAvoidingInput
        input={InputAwesome}

        placeholder="It's me! Carlio"
        onBlur={onBlur}
        onChangeText={onChange}
        value={value}
          />
        )}
      />

How to select the next TextInput

The library exposes some methods through the ref focus, blur and clear

iOS ExampleAndroid Example
iOS ExampleAndroid Example
import { TextInput } from 'react-native';
import { KeyboardAvoidingInput, KeyboardAvoidingInputHandle } from 'react-native-keyboard-avoiding-input';

// ...

const inputRef = React.useRef<KeyboardAvoidingInputHandle>(null)

 <KeyboardAvoidingInput
    input={TextInput}
    // Rest props a text input
    onSubmitEditing={()=> inputRef.current?.focus()}
    placeholder="Text me!"
    />

 <KeyboardAvoidingInput
    input={TextInput}
    ref={inputRef}
    // Rest props a text input
    placeholder="Other input"
    />

Props

NameDescriptionDetails
inputReact component type TextInputrequired TextInput Component
returnKeyTypeClearChanges returnKey behavior to clean the TextInputboolean
returnKeyLabelBy default the returnKeyType is usedstring
returnKeyIconRenders an icon in place of returnKeyLabel or returnKeyType textReact component
toggleVisibilityPasswordRenders toggle for show and hide pass, required secureTextEntryboolean
toggleShowTextChange the text of Show when toggleVisibilityPassword is truestring
toggleHideTextChange the text of Hide when toggleVisibilityPassword is truestring
showPasswordIconRenders an icon in place of ShowReact component
hidePasswordIconRenders an icon in place of HideReact component
actionLabelStyleresponsible for the style of the texts of Done, Clear, Hide or ShowStyleProp<TextStyle>
actionContainerStyleresponsible for the container of the action textStyleProp<ViewStyle>
containerStyleResponsible for the KeyboardAvoidingInput container styleStyleProp<ViewStyle>
inputStyleResponsible for the KeyboardAvoidingInput styleStyleProp<TextInputStyle>
onOpenfunction called the input is openedfunction
onClosefunction called the input is closedfunction

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

Give me a Star

If you think this project is helpful just give me a ⭐️ :D

License

react-native-keyboard-avoiding-input is MIT licensed and built with ❤️ in 🇧🇷 by Godrix