Created
June 13, 2016 07:07
-
-
Save tigerraj32/799c3158cbfef9e67eb391df86b68249 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
import { Dimensions } from 'react-native' | |
import React, {View, DeviceEventEmitter} from 'react-native' | |
class SomeScene extends React.Component { | |
constructor (props) { | |
super(props) | |
this.state = { | |
visibleHeight: Dimensions.get('window').height | |
} | |
} | |
componentWillMount () { | |
DeviceEventEmitter.addListener('keyboardWillShow', this.keyboardWillShow.bind(this)) | |
DeviceEventEmitter.addListener('keyboardWillHide', this.keyboardWillHide.bind(this)) | |
} | |
keyboardWillShow (e) { | |
let newSize = Dimensions.get('window').height - e.endCoordinates.height | |
this.setState({visibleHeight: newSize}) | |
} | |
keyboardWillHide (e) { | |
this.setState({visibleHeight: Dimensions.get('window').height}) | |
} | |
render () { | |
return ( | |
<View style={{height: this.state.visibleHeight}}> | |
... | |
</View> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment