Rocket.Chat.ReactNative/app/presentation/KeyboardView.js

45 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-08-09 13:12:00 +00:00
import React from 'react';
import PropTypes from 'prop-types';
import { ViewPropTypes } from 'react-native';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
import { connect } from 'react-redux';
import scrollPersistTaps from '../utils/scrollPersistTaps';
import { setKeyboardOpen, setKeyboardClosed } from '../actions/keyboard';
2017-08-09 13:12:00 +00:00
@connect(null, dispatch => ({
setKeyboardOpen: () => dispatch(setKeyboardOpen()),
setKeyboardClosed: () => dispatch(setKeyboardClosed())
}))
2017-08-09 13:12:00 +00:00
export default class KeyboardView extends React.PureComponent {
static propTypes = {
style: ViewPropTypes.style,
contentContainerStyle: ViewPropTypes.style,
2017-08-09 13:12:00 +00:00
keyboardVerticalOffset: PropTypes.number,
scrollEnabled: PropTypes.bool,
2017-08-09 16:19:17 +00:00
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node
]),
setKeyboardOpen: PropTypes.func,
setKeyboardClosed: PropTypes.func
2017-08-09 13:12:00 +00:00
}
render() {
return (
<KeyboardAwareScrollView
{...scrollPersistTaps}
style={this.props.style}
contentContainerStyle={this.props.contentContainerStyle}
scrollEnabled={this.props.scrollEnabled}
alwaysBounceVertical={false}
extraHeight={this.props.keyboardVerticalOffset}
behavior='position'
onKeyboardWillShow={() => this.props.setKeyboardOpen()}
onKeyboardWillHide={() => this.props.setKeyboardClosed()}
>
2017-08-09 13:12:00 +00:00
{this.props.children}
</KeyboardAwareScrollView>
2017-08-09 13:12:00 +00:00
);
}
}