add keyboard listener for IOS

This commit is contained in:
Jan de la Peña
2017-10-02 19:46:42 +08:00
committed by GitHub
parent b1e44190ce
commit f1c990d813

View File

@@ -3,6 +3,7 @@ import React from 'react';
import {
StyleSheet,
View,
Keyboard,
ViewPropTypes,
Dimensions
} from 'react-native';
@@ -12,6 +13,38 @@ import Send from './Send';
import Actions from './Actions';
export default class InputToolbar extends React.Component {
constructor(props) {
super(props);
this.state = {
position: 'absolute'
};
}
componentWillMount () {
this.keyboardWillShowListener =
Keyboard.addListener('keyboardWillShow', this._keyboardWillShow);
this.keyboardWillHideListener =
Keyboard.addListener('keyboardWillHide', this._keyboardWillHide);
}
componentWillUnmount () {
this.keyboardWillShowListener.remove();
this.keyboardWillHideListener.remove();
}
_keyboardWillShow = () => {
this.setState({
position: 'relative'
});
}
_keyboardWillHide = () => {
this.setState({
position: 'absolute'
});
}
renderActions() {
if (this.props.renderActions) {
return this.props.renderActions(this.props);
@@ -53,7 +86,8 @@ export default class InputToolbar extends React.Component {
render() {
return (
<View style={[styles.container, this.props.containerStyle]}>
<View
style={[styles.container, this.props.containerStyle, { position: this.state.position }]}>
<View style={[styles.primary, this.props.primaryStyle]}>
{this.renderActions()}
{this.renderComposer()}
@@ -70,7 +104,6 @@ const styles = StyleSheet.create({
borderTopWidth: StyleSheet.hairlineWidth,
borderTopColor: '#b2b2b2',
backgroundColor: '#FFFFFF',
position: 'absolute',
bottom: 0,
width: Dimensions.get('window').width
},