Gathering detailed insights and metrics for @exodus/react-native-keyboard-aware-scroll-view
Gathering detailed insights and metrics for @exodus/react-native-keyboard-aware-scroll-view
Gathering detailed insights and metrics for @exodus/react-native-keyboard-aware-scroll-view
Gathering detailed insights and metrics for @exodus/react-native-keyboard-aware-scroll-view
npm install @exodus/react-native-keyboard-aware-scroll-view
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
5,291 Stars
182 Commits
648 Forks
44 Watching
20 Branches
79 Contributors
Updated on 27 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-29.6%
131
Compared to previous day
Last week
-11%
1,174
Compared to previous week
Last month
-13.7%
5,061
Compared to previous month
Last year
-9.5%
39,331
Compared to previous year
2
1
A ScrollView component that handles keyboard appearance and automatically scrolls to focused TextInput
.
v0.4.0
requires RN>=0.48
v0.2.0
requires RN>=0.32.0
.v0.1.2
requires RN>=0.27.2
but you should use 0.2.0
in order to make it work with multiple scroll views.v0.0.7
requires react-native>=0.25.0
.v0.0.6
for older RN versions.Installation can be done through npm
or yarn
:
1npm i react-native-keyboard-aware-scroll-view --save
1yarn add react-native-keyboard-aware-scroll-view
You can use the KeyboardAwareScrollView
, KeyboardAwareSectionList
or the KeyboardAwareFlatList
components. They accept ScrollView
, SectionList
and FlatList
default props respectively and
implement a custom high order component called KeyboardAwareHOC
to handle keyboard appearance.
The high order component is also available if you want to use it in any other component.
Import react-native-keyboard-aware-scroll-view
and wrap your content inside
it:
1import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'
1<KeyboardAwareScrollView> 2 <View> 3 <TextInput /> 4 </View> 5</KeyboardAwareScrollView>
TextInput
fieldsAs of v0.1.0
, the component auto scrolls to the focused TextInput
😎. For versions v0.0.7
and older you can do the following.
TextInput
In order to scroll to any TextInput
field, you can use the built-in method scrollToFocusedInput
. Example:
1_scrollToInput (reactNode: any) { 2 // Add a 'scroll' ref to your ScrollView 3 this.scroll.props.scrollToFocusedInput(reactNode) 4}
1<KeyboardAwareScrollView 2 innerRef={ref => { 3 this.scroll = ref 4 }}> 5 <View> 6 <TextInput 7 onFocus={(event: Event) => { 8 // `bind` the function if you're using ES6 classes 9 this._scrollToInput(ReactNative.findNodeHandle(event.target)) 10 }} 11 /> 12 </View> 13</KeyboardAwareScrollView>
There's another built-in function that lets you programatically scroll to any position of the scroll view:
1this.scroll.props.scrollToPosition(0, 0)
You can register to ScrollViewResponder
events onKeyboardWillShow
and onKeyboardWillHide
:
1<KeyboardAwareScrollView 2 onKeyboardWillShow={(frames: Object) => { 3 console.log('Keyboard event', frames) 4 }}> 5 <View> 6 <TextInput /> 7 </View> 8</KeyboardAwareScrollView>
First, Android natively has this feature, you can easily enable it by setting windowSoftInputMode
in AndroidManifest.xml
. Check here.
But if you want to use feature like extraHeight
, you need to enable Android Support with the following steps:
0.46
or above.windowSoftInputMode
to adjustPan
in AndroidManifest.xml
.enableOnAndroid
property to true
.Android Support is not perfect, here is the supported list:
Prop | Android Support |
---|---|
viewIsInsideTabBar | Yes |
resetScrollToCoords | Yes |
enableAutomaticScroll | Yes |
extraHeight | Yes |
extraScrollHeight | Yes |
enableResetScrollToCoords | Yes |
keyboardOpeningTime | No |
All the ScrollView
/FlatList
props will be passed.
Prop | Type | Description |
---|---|---|
innerRef | Function | Catch the reference of the component. |
viewIsInsideTabBar | boolean | Adds an extra offset that represents the TabBarIOS height. |
resetScrollToCoords | Object: {x: number, y: number} | Coordinates that will be used to reset the scroll when the keyboard hides. |
enableAutomaticScroll | boolean | When focus in TextInput will scroll the position, default is enabled. |
extraHeight | number | Adds an extra offset when focusing the TextInput s. |
extraScrollHeight | number | Adds an extra offset to the keyboard. Useful if you want to stick elements above the keyboard. |
enableResetScrollToCoords | boolean | Lets the user enable or disable automatic resetScrollToCoords. |
keyboardOpeningTime | number | Sets the delay time before scrolling to new position, default is 250 |
enableOnAndroid | boolean | Enable Android Support |
Use innerRef
to get the component reference and use this.scrollRef.props
to access these methods.
Method | Parameter | Description |
---|---|---|
getScrollResponder | void | Get ScrollResponder |
scrollToPosition | x: number, y: number, animated: bool = true | Scroll to specific position with or without animation. |
scrollToEnd | animated?: bool = true | Scroll to end with or without animation. |
scrollIntoView | element: React.Element<*>, options: { getScrollPosition: ?(parentLayout, childLayout, contentOffset) => { x: number, y: number, animated: boolean } } | Scrolls an element inside a KeyboardAwareScrollView into view. |
Enabling any component to be keyboard-aware is very easy. Take a look at the code of KeyboardAwareFlatList
:
1/* @flow */ 2 3import { FlatList } from 'react-native' 4import listenToKeyboardEvents from './KeyboardAwareHOC' 5 6export default listenToKeyboardEvents(FlatList)
The HOC can also be configured. Sometimes it's more convenient to provide a static config than configuring the behavior with props. This HOC config can be overriden with props.
1/* @flow */ 2 3import { FlatList } from 'react-native' 4import listenToKeyboardEvents from './KeyboardAwareHOC' 5 6const config = { 7 enableOnAndroid: true, 8 enableAutomaticScroll: true 9} 10 11export default listenToKeyboardEvents(config)(FlatList)
The available config options are:
1{ 2 enableOnAndroid: boolean, 3 contentContainerStyle: ?Object, 4 enableAutomaticScroll: boolean, 5 extraHeight: number, 6 extraScrollHeight: number, 7 enableResetScrollToCoords: boolean, 8 keyboardOpeningTime: number, 9 viewIsInsideTabBar: boolean, 10 refPropName: string, 11 extractNativeRef: Function 12}
MIT.
Álvaro Medina Ballester <amedina at apsl.net>
Built with 💛 by APSL.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 12/25 approved changesets -- score normalized to 4
Reason
0 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
14 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn Morereact-native-keyboard-aware-scroll-view
A React Native ScrollView component that resizes when the keyboard appears.
@codler/react-native-keyboard-aware-scroll-view
A React Native ScrollView component that resizes when the keyboard appears.
react-native-input-scroll-view
Perfect TextInput ScrollView
react-native-keyboard-avoiding-scroll-view
React Native ScrollView extension that prevents inputs from being covered by the keyboard