Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sjchmiela
Last active March 11, 2020 23:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sjchmiela/e1fcb7ca255e77e92bb2c64bc63b7fee to your computer and use it in GitHub Desktop.
Save sjchmiela/e1fcb7ca255e77e92bb2c64bc63b7fee to your computer and use it in GitHub Desktop.
export * from "./expo-nativescript-adapter.common";
export const NativeModulesProxy = {};
const provider = EXModuleRegistryProvider.new();
const moduleRegistry = provider.moduleRegistryForExperienceId(
"@sjchmiela/test"
);
const exportedModules = moduleRegistry.getAllExportedModules();
for (let i = 0; i < exportedModules.count; i++) {
const module = exportedModules[i];
const moduleName = EXExportedModule.exportedModuleName.apply(module.constructor);
NativeModulesProxy[moduleName] = {};
const methods = module.getExportedMethods();
const methodsKeys = methods.allKeys;
for (let j = 0; j < methodsKeys.count; j++) {
const methodName = methodsKeys[j];
NativeModulesProxy[moduleName][methodName] = function callNativeMethod() {
const argumentsArray = Array.from(arguments);
new Promise((resolve, reject) => {
try {
EXExportedModule.prototype.callExportedMethodWithArgumentsResolverRejecter.apply(
module,
[
methodName,
argumentsArray,
result => resolve(result),
(code, message, error) => reject(error || new Error(message))
]
);
} catch (e) {
reject(e);
}
});
};
}
const constants = module.constantsToExport();
const constantsKeys = constants.allKeys;
for (let j = 0; j < constantsKeys.count; j++) {
const constantKey = constantsKeys[j];
NativeModulesProxy[moduleName][constantKey] = constants.objectForKey(constantKey);
}
}
interface EXAppLifecycleListener extends NSObjectProtocol {
onAppBackgrounded(): void;
onAppForegrounded(): void;
}
declare var EXAppLifecycleListener: {
prototype: EXAppLifecycleListener;
};
interface EXAppLifecycleService extends NSObjectProtocol {
registerAppLifecycleListener(listener: EXAppLifecycleListener): void;
setAppStateToBackground(): void;
setAppStateToForeground(): void;
unregisterAppLifecycleListener(listener: EXAppLifecycleListener): void;
}
declare var EXAppLifecycleService: {
prototype: EXAppLifecycleService;
};
declare var EXCoreVersionNumber: number;
declare var EXCoreVersionString: interop.Reference<number>;
declare function EXErrorWithMessage(p1: string): NSError;
interface EXEventEmitter {
startObserving(): void;
stopObserving(): void;
supportedEvents(): NSArray<string>;
}
declare var EXEventEmitter: {
prototype: EXEventEmitter;
};
interface EXEventEmitterService {
sendEventWithNameBody(name: string, body: any): void;
}
declare var EXEventEmitterService: {
prototype: EXEventEmitterService;
};
declare class EXExportedModule extends NSObject implements EXInternalModule, NSCopying {
static alloc(): EXExportedModule; // inherited from NSObject
static exportedInterfaces(): NSArray<any /* Protocol */>;
static exportedModuleName(): string;
static new(): EXExportedModule; // inherited from NSObject
readonly debugDescription: string; // inherited from NSObjectProtocol
readonly description: string; // inherited from NSObjectProtocol
readonly hash: number; // inherited from NSObjectProtocol
readonly isProxy: boolean; // inherited from NSObjectProtocol
readonly superclass: typeof NSObject; // inherited from NSObjectProtocol
readonly // inherited from NSObjectProtocol
constructor(); // inherited from EXInternalModule
constructor(o: { experienceId: string; }); // inherited from EXInternalModule
callExportedMethodWithArgumentsResolverRejecter(methodName: string, _arguments: NSArray<any> | any[], resolver: (p1: any) => void, rejecter: (p1: string, p2: string, p3: NSError) => void): void;
class(): typeof NSObject;
conformsToProtocol(aProtocol: any /* Protocol */): boolean;
constantsToExport(): NSDictionary<any, any>;
copyWithZone(zone: interop.Pointer | interop.Reference<any>): any;
getExportedMethods(): NSDictionary<string, string>;
init(): this;
initWithExperienceId(experienceId: string): this;
isEqual(object: any): boolean;
isKindOfClass(aClass: typeof NSObject): boolean;
isMemberOfClass(aClass: typeof NSObject): boolean;
methodQueue(): NSObject;
performSelector(aSelector: string): any;
performSelectorWithObject(aSelector: string, object: any): any;
performSelectorWithObjectWithObject(aSelector: string, object1: any, object2: any): any;
respondsToSelector(aSelector: string): boolean;
retainCount(): number;
self(): this;
}
declare function EXFatal(p1: NSError): void;
interface EXInternalModule extends NSObjectProtocol {
init?(): EXInternalModule;
initWithExperienceId?(experienceId: string): EXInternalModule;
}
declare var EXInternalModule: {
prototype: EXInternalModule;
exportedInterfaces(): NSArray<any /* Protocol */>;
};
interface EXJavaScriptContextProvider extends NSObjectProtocol {
javaScriptContextRef(): interop.Pointer | interop.Reference<any>;
}
declare var EXJavaScriptContextProvider: {
prototype: EXJavaScriptContextProvider;
};
interface EXKernelService extends NSObjectProtocol {
}
declare var EXKernelService: {
prototype: EXKernelService;
name(): string;
sharedInstance(): EXKernelService;
};
interface EXMethodInfo {
jsName: string;
objcName: string;
}
declare var EXMethodInfo: interop.StructType<EXMethodInfo>;
interface EXModuleInfo {
jsName: string;
internalName: string;
}
declare var EXModuleInfo: interop.StructType<EXModuleInfo>;
declare class EXModuleRegistry extends NSObject {
static alloc(): EXModuleRegistry; // inherited from NSObject
static new(): EXModuleRegistry; // inherited from NSObject
readonly experienceId: string;
constructor(o: { internalModules: NSSet<EXInternalModule>; exportedModules: NSSet<EXExportedModule>; viewManagers: NSSet<EXViewManager>; singletonModules: NSSet<any>; });
getAllExportedModules(): NSArray<EXExportedModule>;
getAllInternalModules(): NSArray<EXInternalModule>;
getAllSingletonModules(): NSArray<any>;
getAllViewManagers(): NSArray<EXViewManager>;
getExportedModuleForName(name: string): EXExportedModule;
getExportedModuleOfClass(moduleClass: typeof NSObject): EXExportedModule;
getModuleImplementingProtocol(protocol: any /* Protocol */): any;
getSingletonModuleForName(singletonModuleName: string): any;
initWithInternalModulesExportedModulesViewManagersSingletonModules(internalModules: NSSet<EXInternalModule>, exportedModules: NSSet<EXExportedModule>, viewManagers: NSSet<EXViewManager>, singletonModules: NSSet<any>): this;
initialize(): void;
registerExportedModule(exportedModule: EXExportedModule): void;
registerInternalModule(internalModule: EXInternalModule): void;
registerViewManager(viewManager: EXViewManager): void;
setDelegate(delegate: EXModuleRegistryDelegate): void;
unregisterInternalModuleForProtocol(protocol: any /* Protocol */): EXInternalModule;
}
interface EXModuleRegistryConsumer extends NSObjectProtocol {
setModuleRegistry(moduleRegistry: EXModuleRegistry): void;
}
declare var EXModuleRegistryConsumer: {
prototype: EXModuleRegistryConsumer;
};
interface EXModuleRegistryDelegate extends NSObjectProtocol {
pickInternalModuleImplementingInterfaceFromAmongModules(interface: any /* Protocol */, internalModules: NSArray<EXInternalModule> | EXInternalModule[]): EXInternalModule;
}
declare var EXModuleRegistryDelegate: {
prototype: EXModuleRegistryDelegate;
};
declare class EXModuleRegistryProvider extends NSObject {
static alloc(): EXModuleRegistryProvider; // inherited from NSObject
static getSingletonModuleForClass(singletonClass: typeof NSObject): EXSingletonModule;
static new(): EXModuleRegistryProvider; // inherited from NSObject
static singletonModules(): NSSet<any>;
moduleRegistryDelegate: EXModuleRegistryDelegate;
constructor(o: { singletonModules: NSSet<any>; });
initWithSingletonModules(modules: NSSet<any>): this;
moduleRegistryForExperienceId(experienceId: string): EXModuleRegistry;
}
declare function EXSharedApplication(): UIApplication;
declare class EXSingletonModule extends NSObject {
static alloc(): EXSingletonModule; // inherited from NSObject
static name(): string;
static new(): EXSingletonModule; // inherited from NSObject
}
interface EXUIManager extends NSObjectProtocol {
addUIBlock(block: (p1: NSDictionary<any, UIView>) => void): void;
addUIBlockForViewImplementingProtocol(block: (p1: any) => void, viewId: any, protocol: any /* Protocol */): void;
addUIBlockForViewOfClass(block: (p1: any) => void, viewId: any, klass: typeof NSObject): void;
dispatchOnClientThread(block: () => void): void;
}
declare var EXUIManager: {
prototype: EXUIManager;
};
declare class EXUtilities extends NSObject implements EXInternalModule, EXModuleRegistryConsumer, EXUtilitiesInterface {
static NSDate(json: any): Date;
static UIColor(json: any): UIColor;
static alloc(): EXUtilities; // inherited from NSObject
static exportedInterfaces(): NSArray<any /* Protocol */>;
static hexStringWithCGColor(color: any): string;
static new(): EXUtilities; // inherited from NSObject
static performSynchronouslyOnMainThread(block: () => void): void;
static screenScale(): number;
readonly debugDescription: string; // inherited from NSObjectProtocol
readonly description: string; // inherited from NSObjectProtocol
readonly hash: number; // inherited from NSObjectProtocol
readonly isProxy: boolean; // inherited from NSObjectProtocol
readonly superclass: typeof NSObject; // inherited from NSObjectProtocol
readonly // inherited from NSObjectProtocol
constructor(); // inherited from EXInternalModule
constructor(o: { experienceId: string; }); // inherited from EXInternalModule
class(): typeof NSObject;
conformsToProtocol(aProtocol: any /* Protocol */): boolean;
currentViewController(): UIViewController;
init(): this;
initWithExperienceId(experienceId: string): this;
isEqual(object: any): boolean;
isKindOfClass(aClass: typeof NSObject): boolean;
isMemberOfClass(aClass: typeof NSObject): boolean;
launchOptions(): NSDictionary<any, any>;
performSelector(aSelector: string): any;
performSelectorWithObject(aSelector: string, object: any): any;
performSelectorWithObjectWithObject(aSelector: string, object1: any, object2: any): any;
respondsToSelector(aSelector: string): boolean;
retainCount(): number;
self(): this;
setModuleRegistry(moduleRegistry: EXModuleRegistry): void;
}
interface EXUtilitiesInterface {
currentViewController(): UIViewController;
launchOptions(): NSDictionary<any, any>;
}
declare var EXUtilitiesInterface: {
prototype: EXUtilitiesInterface;
};
declare class EXViewManager extends EXExportedModule {
static alloc(): EXViewManager; // inherited from NSObject
static new(): EXViewManager; // inherited from NSObject
getPropsNames(): NSDictionary<string, string>;
supportedEvents(): NSArray<string>;
updatePropWithValueOnView(propName: string, value: any, view: UIView): void;
view(): UIView;
viewName(): string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment