I'm new to react-native,
I have a segment tab controller nested inside a scrollView , I'm trying to scroll the scrollView by code to show the selected segement tab in the top left of the scroll view when a segment tab is being tapped.
for some reason this is not working for me. I hard coded x= 100
for now just for testing purposes , I see the console log of the scroll to segment
in the debugger. but the position does not change.
I call scrollToSegment() from the onTabPress of the method of the segment tab controller.
scrollToSegment = () => {
console.log('scroll to segment')
this.sRef.scrollTo({
x:100,
y:0,
animated:true
});
};
<ScrollView
style={{paddingTop: 40, height: 100}}
horizontal
showsHorizontalScrollIndicator={false}
ref={ref => (this.sRef = ref)}
contentContainerStyle={{ flexGrow: 1 }}
>
<SegmentedControlTab
tabStyle={styles.tabStyle}
tabTextStyle={styles.tabTextStyle}
activeTabStyle={styles.activeTabStyle}
activeTabTextStyle={styles.activeTabTextStyle}
values={categoriesName}
selectedIndex={currentSelectedIndex}
onTabPress={(index) => {
this.scrollToSegment();
return onPressSegmentTab(index)
}
}
/>
</ScrollView>