118cf86c2STomasz Sapeta // Copyright 2015-present 650 Industries. All rights reserved. 2*cc2b5a7fSGabriel Donadel Dall'Agnol import ExpoModulesCore 318cf86c2STomasz Sapeta 4*cc2b5a7fSGabriel Donadel Dall'Agnol open class DevMenuModule: Module { definitionnull5*cc2b5a7fSGabriel Donadel Dall'Agnol public func definition() -> ModuleDefinition { 6*cc2b5a7fSGabriel Donadel Dall'Agnol Name("ExpoDevMenu") 783ade7efSandy 818cf86c2STomasz Sapeta // MARK: JavaScript API 9*cc2b5a7fSGabriel Donadel Dall'Agnol AsyncFunction("openMenu") { 1018cf86c2STomasz Sapeta DevMenuManager.shared.openMenu() 1118cf86c2STomasz Sapeta } 12aacdc29aSŁukasz Kosmaty 13*cc2b5a7fSGabriel Donadel Dall'Agnol AsyncFunction("closeMenu") { 14169f3220SŁukasz Kosmaty DevMenuManager.shared.closeMenu() 15169f3220SŁukasz Kosmaty } 16169f3220SŁukasz Kosmaty 17*cc2b5a7fSGabriel Donadel Dall'Agnol AsyncFunction("hideMenu") { 18169f3220SŁukasz Kosmaty DevMenuManager.shared.hideMenu() 19169f3220SŁukasz Kosmaty } 20169f3220SŁukasz Kosmaty 21*cc2b5a7fSGabriel Donadel Dall'Agnol AsyncFunction("addDevMenuCallbacks") { (callbacks: [[String: Any]]) in 22169f3220SŁukasz Kosmaty callbacks.forEach { callback in 23169f3220SŁukasz Kosmaty guard let name = callback["name"] as? String else { 24169f3220SŁukasz Kosmaty return 25169f3220SŁukasz Kosmaty } 26169f3220SŁukasz Kosmaty 27169f3220SŁukasz Kosmaty let shouldCollapse = callback["shouldCollapse"] as? Bool ?? true 28169f3220SŁukasz Kosmaty DevMenuManager.shared.registeredCallbacks.append( 29169f3220SŁukasz Kosmaty DevMenuManager.Callback(name: name, shouldCollapse: shouldCollapse) 30169f3220SŁukasz Kosmaty ) 31169f3220SŁukasz Kosmaty } 32*cc2b5a7fSGabriel Donadel Dall'Agnol } 33*cc2b5a7fSGabriel Donadel Dall'Agnol } 34169f3220SŁukasz Kosmaty 35*cc2b5a7fSGabriel Donadel Dall'Agnol deinit { 36*cc2b5a7fSGabriel Donadel Dall'Agnol // cleanup registered callbacks when the bridge is deallocated to prevent these leaking into other (potentially unrelated) bridges 37*cc2b5a7fSGabriel Donadel Dall'Agnol if DevMenuManager.wasInitilized { 38*cc2b5a7fSGabriel Donadel Dall'Agnol DevMenuManager.shared.registeredCallbacks = [] 39*cc2b5a7fSGabriel Donadel Dall'Agnol } 4083ade7efSandy } 4118cf86c2STomasz Sapeta } 42