Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sync two scrollviews in react native?

My requirement is to create a table with fixed header and first column, table data will scroll in both horizontal and vertical directions.

for this I have used 3 scrollviews , following gif will make it clear enter image description here

  1. 1st scrollview is the header name row, it is set to horizontal = true (i.e its scroll direction is horizontal)
  2. 2nd scrollview is kcname 1st column of the table, it is vertical scroll, both of these have scrollEnabled={false}, as they wont take scroll gesture, they are scroll programmatically using scrollTo
  3. 3rd scrollview is body cell table filled with data, this view has 2 scrollviews as parent , one to take horizontal scroll and another to take vertical scroll.

the scroll values of two body scroll views are put in scrollTo of the other two scrollview using refs on onScroll event, scrollEventThrottle value is 16 .

My problem is how to sync these scrollviews scrolls as this clearly shows lag, which is not acceptable

like image 674
Abhinav Singh Avatar asked Apr 11 '17 07:04

Abhinav Singh


People also ask

How do I use two ScrollView in react native?

let firstRef: ScrollView | null; let secondRef: ScrollView | null; <ScrollView ref={ref => (firstRef = ref)}> ... <ScrollView ref={ref => (secondRef = ref)} onScroll={e => { if(firstRef) { firstRef. scrollTo({ x: e. nativeEvent.

How do I sync my scroll in react?

All you need is to: make <ScrollSync> as a common parent to your nodes you want to sync scroll with other nodes (which is a React component that uses React's new Context API) and then wrap each scrollable-node with a <ScrollSyncNode>

What is scrollEventThrottle?

scrollEventThrottle: It is used to control the firing of scroll events while scrolling.


1 Answers

Disable scrollTos animation like this:

this.toolbar.scrollTo({
  x: yourXValue,
  animated: false,
});

Then there is no lag :)

like image 142
Henrik R Avatar answered Nov 09 '22 00:11

Henrik R