Skip to content

Instantly share code, notes, and snippets.

@gHashTag
Created April 3, 2018 10:14
Show Gist options
  • Select an option

  • Save gHashTag/0bb21929538ad58cda86a1257e740cdf to your computer and use it in GitHub Desktop.

Select an option

Save gHashTag/0bb21929538ad58cda86a1257e740cdf to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
import { ScrollView, View, Text } from 'react-native'
class App extends Component {
state = {
scrollY: window.scrollY
}
componentDidMount() {
window.addEventListener('scroll', this.handleScroll)
}
componentWillUnmount() {
window.removeEventListener('scroll', this.handleScroll)
}
handleScroll = () => {
this.setState({ scrollY: window.scrollY })
}
render() {
console.log('state', this.state.scrollY)
const { scrollY } = this.state
return (
<View>
<Text style={{ fontSize: 50, marginBottom: 500, marginTop: 100 }}>Hello world1</Text>
<Text style={{ fontSize: 50, marginBottom: 500, marginTop: 100 }}>Hello world2</Text>
<View style={{ position: 'fixed' }}>
<Text style={{ fontSize: 50, transform: [{ translateX: scrollY }], marginBottom: 900, marginTop: 100 }}>Hello world3</Text>
</View>
</View>
)
}
}
export default App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment