Skip to content

Commit dbec23d

Browse files
committed
add support for android
1 parent 24bc79f commit dbec23d

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

lib/KeyboardAwareFlatList.js

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
/* @flow */
2+
13
import React from 'react';
24
import createReactClass from 'create-react-class';
35
import PropTypes from 'prop-types';
4-
import { FlatList } from 'react-native';
6+
import { FlatList, Platform } from 'react-native';
57
import KeyboardAwareMixin from './KeyboardAwareMixin';
68

79
const KeyboardAwareFlatList = createReactClass({
@@ -11,27 +13,51 @@ const KeyboardAwareFlatList = createReactClass({
1113
x: PropTypes.number,
1214
y: PropTypes.number,
1315
}),
16+
onScroll: PropTypes.func,
17+
enableOnAndroid: PropTypes.bool,
1418
},
1519
mixins: [KeyboardAwareMixin],
1620

1721
componentWillMount: function () {
18-
this.setViewIsInsideTabBar(this.props.viewIsInsideTabBar)
19-
this.setResetScrollToCoords(this.props.resetScrollToCoords)
22+
this.setViewIsInsideTabBar(!!this.props.viewIsInsideTabBar)
23+
if (this.props.resetScrollToCoords) {
24+
this.setResetScrollToCoords(this.props.resetScrollToCoords)
25+
}
26+
},
27+
28+
onScroll: function (e: SyntheticEvent & {nativeEvent: {contentOffset: number}}) {
29+
this.handleOnScroll(e)
30+
this.props.onScroll && this.props.onScroll(e)
2031
},
2132

2233
render: function () {
34+
const {
35+
enableOnAndroid,
36+
contentContainerStyle,
37+
} = this.props
38+
39+
const {
40+
keyboardSpace,
41+
} = this.state
42+
43+
let newContentContainerStyle
44+
45+
if (Platform.OS === 'android' && enableOnAndroid) {
46+
newContentContainerStyle = Object.assign({}, contentContainerStyle)
47+
newContentContainerStyle.paddingBottom = (newContentContainerStyle.paddingBottom || 0) + keyboardSpace
48+
}
49+
2350
return (
2451
<FlatList
2552
ref='_rnkasv_keyboardView'
2653
keyboardDismissMode='interactive'
27-
contentInset={{bottom: this.state.keyboardSpace}}
54+
contentInset={{bottom: keyboardSpace}}
55+
automaticallyAdjustContentInsets={false}
2856
showsVerticalScrollIndicator={true}
2957
scrollEventThrottle={0}
3058
{...this.props}
31-
onScroll={e => {
32-
this.handleOnScroll(e)
33-
this.props.onScroll && this.props.onScroll(e)
34-
}}
59+
contentContainerStyle={newContentContainerStyle || contentContainerStyle}
60+
onScroll={this.onScroll}
3561
/>
3662
)
3763
},

0 commit comments

Comments
 (0)