Created
August 2, 2018 19:52
-
-
Save camiloibarrayepes/1cbda389d6d0a107e7d6afc5653d9cc1 to your computer and use it in GitHub Desktop.
ScrollBar/ScrollIndicator React Native
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
| /*--------- variable ----------*/ | |
| this.state={varScroll:false} | |
| /*-------- Functions ----------*/ | |
| setvarScrollState() { | |
| this.setState({VarScroll: true}); | |
| } | |
| setvarScrollStateRev() { | |
| this.setState({VarScroll: false}); | |
| } | |
| /*-------- View ----------*/ | |
| <View style={{flexDirection: 'row', justifyContent: 'flex-end', marginHorizontal: 7}}> | |
| { | |
| this.state.hScroll > 1000 || this.state.hScroll == 0 ? | |
| <View | |
| style = {{ | |
| marginTop: (this.state.wScroll / this.state.hScroll) < 0.1 || this.state.hScroll == 0 ? 15 : 200*(this.state.wScroll / this.state.hScroll), | |
| marginHorizontal: 200, | |
| height: 35, | |
| width: 2, | |
| backgroundColor: 'grey', | |
| position:'absolute' | |
| }} | |
| /> | |
| : | |
| this.state.hScroll < 200 ? | |
| null | |
| : | |
| <View | |
| style = {{ | |
| marginTop: (this.state.wScroll / this.state.hScroll) < 0.1 ? 15 : 220*(this.state.wScroll / this.state.hScroll), | |
| marginLeft:338.5, | |
| height: 65, | |
| width: 2, | |
| backgroundColor: 'grey', | |
| position:'absolute' | |
| }} | |
| /> | |
| } | |
| <ScrollView | |
| onMomentumScrollBegin={() => {this.setvarScrollState()}} | |
| onMomentumScrollEnd={() => {this.setvarScrollStateRev()}} | |
| scrollEventThrottle={5} | |
| onContentSizeChange={(w, h) => this.state.hScroll = h} | |
| showsVerticalScrollIndicator={false} | |
| onScroll={event => { | |
| this.state.wScroll = event.nativeEvent.contentOffset.y | |
| }} | |
| style={{ marginVertical: 15, marginHorizontal:15, width: this.state.measurements3.width}}> | |
| { | |
| item.map((value, index) => { | |
| return <TouchableOpacity | |
| style={{marginVertical:6, alignSelf:'center'}} | |
| > | |
| <Text>{ value.itemName }</Text> | |
| </TouchableOpacity> | |
| }) | |
| } | |
| </ScrollView> | |
| </View> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment