PedroBern / react-native-collapsible-tab-view

A cross-platform Collapsible Tab View component for React Native
MIT License
875 stars 171 forks source link

`ref.current?.setIndex(n)` causes header to hide #138

Closed alexpchin closed 3 years ago

alexpchin commented 3 years ago

When using setIndex the header hides on iOS. You can test by adding something like:

  useEffect(() => {
    setTimeout(() => {
      pageRef.current?.setIndex(0);
    }, 500);
  }, []);
alexpchin commented 3 years ago

I will add more details to this ticket. We should probably also add a check here:

const name = tabNames.value[index]

To ensure that the index is a valid one.

andreialecu commented 3 years ago

This does not reproduce in the Example app's "Ref example jumpToTab after 1 second" (which does the same thing).

A more detailed repro would help.

alexpchin commented 3 years ago

Hi @andreialecu I've added:

React.useEffect(() => {
    setTimeout(() => {
      // Only seems to happen with `0`
      pageRef.current?.setIndex(0);
    }, 500);
  }, []);

To this PR https://github.com/andreialecu/rnctv-react-native-bare-test/pull/2 Please tell me if you can reproduce.

alexpchin commented 3 years ago

I can also confirm this happens on the example app when using setIndex(0)

andreialecu commented 3 years ago

I see.

This only happens if the index is already the same as the one being set to. It's essentially the same as clicking on the tab bar for the same tab pane.

To clarify, if you increase the timeout to 2500 in your repro and move to index 1 before it sets 0, you'll see that it doesn't hide the header.

I'm not sure if I'd call it a feature or a bug. 🤔

andreialecu commented 3 years ago

To clarify, you can work around it via:

      const index = pageRef.current?.getCurrentIndex();
      if (index !== 0) {
        pageRef.current?.setIndex(0);
      }
alexpchin commented 3 years ago

Thanks for the clarification @andreialecu