Skip to content

Commit

Permalink
⭐️ Impl: Types - Add Types for RNIModalViewModule
Browse files Browse the repository at this point in the history
TODO:2023-03-04-04-20-46 - Library Typescript Re-Write
  • Loading branch information
dominicstop committed Mar 3, 2023
1 parent fc2ca7d commit a7dab6f
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/native_modules/RNIModalViewModule.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
import { NativeModules, NativeEventEmitter } from 'react-native';
import * as Helpers from '../functions/helpers';

const moduleName = "RNIModalViewModule";
const NativeModule = NativeModules[moduleName];
const MODULE_NAME = 'RNIModalViewModule';

const COMMAND_KEYS = {
dismissModalByID: 'dismissModalByID',
dismissAllModals: 'dismissAllModals'
};
interface RNIModalViewModule {
dismissModalByID( //
modalID: string,
callback: (success: boolean) => void
): void;

dismissAllModals( //
animated: boolean,
callback: (success: boolean) => void
): void;
}

// wip
const ModalViewFocusEvents = new NativeEventEmitter(NativeModule);
export const RNIModalViewModule: RNIModalViewModule =
NativeModules[MODULE_NAME];

export class RNIModalViewModule {
export const RNIModalViewFocusEvents = //
new NativeEventEmitter(RNIModalViewModule as any);

export class ModalViewModule {
static dismissModalByID(modalID = ''){
const promise = new Promise((resolve, reject) => {
try {
NativeModule[COMMAND_KEYS.dismissModalByID](modalID, success => {
RNIModalViewModule.dismissModalByID(modalID, success => {
(success? resolve : reject)();
});

Expand All @@ -33,7 +42,7 @@ export class RNIModalViewModule {
static dismissAllModals(animated = true){
const promise = new Promise((resolve, reject) => {
try {
NativeModule[COMMAND_KEYS.dismissAllModals](animated, success => {
RNIModalViewModule.dismissAllModals(animated, success => {
(success? resolve : reject)();
});

Expand All @@ -46,4 +55,4 @@ export class RNIModalViewModule {

return Helpers.promiseWithTimeout(1000, promise);
};
};
};

0 comments on commit a7dab6f

Please sign in to comment.