Created
April 3, 2018 10:14
-
-
Save gHashTag/0bb21929538ad58cda86a1257e740cdf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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