[react-native] Add module DevSettings (#43679)

* feat: add dev settings to react-native

* test: add test calls for dev settings

* fix: remove trailing whitespace
This commit is contained in:
Christian Ost
2020-04-07 12:26:29 +02:00
committed by GitHub
parent 8e966505a0
commit cbb0a943e2
2 changed files with 31 additions and 0 deletions

View File

@@ -35,6 +35,7 @@
// Mohamed Shaban <https://github.com/drmas>
// André Krüger <https://github.com/akrger>
// Jérémy Barbet <https://github.com/jeremybarbet>
// Christian Ost <https://github.com/ca057>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
@@ -8913,6 +8914,28 @@ export interface KeyboardStatic extends NativeEventEmitter {
addListener(eventType: KeyboardEventName, listener: KeyboardEventListener): EmitterSubscription;
}
/**
* The DevSettings module exposes methods for customizing settings for developers in development.
*/
export interface DevSettingsStatic extends NativeEventEmitter {
/**
* Adds a custom menu item to the developer menu.
*
* @param title - The title of the menu item. Is internally used as id and should therefore be unique.
* @param handler - The callback invoked when pressing the menu item.
*/
addMenuItem(title: string, handler: () => any): void;
/**
* Reload the application.
*
* @param reason
*/
reload(reason?: string): void;
}
export const DevSettings: DevSettingsStatic;
//////////////////////////////////////////////////////////////////////////
//
// R E - E X P O R T S

View File

@@ -96,6 +96,7 @@ import {
HostComponent,
Appearance,
useColorScheme,
DevSettings,
} from 'react-native';
declare module 'react-native' {
@@ -1085,3 +1086,10 @@ const DarkMode = () => {
return <Text>Is dark mode enabled? {isDarkMode}</Text>;
};
// DevSettings
DevSettings.addMenuItem('alert', () => {
Alert.alert('alert');
});
DevSettings.reload();
DevSettings.reload('reload with reason');