1 // Copyright 2015-present 650 Industries. All rights reserved.
2 import ExpoModulesCore
3 
4 open class DevMenuModule: Module {
definitionnull5   public func definition() -> ModuleDefinition {
6     Name("ExpoDevMenu")
7 
8     // MARK: JavaScript API
9     AsyncFunction("openMenu") {
10       DevMenuManager.shared.openMenu()
11     }
12 
13     AsyncFunction("closeMenu") {
14       DevMenuManager.shared.closeMenu()
15     }
16 
17     AsyncFunction("hideMenu") {
18       DevMenuManager.shared.hideMenu()
19     }
20 
21     AsyncFunction("addDevMenuCallbacks") { (callbacks: [[String: Any]]) in
22       callbacks.forEach { callback in
23         guard let name = callback["name"] as? String else {
24           return
25         }
26 
27         let shouldCollapse = callback["shouldCollapse"] as? Bool ?? true
28         DevMenuManager.shared.registeredCallbacks.append(
29           DevMenuManager.Callback(name: name, shouldCollapse: shouldCollapse)
30         )
31       }
32     }
33   }
34 
35   deinit {
36     // cleanup registered callbacks when the bridge is deallocated to prevent these leaking into other (potentially unrelated) bridges
37     if DevMenuManager.wasInitilized {
38       DevMenuManager.shared.registeredCallbacks = []
39     }
40   }
41 }
42