Skip to content

fix(ios): persist position during page list head changes#1078

Open
alpha0010 wants to merge 1 commit intocallstack:masterfrom
alpha0010:patch-5
Open

fix(ios): persist position during page list head changes#1078
alpha0010 wants to merge 1 commit intocallstack:masterfrom
alpha0010:patch-5

Conversation

@alpha0010
Copy link
Copy Markdown
Contributor

Summary

Dynamic changes to the page list prior to the currently visible page now maintain the same visible page on iOS (this already works on Android).

Fixes #965

Test Plan

What's required for testing (prerequisites)?

function DemoPager() {
  const allPages = [0, 1, 2, 3, 4];
  const [pages, setPages] = useState(allPages);

  const togglePage = (page: number) =>
    setPages((prev) => {
      const itemIndex = prev.indexOf(page);
      const next = [...prev];
      if (itemIndex === -1) {
        next.push(page);
        next.sort((a, b) => a - b);
      } else {
        next.splice(itemIndex, 1);
      }
      return next;
    });

  return (
    <View style={styles.container}>
      <PagerView style={styles.container}>
        {pages.map((page) => (
          <View collapsable={false} key={`x:${page}`}>
            <Text>{page}</Text>
          </View>
        ))}
      </PagerView>
      <View style={styles.container}>
        {allPages.map((page) => (
          <Button
            key={`x:${page}`}
            onPress={() => togglePage(page)}
            title={`Toggle ${page}`}
          />
        ))}
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {flex: 1},
});

What are the steps to reproduce (after prerequisites)?

Use the above test screen to add/remove pages before/after the currently visible page. With this PR, iOS should now match the existing Android behavior.

Compatibility

OS Implemented
iOS
Android N/A

Checklist

  • I have tested this on a device and a simulator
  • I added the documentation in README.md
  • I updated the typed files (TS and Flow)

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

Successfully merging this pull request may close these issues.

(iOS) Dynamic pages causes page switch when adding pages at the start

1 participant