mirror of
https://github.com/zhigang1992/react-native-gifted-chat.git
synced 2026-04-28 20:25:43 +08:00
add keyboard listener for IOS
This commit is contained in:
@@ -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
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user