Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save camiloibarrayepes/1cbda389d6d0a107e7d6afc5653d9cc1 to your computer and use it in GitHub Desktop.

Select an option

Save camiloibarrayepes/1cbda389d6d0a107e7d6afc5653d9cc1 to your computer and use it in GitHub Desktop.
ScrollBar/ScrollIndicator React Native
/*--------- 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