Skip to content

Commit

Permalink
🛠 Refactor: Extract to ModalViewModule
Browse files Browse the repository at this point in the history
Related To:
* TODO:2023-03-04-05-20-26 - Library Native Cleanup

Summary: Extract `ModalViewModule` class from `RNIModalViewModule` to `src/module/ModalViewModule.ts`.
  • Loading branch information
dominicstop committed Mar 3, 2023
1 parent a7dab6f commit ae5869e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 37 deletions.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export * from './ModalView';

export * from './module/ModalViewModule';

export * from './constants/Enums';
export * from './context/ModalContext';
export * from './hoc/withModalLifecycle';
Expand Down
38 changes: 38 additions & 0 deletions src/module/ModalViewModule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { RNIModalViewModule } from 'src/native_modules/RNIModalViewModule';
import * as Helpers from '../functions/helpers';

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

} catch(error){
console.log("RNIModalViewModule, dismissModalByID error:");
console.log(error);
reject(error);
};
});

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

static dismissAllModals(animated = true){
const promise = new Promise((resolve, reject) => {
try {
RNIModalViewModule.dismissAllModals(animated, success => {
(success? resolve : reject)();
});

} catch(error){
console.log("RNIModalViewModule, dismissAllModals error:");
console.log(error);
reject();
};
});

return Helpers.promiseWithTimeout(1000, promise);
};
};
37 changes: 0 additions & 37 deletions src/native_modules/RNIModalViewModule.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { NativeModules, NativeEventEmitter } from 'react-native';
import * as Helpers from '../functions/helpers';

const MODULE_NAME = 'RNIModalViewModule';

Expand All @@ -20,39 +19,3 @@ export const RNIModalViewModule: RNIModalViewModule =

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

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

} catch(error){
console.log("RNIModalViewModule, dismissModalByID error:");
console.log(error);
reject(error);
};
});

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

static dismissAllModals(animated = true){
const promise = new Promise((resolve, reject) => {
try {
RNIModalViewModule.dismissAllModals(animated, success => {
(success? resolve : reject)();
});

} catch(error){
console.log("RNIModalViewModule, dismissAllModals error:");
console.log(error);
reject();
};
});

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

0 comments on commit ae5869e

Please sign in to comment.