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

[iOS] Cannot scroll to new dynamic page using setPage() unless scrolled back #921

Closed
tannguyen05 opened this issue Nov 22, 2024 · 4 comments
Assignees

Comments

@tannguyen05
Copy link

Environment

"react-native": "0.74.5",
"react-native-pager-view": "6.5.1",
"react-native-tab-view": "4.0.2"

Description

In my case, the new page can be scrolled to by swipe gesture or manually called using setPage, but currently only swipe gesture is possible (thanks @MrRefactor - #898), setPage is called but it does not change the page

May be related - #791 #597

Expected

The new page can be scrolled to using the setPage method.

@MrRefactor
Copy link
Collaborator

Please check if #923 is fixing your issue

@tannguyen05
Copy link
Author

@MrRefactor sorry, i tried but it still dosen't work

  1. can't scroll to second page
Simulator.Screen.Recording.-.iPhone.15.Pro.Max.-.2024-11-25.at.15.31.25.mp4
  1. can't go to second page using setPage
Simulator.Screen.Recording.-.iPhone.15.Pro.Max.-.2024-11-25.at.15.32.11.mp4

here my code:

const App = () => {
  const [routes, setRoutes] = useState([
    {key: 'first', name: 'First Page'},
    {key: 'add', name: 'Add'},
  ]);
  const pageRef = useRef(null);

  return (
    <SafeAreaView style={{flex: 1, backgroundColor: '#fff'}}>
      <PagerView ref={pageRef} style={{flex: 1}} initialPage={0}>
        {routes.map(item => {
          if (item.key === 'add') {
            return (
              <View
                key={item.key}
                style={{
                  flex: 1,
                  alignItems: 'center',
                  justifyContent: 'center',
                }}>
                <Text>{item.name}</Text>
                <Button
                  title="Add second page"
                  onPress={() => {
                    const newRoutes = [
                      {key: 'first', name: 'First Page'},
                      {key: 'second', name: 'Second Page'},
                      {key: 'add', name: 'Add'},
                    ];
                    setRoutes(newRoutes);
                  }}
                />
                <Button
                  title="go to second page"
                  onPress={() => {
                    pageRef.current.setPage(1);
                  }}
                />
              </View>
            );
          }

          return (
            <View
              key={item.key}
              style={{
                flex: 1,
                alignItems: 'center',
                justifyContent: 'center',
              }}>
              <Text>{item.name}</Text>
            </View>
          );
        })}
      </PagerView>
    </SafeAreaView>
  );
};

export default App;

@MrRefactor
Copy link
Collaborator

hey @tannguyen05 , I cannot reproduce it on latest master branch. I will release 6.5.2 version of the lib, please use it.

Screen.Recording.2024-11-28.at.14.46.21.mov

@MrRefactor MrRefactor self-assigned this Nov 28, 2024
@tannguyen05
Copy link
Author

tannguyen05 commented Dec 2, 2024

@MrRefactor sorry i tried the latest version 6.6.0 but it doesn't seem to work like your video

=====
hey! I think it's because my application doesn't use fabric.

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

No branches or pull requests

2 participants