Skip to content

Instantly share code, notes, and snippets.

@tigerraj32
Created June 13, 2016 07:07
Show Gist options
  • Save tigerraj32/799c3158cbfef9e67eb391df86b68249 to your computer and use it in GitHub Desktop.
Save tigerraj32/799c3158cbfef9e67eb391df86b68249 to your computer and use it in GitHub Desktop.
'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