Gathering detailed insights and metrics for @codler/react-native-keyboard-aware-scroll-view
Gathering detailed insights and metrics for @codler/react-native-keyboard-aware-scroll-view
Gathering detailed insights and metrics for @codler/react-native-keyboard-aware-scroll-view
Gathering detailed insights and metrics for @codler/react-native-keyboard-aware-scroll-view
react-native-keyboard-aware-scroll-view
A React Native ScrollView component that resizes when the keyboard appears.
@exodus/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
npm install @codler/react-native-keyboard-aware-scroll-view
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
38 Stars
177 Commits
16 Forks
3 Watching
3 Branches
1 Contributors
Updated on 11 Sept 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
28.8%
2,325
Compared to previous day
Last week
7%
11,663
Compared to previous week
Last month
-5.5%
48,893
Compared to previous month
Last year
-21.1%
654,036
Compared to previous year
1
1
A ScrollView component that handles keyboard appearance and automatically scrolls to focused TextInput
.
v2.0.0
requires RN>=0.65.1
v1.0.0
requires RN>=0.63.0
Installation can be done through npm
:
1npm i @codler/react-native-keyboard-aware-scroll-view --save
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 '@codler/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}
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
license file not detected
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
12 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 More