
Research
/Security News
Contagious Interview Campaign Escalates With 67 Malicious npm Packages and New Malware Loader
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.
react-native-keyboard-aware-view
Advanced tools
A simple React Native View component that resizes composite children views inside itself when the keyboard appears. You can implement your own ScrollView, ListView, Multiple Views etc... inside the View and set your own view to 'flex: 1'.
A simple React Native View component that resizes composite children views inside itself when the keyboard appears. You can implement your own ScrollView, ListView, Multiple Views etc... inside the View and set your own view to 'flex: 1'.
For the screen below demonstration, the <TextInput>
automatically jumping according to <ScrollView>
scroll is NOT related to this library. It is related to my own implementation of <CTextInput>
, which is another story & beyond the scope of this plugin.
The problem this plugin aims to solve is to offer easy approach to adjust the view height when keyboard shows / hides. So that you could see the view at the bottom of the screen always sticking above the keyboard. You want to implement a sticky Whatsapp-like message text input box? Set your Chat scrollview to flex: 1, and set your message box view below the scrollview, and then wrap them both inside <KeyboardAwareView>
. Here you go. You have implemented a sticky message box view in iOS with no effort at all!
<View>
with "flex: 1" bootstrapped.Tested: it only affects iOS since Android version of React Native lacks support of this callback, by v0.17:
DeviceEventEmitter.addListener('keyboardWillShow', this.onKeyboardWillShow.bind(this))
DeviceEventEmitter.addListener('keyboardWillHide', this.onKeyboardWillHide.bind(this))
I believe this callback feature will not be landed in the future Android version of React Native. But anyway, Android version has its very own native handling for the keyboards without coding, so this lack is somehow acceptable.
You can install this component through npm
:
npm i react-native-keyboard-aware-view --save
Import react-native-keyboard-aware-view
and wrap your content inside
it:
import { KeyboardAwareView } from 'react-native-keyboard-aware-view'
<KeyboardAwareView animated={true}>
...
</KeyboardAwareView>
<KeyboardAwareView animated={false}>
...
</KeyboardAwareView>
~~After adopting this plugin, when your Android app needs to undergo indeterminate layout changes THAT would affect the layout of <KeyboardAwareView>
, the keyboard would be dismissed. If you do not want the keyboard to be dismissed by this behaviour you just have to set this parameter to true:
<KeyboardAwareView doNotForceDismissKeyboardWhenLayoutChanges={true}>
...
</KeyboardAwareView>
However, iOS still keeps this parameter to control the keyboard:
<KeyboardAwareView doNotForceDismissKeyboardWhenLayoutChanges={true}>
...
</KeyboardAwareView>
render() {
return (
<View style={{flex: 1}}>
<KeyboardAwareView animated={true}>
<View style={[styles.bg]}>
<ScrollView
ref={(view) => {this.scrollView = view; }}
style={[{flex: 1, alignSelf: 'stretch'}, this.props.style]}
keyboardShouldPersistTaps={true}
automaticallyAdjustContentInsets={false}
onScroll={this.onScroll.bind(this)}
scrollEventThrottle={200}
onLayout={(e) => {var {x, y, width, height} = e.nativeEvent.layout; console.log(height); }}>
<View style={{height: 34}} />
<CTextInput scrollView={this.getScrollView()} placeholder="登記名稱"/>
<CTextInput scrollView={this.getScrollView()} placeholder="電郵"/>
<CTextInput scrollView={this.getScrollView()} placeholder="電話"/>
<CTextInput scrollView={this.getScrollView()} placeholder="登記名稱"/>
<CTextInput scrollView={this.getScrollView()} placeholder="電郵"/>
<CTextInput scrollView={this.getScrollView()} placeholder="電話"/>
<CTextInput scrollView={this.getScrollView()} placeholder="登記名稱"/>
<CTextInput scrollView={this.getScrollView()} placeholder="電郵"/>
<CTextInput scrollView={this.getScrollView()} placeholder="電話"/>
<CTextInput scrollView={this.getScrollView()} placeholder="登記名稱"/>
<CTextInput scrollView={this.getScrollView()} placeholder="電郵"/>
<CTextInput scrollView={this.getScrollView()} placeholder="電話"/>
<CTextInput scrollView={this.getScrollView()} placeholder="登記名稱"/>
<CTextInput scrollView={this.getScrollView()} placeholder="電郵"/>
<CTextInput scrollView={this.getScrollView()} placeholder="電話"/>
<View style={{height: 46}} />
<Text>或以Facebook登記</Text>
<Image source={GLOBAL.IMAGE.icon_facebook} style={{width: 50, height: 50}} />
</ScrollView>
</View>
<TouchableOpacity style={{height: 50, backgroundColor: 'transparent', alignItems: 'center', justifyContent: 'center', alignSelf: 'stretch'}}>
<Text style={{fontSize: 20, color: '#FFFFFF'}}>提交</Text>
<CTextInput scrollView={this.getScrollView()} placeholder="電話"/>
</TouchableOpacity>
</KeyboardAwareView>
</View>
);
}
render() {
return (
<View style={{flex: 1}}>
<KeyboardAwareView animated={true}>
<View style={{flex: 1}}>
<ScrollView style={{flex: 1}}>
<Text style={{fontSize: 20, color: '#FFFFFF'}}>A</Text>
<Text style={{fontSize: 20, color: '#FFFFFF'}}>B</Text>
<Text style={{fontSize: 20, color: '#FFFFFF'}}>C</Text>
<Text style={{fontSize: 20, color: '#FFFFFF'}}>D</Text>
</ScrollView>
</View>
<TouchableOpacity style={{height: 50, backgroundColor: 'transparent', alignItems: 'center', justifyContent: 'center', alignSelf: 'stretch'}}>
<Text style={{fontSize: 20, color: '#FFFFFF'}}>Submit</Text>
</TouchableOpacity>
</KeyboardAwareView>
</View>
);
}
MIT.
FAQs
A simple React Native View component that resizes composite children views inside itself when the keyboard appears. You can implement your own ScrollView, ListView, Multiple Views etc... inside the View and set your own view to 'flex: 1'.
The npm package react-native-keyboard-aware-view receives a total of 672 weekly downloads. As such, react-native-keyboard-aware-view popularity was classified as not popular.
We found that react-native-keyboard-aware-view demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.