Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding items to Android React Native Developer menu

In React Native when making development builds you can shake the device or use the menu button to bring up a developer menu. How do you add an additional custom item to this menu? I haven't been able to find any documentation on adding another item but I think it would be very handy to say toggle between server environments (dev, prod, etc.) from the dev menu rather than making separate builds to test against each environment.

like image 326
Steven Avatar asked Feb 05 '16 03:02

Steven


1 Answers

You can use DevSettings addMenuItem function to add item in React Native developer menu

in your main App.js component, write

import { DevSettings } from 'react-native';

//...

useEffect(() => {
    // componentDidMount

    // Add our toggle command to the menu
    DevSettings.addMenuItem('Toggle Storybook', () => {
        // Perform your logic here
    });
}, []);
like image 156
Sanjeev Avatar answered Nov 15 '22 09:11

Sanjeev