Last active
November 22, 2015 23:53
-
-
Save rileybracken/92e6dbbdf869adc090e4 to your computer and use it in GitHub Desktop.
Animated Pull Down Header
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
/** | |
* | |
* My Attempt at the Twitter Mobile scroll and grow header interaction in | |
* React Native. The problem I am running into problems with the rendering | |
* at the top. I have tried animating translateY, top and margin top. All | |
* do the exact same thing. The only thing I can think to do to get around | |
* this is position the element at a negative margin to compensate for the | |
* jumping around. | |
* | |
**/ | |
'use strict'; | |
import React, { | |
AppRegistry, | |
ScrollView, | |
Animated, | |
Component | |
} from 'react-native'; | |
class ReactNativePullDownGrowHeader extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
scrollY: new Animated.Value(0), | |
}; | |
} | |
render() { | |
return ( | |
<ScrollView | |
scrollEventThrottle={ 16 } | |
onScroll={ Animated.event( | |
[{ nativeEvent: { contentOffset: { y: this.state.scrollY }}}] | |
)} | |
> | |
<Animated.View | |
style={[ | |
{ transform: [{ translateY: this.state.scrollY }] }, | |
{ backgroundColor: 'red' }, | |
{ height: this.state.scrollY.interpolate({ | |
inputRange: [ -500, 0 ], | |
outputRange: [ 600, 100 ] | |
})} | |
]} | |
> | |
</Animated.View> | |
</ScrollView> | |
); | |
} | |
}; | |
AppRegistry.registerComponent('ReactNativePullDownGrowHeader', () => ReactNativePullDownGrowHeader); |
Author
rileybracken
commented
Nov 22, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment