Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay/Flicker in View when setting State in onPageSelected #766

Open
RemiHin opened this issue Sep 4, 2023 · 3 comments
Open

Delay/Flicker in View when setting State in onPageSelected #766

RemiHin opened this issue Sep 4, 2023 · 3 comments
Labels
question Further information is requested

Comments

@RemiHin
Copy link

RemiHin commented Sep 4, 2023

I've created a PagerView with an onPageSelected callback:

const [index, setIndex] = useState(0);
                <PagerView
                  ref={pagerRef}
                  className={'flex-1'}
                  onPageSelected={onPageSelected}
                  initialPage={index}>
                  <View key="1">
                    <Text className={'text-black'}>First page</Text>
                  </View>
                  <View key="2">
                    <Text className={'text-black'}>Second page</Text>
                  </View>
                </PagerView>
  const onPageSelected = (event) => {
    const {position} = event.nativeEvent;
    if(position !== index) {
      setIndex(position);
    }
  }

When i change view, there is a small delay. I've traced it back to the setIndex() useState.
I want to use the index to show different button styles based on if it is the active view or not.

How do i get around this?
When i remove the setIndex(), its super smooth, but I dont have access to the current active page.
Can i get the current active page from the ref? Is there a better way to implement this?

@RemiHin RemiHin added the question Further information is requested label Sep 4, 2023
@lucaslucenagithub
Copy link

Did you get it?

@RemiHin
Copy link
Author

RemiHin commented Sep 29, 2023

I did fix it, but I did it by rebuilding the entire component from scratch. Dont know what i did different the second time, i think it might be something with multiple state updates or useeffects creating the flicker.

@tmKnight01
Copy link

I did fix it, but I did it by rebuilding the entire component from scratch. Dont know what i did different the second time, i think it might be something with multiple state updates or useeffects creating the flicker.

can you tell me how to reslove this problem ? i also have this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants