2

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.

Tony
  • 36,591
  • 10
  • 48
  • 83

2 Answers2

2

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()

Tony
  • 36,591
  • 10
  • 48
  • 83
0

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

keyre
  • 1