Reputation: 38341
React navigation has a well documented setOptions
. https://reactnavigation.org/docs/navigation-prop
However I can't seem to find any method to retrieve the current options for the active navigator. Am I missing something? Or is there a reason why it may be private?
In particular I'm interested in getting the drawerType
option out of Drawer navigator.
Upvotes: 2
Views: 3165
Reputation: 11
We can use navigationRef.getCurrentOptions
// RootNavigation.js
import { createNavigationContainerRef } from '@react-navigation/native';
export const navigationRef = createNavigationContainerRef();
// App.tsx
import * as RootNavigation from './RootNavigation';
function App() {
return (
<View style={{ flex: 1 }}>
<NavigationContainer ref={RootNavigation.navigationRef}>{/* ... */}</NavigationContainer>
</View>
);
}
// Demo.tsx
import { navigationRef } from './RootNavigation';
function Demo() {
const options = navigationRef.getCurrentOptions();
}
docs link: https://reactnavigation.org/docs/5.x/navigation-container/#getcurrentoptions
Upvotes: 1
Reputation: 38341
I just found these two handy methods.
nav.getCurrentOptions()
nav.addListener('options', () => {
})
they are both available on the NavigationContainerRef
, which you can obtain via createNavigationContainerRef()
Upvotes: 3