Skip to content

Commit b141aeb

Browse files
committed
add keyboard aware support to FlatList
1 parent 79e5fda commit b141aeb

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

lib/KeyboardAwareFlatList.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
import createReactClass from 'create-react-class';
3+
import PropTypes from 'prop-types';
4+
import { FlatList } from 'react-native';
5+
import KeyboardAwareMixin from './KeyboardAwareMixin';
6+
7+
const KeyboardAwareFlatList = createReactClass({
8+
propTypes: {
9+
viewIsInsideTabBar: PropTypes.bool,
10+
resetScrollToCoords: PropTypes.shape({
11+
x: PropTypes.number,
12+
y: PropTypes.number,
13+
}),
14+
},
15+
mixins: [KeyboardAwareMixin],
16+
17+
componentWillMount: function () {
18+
this.setViewIsInsideTabBar(this.props.viewIsInsideTabBar)
19+
this.setResetScrollToCoords(this.props.resetScrollToCoords)
20+
},
21+
22+
render: function () {
23+
return (
24+
<FlatList
25+
ref='_rnkasv_keyboardView'
26+
keyboardDismissMode='interactive'
27+
contentInset={{bottom: this.state.keyboardSpace}}
28+
showsVerticalScrollIndicator={true}
29+
scrollEventThrottle={0}
30+
{...this.props}
31+
onScroll={e => {
32+
this.handleOnScroll(e)
33+
this.props.onScroll && this.props.onScroll(e)
34+
}}
35+
/>
36+
)
37+
},
38+
})
39+
40+
export default KeyboardAwareFlatList

0 commit comments

Comments
 (0)