PedroBern / react-native-collapsible-tab-view

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

How to programatically switch tabs? #387

Open 1mike12 opened 5 months ago

1mike12 commented 5 months ago

I need to be able to programatically switch to a specific tab, how do we do that?

I wouldve assumed an api where we keep the index in state, and listen back to onIndexChanges,

failing that, a ref to access the internal methods of the container. But can't see any docs about either

1mike12 commented 5 months ago

after looking at the source I found we can do

ref = createRef<Tabs.Container>()
this.ref.current?.jumpToTab("following")

It works but there's still a typescript error TS2503: Cannot find namespace Tabs

Is there a better way to do this?

SrAnthony commented 5 months ago

There's a CollapsibleRef type you can use: const ref = useRef<CollapsibleRef>(null)