Skip to content

Commit

Permalink
feat: creating package module
Browse files Browse the repository at this point in the history
  • Loading branch information
Stringsaeed committed Nov 2, 2022
1 parent 6c3587c commit 66af560
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/index.tsx → src/NotificationsUtilsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const LINKING_ERROR =
'- You rebuilt the app after installing the package\n' +
'- You are not using Expo Go\n';

const NotificationsUtils = NativeModules.NotificationsUtils
const NotificationsUtilsModule = NativeModules.NotificationsUtils
? NativeModules.NotificationsUtils
: new Proxy(
{},
Expand All @@ -17,6 +17,4 @@ const NotificationsUtils = NativeModules.NotificationsUtils
}
);

export function multiply(a: number, b: number): Promise<number> {
return NotificationsUtils.multiply(a, b);
}
export default NotificationsUtilsModule;
47 changes: 47 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Platform } from 'react-native';
import NotificationsUtilsModule from './NotificationsUtilsModule';

type OpenSettingsOptions = {
channelId?: string;
};

interface INotificationsUtils {
/**
* API used to open the Platform specific System settings for the application.
*
* If the API version is >= 26:
* - With no `channelId`, the notification settings screen is displayed.
* - With a `channelId`, the notification settings screen for the specific channel is displayed.
*
* If the API version is < 26, the application settings screen is displayed. The `channelId`
* is ignored.
*
* If an invalid `channelId` is provided (e.g. does not exist), the settings screen will redirect
* back to your application.
*
* On iOS, this is a no-op & instantly resolves.
*
* @platform android
* @param channelId The ID of the channel which will be opened. Can be ignored/omitted to display the
* overall notification settings.
*/
openSettings(options?: OpenSettingsOptions): Promise<void>;
}

const NotificationsUtils: INotificationsUtils = {
openSettings: (options) => {
if (Platform.OS === 'android') {
if (typeof options?.channelId !== 'string') {
throw new Error(
`NotificationsUtils.openSettings: Expected 'channelId' to be a string, got ${typeof options?.channelId}.`
);
}
const { channelId } = options;

return NotificationsUtilsModule.openAppNotificationsSettings(channelId);
}
return NotificationsUtilsModule.openAppNotificationsSettings();
},
};

export default NotificationsUtils;

0 comments on commit 66af560

Please sign in to comment.