1 package expo.interfaces.devmenu
2 
3 import android.app.Activity
4 import android.os.Bundle
5 import android.view.KeyEvent
6 import android.view.MotionEvent
7 import com.facebook.react.ReactNativeHost
8 import com.facebook.react.bridge.ReadableMap
9 import expo.interfaces.devmenu.items.DevMenuDataSourceItem
10 import kotlinx.coroutines.CoroutineScope
11 
12 interface DevMenuManagerInterface {
13   /**
14    * Opens the dev menu in provided [activity]
15    */
openMenunull16   fun openMenu(activity: Activity, screen: String? = null)
17 
18   /**
19    * Closes the dev menu.
20    * This method will trigger the js code, which should smoothly hide the menu.
21    */
22   fun closeMenu()
23 
24   /**
25    * Hides the dev menu.
26    * This method will destroyed the current dev menu [Activity].
27    */
28   fun hideMenu()
29 
30   /**
31    * Toggles the dev menu in provided [activity]
32    */
33   fun toggleMenu(activity: Activity)
34 
35   /**
36    * Handles `onKeyEvent`. It's active only if [DevMenuPreferencesInterface.keyCommandsEnabled] is true.
37    */
38   fun onKeyEvent(keyCode: Int, event: KeyEvent): Boolean
39 
40   /**
41    * Handles `onTouchEvent`. It's active only if [DevMenuPreferencesInterface.touchGestureEnabled] is true.
42    */
43   fun onTouchEvent(ev: MotionEvent?)
44 
45   /**
46    * Initializes the dev menu manager to work with provided delegate.
47    */
48   fun setDelegate(newDelegate: DevMenuDelegateInterface)
49 
50   /**
51    * Initializes the dev menu manager to work with react native host.
52    */
53   fun initializeWithReactNativeHost(reactNativeHost: ReactNativeHost)
54 
55   /**
56    * Finds and dispatches action with provided [actionId].
57    * If such action doesn't exist, ignore it.
58    */
59   fun dispatchCallable(actionId: String, args: ReadableMap?)
60 
61   /**
62    * @return a list of dev menu items serialized to the [Bundle].
63    */
64   fun serializedItems(): List<Bundle>
65 
66   /**
67    * @return a list of dev menu screens serialized to the [Bundle].
68    */
69   fun serializedScreens(): List<Bundle>
70 
71   /**
72    * @return a instance of [DevMenuPreferencesInterface] that keeps all settings for current dev menu delegate,
73    * or `null` if delegate wasn't provided.
74    */
75   fun getSettings(): DevMenuPreferencesInterface?
76 
77   /**
78    * @return the dev menu application host.
79    */
80   fun getMenuHost(): ReactNativeHost
81 
82   /**
83    * Synchronizes [ReactInstanceManager] from delegate with one saved in [DevMenuManger].
84    */
85   fun synchronizeDelegate()
86 
87   /**
88    * Set the current screen on which all action will be dispatched.
89    */
90   fun setCurrentScreen(screen: String?)
91 
92   /**
93    * Sends an event to the delegate's bridge if exists.
94    */
95   fun sendEventToDelegateBridge(eventName: String, eventData: Any?)
96 
97   /**
98    * Whether delegate was initialized
99    */
100   fun isInitialized(): Boolean
101 
102   /**
103    * Whether to automatically show the dev menu on app load. Defaults to true if not set.
104    */
105   fun setCanLaunchDevMenuOnStart(shouldAutoLaunch: Boolean)
106 
107   suspend fun fetchDataSource(id: String): List<DevMenuDataSourceItem>
108 
109   val coroutineScope: CoroutineScope
110 }
111