Skip to content

Commit 66af560

Browse files
committed
feat: creating package module
1 parent 6c3587c commit 66af560

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

src/index.tsx renamed to src/NotificationsUtilsModule.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const LINKING_ERROR =
66
'- You rebuilt the app after installing the package\n' +
77
'- You are not using Expo Go\n';
88

9-
const NotificationsUtils = NativeModules.NotificationsUtils
9+
const NotificationsUtilsModule = NativeModules.NotificationsUtils
1010
? NativeModules.NotificationsUtils
1111
: new Proxy(
1212
{},
@@ -17,6 +17,4 @@ const NotificationsUtils = NativeModules.NotificationsUtils
1717
}
1818
);
1919

20-
export function multiply(a: number, b: number): Promise<number> {
21-
return NotificationsUtils.multiply(a, b);
22-
}
20+
export default NotificationsUtilsModule;

src/index.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { Platform } from 'react-native';
2+
import NotificationsUtilsModule from './NotificationsUtilsModule';
3+
4+
type OpenSettingsOptions = {
5+
channelId?: string;
6+
};
7+
8+
interface INotificationsUtils {
9+
/**
10+
* API used to open the Platform specific System settings for the application.
11+
*
12+
* If the API version is >= 26:
13+
* - With no `channelId`, the notification settings screen is displayed.
14+
* - With a `channelId`, the notification settings screen for the specific channel is displayed.
15+
*
16+
* If the API version is < 26, the application settings screen is displayed. The `channelId`
17+
* is ignored.
18+
*
19+
* If an invalid `channelId` is provided (e.g. does not exist), the settings screen will redirect
20+
* back to your application.
21+
*
22+
* On iOS, this is a no-op & instantly resolves.
23+
*
24+
* @platform android
25+
* @param channelId The ID of the channel which will be opened. Can be ignored/omitted to display the
26+
* overall notification settings.
27+
*/
28+
openSettings(options?: OpenSettingsOptions): Promise<void>;
29+
}
30+
31+
const NotificationsUtils: INotificationsUtils = {
32+
openSettings: (options) => {
33+
if (Platform.OS === 'android') {
34+
if (typeof options?.channelId !== 'string') {
35+
throw new Error(
36+
`NotificationsUtils.openSettings: Expected 'channelId' to be a string, got ${typeof options?.channelId}.`
37+
);
38+
}
39+
const { channelId } = options;
40+
41+
return NotificationsUtilsModule.openAppNotificationsSettings(channelId);
42+
}
43+
return NotificationsUtilsModule.openAppNotificationsSettings();
44+
},
45+
};
46+
47+
export default NotificationsUtils;

0 commit comments

Comments
 (0)