torgeadelin / react-native-animated-nav-tab-bar

A simple and customisable React Native component that implements an animated bottom tab bar for React Navigation.
MIT License
889 stars 102 forks source link

State force reset when switching between tabs #118

Closed kockok closed 2 years ago

kockok commented 2 years ago

I use const [isOpen, setIsOpen] = useState(false); to control the state of an accordion.

However, when I switch to other tabs, the screen state of the original tab component will always be reset.

Is this intended?

I tried setting

options={{
          unmountOnBlur: false,
}}

But the local state will still be forced to set back to the default value.

I've tried all these options, only setting component={ComponentA} will keep the local state.

kockok commented 2 years ago

I figured out that when I change back to <Tabs.screen component={ComponentA} />, the state retains. However, when I render the component explicitly:

    <Tabs.Screen
        name="ComponentA"
        options={{
          unmountOnBlur: false,
        }}
      >
        {(props) => <ComponentA {...props} tess={'TEST'} />}
      </Tabs.Screen>

then the state won't keep, just wondering how to keep the state intact with the second component rendering method.

Also, if I use initialParams={{ tess: 'test' }} to pass props, rerender will be triggered and the state will be lost.

github-actions[bot] commented 2 years ago

Stale issue message