Skip to content

Commit ecc3ec8

Browse files
author
alvaromb
committed
Solved small issue when rendering scroll view inside a TabBarIOS
1 parent 6f2b771 commit ecc3ec8

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

lib/KeyboardAwareListView.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ import KeyboardAwareMixin from './KeyboardAwareMixin'
44
const KeyboardAwareListView = React.createClass({
55
propTypes: {
66
...ListView.propTypes,
7+
viewIsInsideTabBar: React.PropTypes.bool,
78
},
89
mixins: [KeyboardAwareMixin],
910

11+
componentWillMount: function() {
12+
if (this.props.viewIsInsideTabBar) {
13+
this.setViewIsInsideTabBar(this.props.viewIsInsideTabBar)
14+
}
15+
},
16+
1017
render: function () {
1118
return (
1219
<ListView

lib/KeyboardAwareMixin.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
import React, { DeviceEventEmitter } from 'react-native'
1+
import { DeviceEventEmitter } from 'react-native'
22
import TimerMixin from 'react-timer-mixin'
33

4+
const _KAM_DEFAULT_TAB_BAR_HEIGHT = 49
5+
46
const KeyboardAwareMixin = {
5-
propTypes: {
6-
viewIsInsideTabBar: React.PropTypes.bool,
7-
},
87
mixins: [TimerMixin],
98

9+
setViewIsInsideTabBar: function (viewIsInsideTabBar) {
10+
this.viewIsInsideTabBar = viewIsInsideTabBar
11+
this.setState({keyboardSpace: _KAM_DEFAULT_TAB_BAR_HEIGHT})
12+
},
13+
1014
getInitialState: function (props) {
15+
this.viewIsInsideTabBar = false
1116
return {
1217
keyboardSpace: 0,
1318
}
1419
},
1520

1621
// Keyboard actions
17-
// TODO: automatically handle TabBar height instead of using props
1822
updateKeyboardSpace: function (frames) {
19-
const keyboardSpace = (this.props.viewIsInsideTabBar) ? frames.endCoordinates.height - 49 : frames.endCoordinates.height
23+
const keyboardSpace = (this.props.viewIsInsideTabBar) ? frames.endCoordinates.height - _KAM_DEFAULT_TAB_BAR_HEIGHT : frames.endCoordinates.height
2024
this.setState({
2125
keyboardSpace: keyboardSpace,
2226
})
@@ -43,7 +47,7 @@ const KeyboardAwareMixin = {
4347
/**
4448
* @param extraHeight: takes an extra height in consideration.
4549
*/
46-
scrollToFocusedInput: function (event, reactNode, extraHeight = 49) {
50+
scrollToFocusedInput: function (event, reactNode, extraHeight = _KAM_DEFAULT_TAB_BAR_HEIGHT) {
4751
const scrollView = this.refs.keyboardView.getScrollResponder()
4852
this.setTimeout(() => {
4953
scrollView.scrollResponderScrollNativeHandleToKeyboard(

lib/KeyboardAwareScrollView.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ import KeyboardAwareMixin from './KeyboardAwareMixin'
44
const KeyboardAwareScrollView = React.createClass({
55
propTypes: {
66
...ScrollView.propTypes,
7+
viewIsInsideTabBar: React.PropTypes.bool,
78
},
89
mixins: [KeyboardAwareMixin],
910

11+
componentWillMount: function() {
12+
if (this.props.viewIsInsideTabBar) {
13+
this.setViewIsInsideTabBar(this.props.viewIsInsideTabBar)
14+
}
15+
},
16+
1017
render: function () {
1118
return (
1219
<ScrollView

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-keyboard-aware-scroll-view",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"description": "A React Native ScrollView component that resizes when the keyboard appears.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)