1.3.1 • Published 3 years ago

react-native-keyboard-tools v1.3.1

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

react-native-keyboard-tools

Typesafe way to work with keyboard

platforms npm npm

github issues github closed issues


Table of contents


Showcase

npm.io

Expo Playground


Usage

$ npm install --save react-native-keyboard-tools

or

$ yarn add react-native-keyboard-tools

KeyboardAwareScrollView

import { View, TextInput } from 'react-native'
import { KeyboardAwareScrollView } from 'react-native-keyboard-tools'

export const MyComponent = () => {
  return (
    <KeyboardAwareScrollView>
      <View>
        <TextInput />
      </View>
      <View>
        <TextInput />
      </View>
      <View>
        <TextInput />
      </View>
    </KeyboardAwareScrollView>
  )
}

useMaskedTextInput

import { useState } from 'react'
import { View, TextInput } from 'react-native'
import { useMaskedTextInput } from 'react-native-keyboard-tools'

export const MyComponent = () => {
  const [value, setValue] = useState("");
  const { onChangeMaskedText } = useMaskedTextInput({ mask: "+3(99) 9999 9999", onChangeText: setValue });

  return <TextInput onChangeText={onChangeMaskedText} />
}

KeyboardAwareScrollView and useMaskedTextInput

import { View, TextInput } from 'react-native'
import { KeyboardAwareScrollView, useMaskedTextInput } from 'react-native-keyboard-tools'

export const MyComponent = () => {
  const [value, setValue] = useState("");
  const { onChangeMaskedText } = useMaskedTextInput({ mask: "+3(99) 9999 9999", onChangeText: setValue });

  return (
    <KeyboardAwareScrollView>
      <View>
        <TextInput />
      </View>
      <View>
        <TextInput />
      </View>
      <View>
        <TextInput onChangeText={onChangeMaskedText} />
      </View>
    </KeyboardAwareScrollView>
  )
}

KeyboardAwareScrollView props and methods

Props

PropDescriptionTypeDefault
childrenAny react nodeReactNodeRequired
automaticallyAdjustContentInsetsControls whether OS should automatically adjust the content inset for scroll views that are placed behind a navigation bar or tab bar/toolbar.Booleanfalse
restoreScrollOnKeyboardHideControls whether library should restore scroll position to the initial value after keyboard become hiddenBooleanfalse

Any react-native ScrollView props are also accepted(ScrollViewProps)

Methods

import { View, TextInput } from 'react-native'
import { KeyboardAwareScrollView, KeyboardAwareScrollViewRef } from 'react-native-keyboard-tools'

export const MyComponent = () => {
  const scrollViewRef = useRef<KeyboardAwareScrollViewRef>();

  return (
    <KeyboardAwareScrollView ref={scrollViewRef}>
      <View>
        <TextInput />
      </View>
      <View>
        <TextInput />
      </View>
      <View>
        <TextInput onChangeText={onChangeMaskedText} />
      </View>
    </KeyboardAwareScrollView>
  )
}

scrollViewRef.scrollTo: ({ x, y, animated }: { x?: number; y?: number; animated?: boolean }) => void


useMaskedTextInput params

const { onChangeMaskedText } = useMaskedTextInput({ mask, onChangeText });

mask: defined by pattern

  • 9 - accept digit.
  • A - accept alpha.
  • S - accept alphanumeric.
  • * - accept all, EXCEPT white space.

Example: AAA-9999

onChangeText: (value: string) => void

onChangeMaskedText: (value: string, rawValue: string) => void


Credits

Inspired by https://github.com/wix/react-native-keyboard-aware-scrollview and https://github.com/benhurott/react-native-masked-text

License

MIT.

Author

Andrii Tiertyshnyi

1.3.1

3 years ago

1.3.0

3 years ago

1.2.2

3 years ago

1.2.0

3 years ago

1.2.1

3 years ago

1.1.0

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago