react-native-alarms 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,246 @@
1
+ export interface AlarmPresentation {
2
+ /**
3
+ * Registered presentation type, such as "alarm" or "reminder".
4
+ */
5
+ type?: string;
6
+
7
+ /**
8
+ * Optional props supplied to the selected React Native screen.
9
+ */
10
+ props?: Record<string, unknown>;
11
+ }
12
+
13
+ /**
14
+ * Shared contract for the native `Alarm` module.
15
+ *
16
+ * This module provides cross-platform native scheduling for React Native.
17
+ * While it can be used as a traditional alarm clock, it is also designed for
18
+ * exact-time reminders, scheduled wake-up flows, recurring tasks, and
19
+ * custom full-screen React Native experiences.
20
+ *
21
+ * Native module name: `Alarm`
22
+ *
23
+ * Events emitted through `NativeEventEmitter`:
24
+ * - `onAlarmFired`
25
+ * - `onAlarmDismissed`
26
+ * - `onAlarmSnoozed`
27
+ */
28
+
29
+ /**
30
+ * Repeat configuration for a scheduled alarm.
31
+ */
32
+ export type AlarmRepeat = {
33
+ /**
34
+ * Repeat strategy.
35
+ *
36
+ * - `none` – Fires once.
37
+ * - `daily` – Repeats every day.
38
+ * - `weekly` – Repeats on selected weekdays.
39
+ * - `interval` – Repeats after a fixed interval.
40
+ */
41
+ type: 'none' | 'daily' | 'weekly' | 'interval';
42
+
43
+ /**
44
+ * Weekdays used when `type` is `weekly`.
45
+ *
46
+ * Values:
47
+ * - `1` = Sunday
48
+ * - `2` = Monday
49
+ * - `3` = Tuesday
50
+ * - `4` = Wednesday
51
+ * - `5` = Thursday
52
+ * - `6` = Friday
53
+ * - `7` = Saturday
54
+ */
55
+ weekdays?: number[];
56
+
57
+ /**
58
+ * Repeat interval in milliseconds.
59
+ *
60
+ * Used only when `type` is `interval`.
61
+ */
62
+ intervalMs?: number;
63
+ };
64
+
65
+ /**
66
+ * Configuration used when scheduling or updating an alarm.
67
+ */
68
+ export type AlarmConfig = {
69
+ /**
70
+ * Optional unique identifier.
71
+ *
72
+ * If omitted, the native module generates one automatically.
73
+ */
74
+ alarmId?: string;
75
+
76
+ /**
77
+ * Trigger time in Unix milliseconds.
78
+ *
79
+ * Example:
80
+ * `Date.now() + 60000`
81
+ */
82
+ timestamp: number;
83
+
84
+ /**
85
+ * Title displayed when the alarm fires.
86
+ */
87
+ title: string;
88
+
89
+ /**
90
+ * Optional body or description.
91
+ */
92
+ body?: string;
93
+
94
+ /**
95
+ * Alarm sound.
96
+ *
97
+ * Use `"default"` or a bundled sound file name.
98
+ */
99
+ sound?: string;
100
+
101
+ /**
102
+ * Enables vibration.
103
+ *
104
+ * Android only.
105
+ * iOS vibration follows system behavior.
106
+ */
107
+ vibrate?: boolean;
108
+
109
+ /**
110
+ * Whether snoozing is allowed.
111
+ */
112
+ snoozeEnabled?: boolean;
113
+
114
+ /**
115
+ * Snooze duration in minutes.
116
+ */
117
+ snoozeMinutes?: number;
118
+
119
+ /**
120
+ * Repeat configuration.
121
+ */
122
+ repeat?: AlarmRepeat;
123
+
124
+ /**
125
+ * Optional JSON string passed back when the alarm fires.
126
+ *
127
+ * Useful for:
128
+ * - task IDs
129
+ * - appointment IDs
130
+ * - navigation targets
131
+ * - custom UI data
132
+ */
133
+ data?: string;
134
+
135
+ /** Screen selection and custom props for the ringing experience. */
136
+ presentation?: AlarmPresentation;
137
+ };
138
+
139
+ /**
140
+ * Alarm object returned from native queries.
141
+ */
142
+ export type AlarmProp = {
143
+ /** Unique alarm identifier. */
144
+ alarmId: string;
145
+
146
+ /** Scheduled trigger timestamp. */
147
+ timestamp: number;
148
+
149
+ /** Alarm title. */
150
+ title: string;
151
+
152
+ /** Alarm body. */
153
+ body: string;
154
+
155
+ /** Sound being used. */
156
+ sound: string;
157
+
158
+ /** Whether vibration is enabled. */
159
+ vibrate: boolean;
160
+
161
+ /** Whether snooze is enabled. */
162
+ snoozeEnabled: boolean;
163
+
164
+ /** Snooze duration in minutes. */
165
+ snoozeMinutes: number;
166
+
167
+ /** Repeat configuration. */
168
+ repeat: AlarmRepeat;
169
+
170
+ /** Custom payload. */
171
+ data: string;
172
+
173
+ /** Whether the alarm is currently enabled. */
174
+ enabled: boolean;
175
+
176
+ /**
177
+ * Next scheduled trigger.
178
+ *
179
+ * `0` means no future trigger exists.
180
+ */
181
+ nextTriggerAt: number;
182
+ };
183
+
184
+ /**
185
+ * Permission status returned by the native module.
186
+ */
187
+ export type AlarmPermission = {
188
+ /**
189
+ * Overall permission state.
190
+ */
191
+ status: 'granted' | 'denied' | 'notDetermined';
192
+
193
+ /** Notification permission. */
194
+ notifications: boolean;
195
+
196
+ /**
197
+ * Whether exact scheduling is available.
198
+ *
199
+ * Primarily relevant on Android.
200
+ */
201
+ canScheduleExact: boolean;
202
+
203
+ /**
204
+ * Overlay permission.
205
+ *
206
+ * Android only.
207
+ * Always `true` on iOS.
208
+ */
209
+ canDrawOverlays: boolean;
210
+
211
+ /**
212
+ * Full-screen intent capability.
213
+ *
214
+ * Android only.
215
+ * Always `true` on iOS.
216
+ */
217
+ canUseFullScreenIntent: boolean;
218
+
219
+ /**
220
+ * iOS backend currently in use.
221
+ *
222
+ * - `alarmkit`
223
+ * - `notifications`
224
+ */
225
+ backend?: 'alarmkit' | 'notifications';
226
+ };
227
+
228
+ /**
229
+ * Event payload emitted through `NativeEventEmitter`.
230
+ */
231
+ export type AlarmEvent = {
232
+ /** Alarm identifier. */
233
+ alarmId: string;
234
+
235
+ /** Original trigger timestamp. */
236
+ timestamp: number;
237
+
238
+ /** Alarm title. */
239
+ title: string;
240
+
241
+ /** Alarm body. */
242
+ body: string;
243
+
244
+ /** Custom JSON payload. */
245
+ data: string;
246
+ };
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Registered React Native screens that can be presented by the alarm system.
3
+ */
4
+
5
+ export type AlarmScreenProps = Record<string, unknown>;
6
+
7
+ export interface AlarmScreenRegistration {
8
+ /** Unique key used in an alarm's presentation configuration. */
9
+ type: string;
10
+
11
+ /** Name registered with React Native's AppRegistry. */
12
+ componentName: string;
13
+ }
14
+
15
+ const DEFAULT_COMPONENT_NAME = 'AlarmRing';
16
+
17
+ const registrations = new Map<string, AlarmScreenRegistration>();
18
+
19
+ /**
20
+ * Registers a screen that can be used for alarm presentation.
21
+ *
22
+ * The component must also be registered using AppRegistry.registerComponent.
23
+ *
24
+ * @example
25
+ * AlarmRegistry.register('reminder', 'ReminderScreen');
26
+ */
27
+ export const AlarmRegistry = {
28
+ register(type: string, componentName: string): void {
29
+ if (!type.trim() || !componentName.trim()) {
30
+ throw new Error('Alarm type and component name are required.');
31
+ }
32
+
33
+ registrations.set(type, { type, componentName });
34
+ },
35
+
36
+ unregister(type: string): boolean {
37
+ return registrations.delete(type);
38
+ },
39
+
40
+ resolve(type?: string): string {
41
+ if (!type) {
42
+ return DEFAULT_COMPONENT_NAME;
43
+ }
44
+
45
+ const registration = registrations.get(type);
46
+
47
+ if (!registration) {
48
+ throw new Error(`No alarm screen registered for type "${type}".`);
49
+ }
50
+
51
+ return registration.componentName;
52
+ },
53
+
54
+ getRegisteredScreens(): AlarmScreenRegistration[] {
55
+ return Array.from(registrations.values());
56
+ },
57
+ };
@@ -0,0 +1 @@
1
+ export * from './AlarmRegistry';