react-native-alarms 0.0.1 → 0.0.3

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.
package/README.md CHANGED
@@ -1,97 +1,429 @@
1
- This is a new [**React Native**](https://reactnative.dev) project, bootstrapped using [`@react-native-community/cli`](https://github.com/react-native-community/cli).
1
+ # React Native Alarms 🔔
2
2
 
3
- # Getting Started
3
+ A powerful, cross-platform alarm management library for React Native. Schedule, manage, and control alarms on both Android and iOS with a unified API.
4
4
 
5
- > **Note**: Make sure you have completed the [Set Up Your Environment](https://reactnative.dev/docs/set-up-your-environment) guide before proceeding.
5
+ [![npm version](https://badge.fury.io/js/react-native-alarms.svg)](https://badge.fury.io/js/react-native-alarms)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
7
 
7
- ## Step 1: Start Metro
8
+ ## Features
8
9
 
9
- First, you will need to run **Metro**, the JavaScript build tool for React Native.
10
+ ✨ **Cross-Platform Support**
11
+ - Seamless support for both Android and iOS
12
+ - Native alarm implementation for reliable delivery
13
+ - Background execution support
10
14
 
11
- To start the Metro dev server, run the following command from the root of your React Native project:
15
+ 🎯 **Comprehensive Alarm Management**
16
+ - Schedule one-time and recurring alarms (daily, weekly, interval-based)
17
+ - Update and cancel alarms
18
+ - Snooze and stop currently ringing alarms
19
+ - Query alarm status
12
20
 
13
- ```sh
14
- # Using npm
15
- npm start
21
+ 🔔 **Event-Driven Architecture**
22
+ - Real-time events for alarm firing, dismissal, and snoozing
23
+ - Easy event listener registration and cleanup
24
+ - Full-screen alarm display on iOS 26+ with AlarmKit
25
+ - Fallback to notifications on older devices
16
26
 
17
- # OR using Yarn
18
- yarn start
27
+ 🔐 **Permission Handling**
28
+ - Automatic permission checking and requesting
29
+ - Platform-specific permission management
30
+ - Detailed permission status reporting
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ npm install react-native-alarms
36
+ # or
37
+ yarn add react-native-alarms
19
38
  ```
20
39
 
21
- ## Step 2: Build and run your app
40
+ ### Native Module Linking
22
41
 
23
- With Metro running, open a new terminal window/pane from the root of your React Native project, and use one of the following commands to build and run your Android or iOS app:
42
+ Since this is a native module, you'll need to link it:
24
43
 
25
- ### Android
44
+ ```bash
45
+ cd ios && pod install && cd ..
46
+ ```
47
+
48
+ For Android, the native code should auto-link.
49
+
50
+ ## Quick Start
51
+
52
+ ### Basic Usage
53
+
54
+ ```typescript
55
+ import { AlarmService } from 'react-native-alarms/service';
56
+
57
+ // Check permissions
58
+ const permission = await AlarmService.checkPermission();
59
+
60
+ // Request permissions if needed
61
+ if (permission.status !== 'granted') {
62
+ await AlarmService.requestPermission();
63
+ }
64
+
65
+ // Schedule an alarm for 10 minutes from now
66
+ const alarmId = await AlarmService.scheduleAlarm({
67
+ timestamp: Date.now() + 10 * 60 * 1000,
68
+ title: 'Wake up!',
69
+ body: 'Time to start your day',
70
+ vibrate: true,
71
+ snoozeEnabled: true,
72
+ snoozeMinutes: 5,
73
+ });
74
+
75
+ console.log('Alarm scheduled:', alarmId);
76
+ ```
77
+
78
+ ### Listening to Alarm Events
79
+
80
+ ```typescript
81
+ import { AlarmService } from 'react-native-alarms/service';
82
+
83
+ // Listen for when alarm fires
84
+ const unsubscribeFired = AlarmService.onAlarmFired((alarm) => {
85
+ console.log('Alarm fired:', alarm.title);
86
+ });
87
+
88
+ // Listen for when alarm is dismissed
89
+ const unsubscribeDismissed = AlarmService.onAlarmDismissed((alarm) => {
90
+ console.log('Alarm dismissed:', alarm.alarmId);
91
+ });
92
+
93
+ // Listen for when alarm is snoozed
94
+ const unsubscribeSnoozed = AlarmService.onAlarmSnoozed((alarm) => {
95
+ console.log('Alarm snoozed:', alarm.alarmId);
96
+ });
97
+
98
+ // Cleanup listeners when done
99
+ unsubscribeFired();
100
+ unsubscribeDismissed();
101
+ unsubscribeSnoozed();
102
+ ```
103
+
104
+ ### Managing Alarms
105
+
106
+ ```typescript
107
+ import { AlarmService } from 'react-native-alarms/service';
108
+
109
+ // Get all scheduled alarms
110
+ const alarms = await AlarmService.getAllAlarms();
111
+
112
+ // Get a specific alarm
113
+ const alarm = await AlarmService.getAlarm(alarmId);
114
+
115
+ // Check if alarm is scheduled
116
+ const isScheduled = await AlarmService.isScheduled(alarmId);
26
117
 
27
- ```sh
28
- # Using npm
29
- npm run android
118
+ // Update an alarm
119
+ await AlarmService.updateAlarm(alarmId, {
120
+ timestamp: Date.now() + 20 * 60 * 1000,
121
+ title: 'Updated alarm',
122
+ });
30
123
 
31
- # OR using Yarn
32
- yarn android
124
+ // Snooze the currently ringing alarm
125
+ await AlarmService.snoozeAlarm(alarmId, 10); // Snooze for 10 minutes
126
+
127
+ // Stop the currently ringing alarm
128
+ await AlarmService.stopAlarm(alarmId);
129
+
130
+ // Cancel a specific alarm
131
+ await AlarmService.cancelAlarm(alarmId);
132
+
133
+ // Cancel all alarms
134
+ await AlarmService.cancelAllAlarms();
33
135
  ```
34
136
 
137
+ ## API Reference
138
+
139
+ ### Types
140
+
141
+ #### `AlarmConfig`
142
+ Configuration object for scheduling alarms.
143
+
144
+ ```typescript
145
+ type AlarmConfig = {
146
+ alarmId?: string; // Unique identifier (auto-generated if omitted)
147
+ timestamp: number; // Time in milliseconds (Date.now() format)
148
+ title: string; // Alarm title/label
149
+ body?: string; // Alarm description
150
+ sound?: string; // 'default' or custom sound file name
151
+ vibrate?: boolean; // Enable vibration (Android only)
152
+ snoozeEnabled?: boolean; // Allow snoozing
153
+ snoozeMinutes?: number; // Snooze duration in minutes
154
+ repeat?: AlarmRepeat; // Repeat configuration
155
+ data?: string; // Custom JSON string payload
156
+ };
157
+ ```
158
+
159
+ #### `AlarmRepeat`
160
+ Repeat configuration for recurring alarms.
161
+
162
+ ```typescript
163
+ type AlarmRepeat = {
164
+ type: 'none' | 'daily' | 'weekly' | 'interval';
165
+ weekdays?: number[]; // 1 = Sunday, 7 = Saturday (for weekly)
166
+ intervalMs?: number; // Interval in milliseconds (for interval type)
167
+ };
168
+ ```
169
+
170
+ #### `Alarm`
171
+ Alarm object returned from queries.
172
+
173
+ ```typescript
174
+ type Alarm = {
175
+ alarmId: string;
176
+ timestamp: number;
177
+ title: string;
178
+ body: string;
179
+ sound: string;
180
+ vibrate: boolean;
181
+ snoozeEnabled: boolean;
182
+ snoozeMinutes: number;
183
+ repeat: AlarmRepeat;
184
+ data: string;
185
+ enabled: boolean;
186
+ nextTriggerAt: number; // 0 if no future trigger
187
+ };
188
+ ```
189
+
190
+ #### `AlarmPermission`
191
+ Permission status object.
192
+
193
+ ```typescript
194
+ type AlarmPermission = {
195
+ status: 'granted' | 'denied' | 'notDetermined';
196
+ notifications: boolean;
197
+ canScheduleExact: boolean;
198
+ canDrawOverlays: boolean; // Android only
199
+ canUseFullScreenIntent: boolean; // Android only
200
+ backend?: string; // iOS only: 'alarmkit' or 'notifications'
201
+ };
202
+ ```
203
+
204
+ ## Platform-Specific Behavior
205
+
35
206
  ### iOS
207
+ - **iOS 26+**: Uses native AlarmKit for real alarms that bypass silent mode
208
+ - **iOS < 26**: Falls back to local notifications
209
+ - Always handles vibration through system settings
210
+ - Full-screen alarm display with system Stop/Snooze buttons
36
211
 
37
- For iOS, remember to install CocoaPods dependencies (this only needs to be run on first clone or after updating native deps).
212
+ ### Android
213
+ - Requires `SCHEDULE_EXACT_ALARM` permission for exact timing
214
+ - Uses full-screen notifications on lock screen
215
+ - Respects silent mode (can be overridden with system settings)
216
+ - Supports custom sounds from app bundle or file system
217
+
218
+ ## Repeat Types
38
219
 
39
- The first time you create a new project, run the Ruby bundler to install CocoaPods itself:
220
+ ### None (One-time)
221
+ ```typescript
222
+ { type: 'none' }
223
+ ```
40
224
 
41
- ```sh
42
- bundle install
225
+ ### Daily
226
+ Rings at the same time every day.
227
+ ```typescript
228
+ { type: 'daily' }
43
229
  ```
44
230
 
45
- Then, and every time you update your native dependencies, run:
231
+ ### Weekly
232
+ Rings at the same time on specified days.
233
+ ```typescript
234
+ {
235
+ type: 'weekly',
236
+ weekdays: [1, 3, 5] // Sunday, Wednesday, Friday
237
+ }
238
+ ```
46
239
 
47
- ```sh
48
- bundle exec pod install
240
+ ### Interval
241
+ Rings at regular intervals. Note: intervals reset if the app is killed.
242
+ ```typescript
243
+ {
244
+ type: 'interval',
245
+ intervalMs: 3600000 // Every hour
246
+ }
49
247
  ```
50
248
 
51
- For more information, please visit [CocoaPods Getting Started guide](https://guides.cocoapods.org/using/getting-started.html).
249
+ ## Building Your Own Alarm UI
250
+
251
+ The library provides the core alarm management logic. You build your own UI components. Here's a complete example:
252
+
253
+ ```typescript
254
+ import React, { useEffect, useState } from 'react';
255
+ import { View, Text, TouchableOpacity, StyleSheet } from 'react-native';
256
+ import { AlarmService } from 'react-native-alarms/service';
257
+
258
+ export function AlarmScreen() {
259
+ const [alarms, setAlarms] = useState([]);
260
+ const [permissions, setPermissions] = useState(null);
261
+
262
+ useEffect(() => {
263
+ initializeAlarms();
264
+ }, []);
265
+
266
+ const initializeAlarms = async () => {
267
+ const perms = await AlarmService.checkPermission();
268
+ setPermissions(perms);
269
+
270
+ if (perms.status !== 'granted') {
271
+ await AlarmService.requestPermission();
272
+ }
273
+
274
+ const allAlarms = await AlarmService.getAllAlarms();
275
+ setAlarms(allAlarms);
276
+
277
+ const unsubFired = AlarmService.onAlarmFired((alarm) => {
278
+ console.log('🔔 Alarm fired:', alarm.title);
279
+ });
280
+
281
+ const unsubSnoozed = AlarmService.onAlarmSnoozed((alarm) => {
282
+ console.log('😴 Alarm snoozed:', alarm.title);
283
+ });
284
+
285
+ return () => {
286
+ unsubFired();
287
+ unsubSnoozed();
288
+ };
289
+ };
290
+
291
+ const scheduleAlarm = async () => {
292
+ const alarmId = await AlarmService.scheduleAlarm({
293
+ timestamp: Date.now() + 5 * 60 * 1000,
294
+ title: 'Time for a break!',
295
+ body: 'Take a moment to rest',
296
+ vibrate: true,
297
+ snoozeEnabled: true,
298
+ snoozeMinutes: 5,
299
+ });
300
+
301
+ const updated = await AlarmService.getAllAlarms();
302
+ setAlarms(updated);
303
+ };
304
+
305
+ return (
306
+ <View style={styles.container}>
307
+ <Text style={styles.title}>Alarm Manager</Text>
308
+
309
+ <TouchableOpacity
310
+ style={styles.button}
311
+ onPress={scheduleAlarm}
312
+ >
313
+ <Text style={styles.buttonText}>Schedule Alarm</Text>
314
+ </TouchableOpacity>
315
+
316
+ <View style={styles.list}>
317
+ {alarms.map((alarm) => (
318
+ <View key={alarm.alarmId} style={styles.alarmItem}>
319
+ <Text>{alarm.title}</Text>
320
+ <Text>{new Date(alarm.timestamp).toLocaleTimeString()}</Text>
321
+ </View>
322
+ ))}
323
+ </View>
324
+ </View>
325
+ );
326
+ }
327
+
328
+ const styles = StyleSheet.create({
329
+ container: { flex: 1, padding: 20 },
330
+ title: { fontSize: 24, fontWeight: 'bold', marginBottom: 20 },
331
+ button: { backgroundColor: '#007AFF', padding: 12, borderRadius: 8 },
332
+ buttonText: { color: '#fff', fontWeight: 'bold', textAlign: 'center' },
333
+ list: { marginTop: 20 },
334
+ alarmItem: { padding: 12, borderBottomWidth: 1, borderBottomColor: '#eee' },
335
+ });
336
+ ```
52
337
 
53
- ```sh
54
- # Using npm
55
- npm run ios
338
+ ## Troubleshooting
56
339
 
57
- # OR using Yarn
58
- yarn ios
340
+ ### "Alarm Native module is not linked"
341
+ Ensure the native module is properly linked:
342
+ ```bash
343
+ cd ios && pod install && cd ..
59
344
  ```
60
345
 
61
- If everything is set up correctly, you should see your new app running in the Android Emulator, iOS Simulator, or your connected device.
346
+ ### Alarms not triggering
347
+ 1. Check permissions: `await AlarmService.checkPermission()`
348
+ 2. Ensure app has necessary permissions:
349
+ - Android: `SCHEDULE_EXACT_ALARM`, `POST_NOTIFICATIONS`
350
+ - iOS: Allow notifications in Settings
351
+
352
+ ### iOS-specific: Notifications instead of full-screen alarm
353
+ - Full-screen alarms (AlarmKit) require iOS 26+
354
+ - Older devices use local notifications
355
+ - Check `permission.backend` to see which is active
62
356
 
63
- This is one way to run your app — you can also build it directly from Android Studio or Xcode.
357
+ ### Android-specific: Alarm doesn't ring when app is killed
358
+ - Enable Autostart permissions on device
359
+ - Check device's battery optimization settings
360
+ - Some OEMs require manual approval in their app management screens
64
361
 
65
- ## Step 3: Modify your app
362
+ ## Contributing
66
363
 
67
- Now that you have successfully run the app, let's make changes!
364
+ Contributions are welcome! Please feel free to submit a Pull Request.
68
365
 
69
- Open `App.tsx` in your text editor of choice and make some changes. When you save, your app will automatically update and reflect these changes — this is powered by [Fast Refresh](https://reactnative.dev/docs/fast-refresh).
366
+ ## License
70
367
 
71
- When you want to forcefully reload, for example to reset the state of your app, you can perform a full reload:
368
+ MIT © 2024 Suraj Prasad
72
369
 
73
- - **Android**: Press the <kbd>R</kbd> key twice or select **"Reload"** from the **Dev Menu**, accessed via <kbd>Ctrl</kbd> + <kbd>M</kbd> (Windows/Linux) or <kbd>Cmd ⌘</kbd> + <kbd>M</kbd> (macOS).
74
- - **iOS**: Press <kbd>R</kbd> in iOS Simulator.
370
+ ## Support
75
371
 
76
- ## Congratulations! :tada:
372
+ For issues and questions, please visit:
373
+ - GitHub Issues: https://github.com/surajprasad13/react-native-alarms/issues
374
+ - Email: surajvishwakarma830@gmail.com
77
375
 
78
- You've successfully run and modified your React Native App. :partying_face:
376
+ ## Changelog
79
377
 
80
- ### Now what?
378
+ ### v0.1.0
379
+ - Improved TypeScript support with proper type exports
380
+ - Added AlarmService convenience class
381
+ - Comprehensive documentation
382
+ - Fixed module linking issues
81
383
 
82
- - If you want to add this new React Native code to an existing application, check out the [Integration guide](https://reactnative.dev/docs/integration-with-existing-apps).
83
- - If you're curious to learn more about React Native, check out the [docs](https://reactnative.dev/docs/getting-started).
384
+ ### v0.0.1
385
+ - Initial release
386
+ - Cross-platform alarm scheduling
387
+ - Event-driven architecture
388
+ - Permission management
84
389
 
85
- # Troubleshooting
390
+ ## Custom Alarm UI & Custom Data
86
391
 
87
- If you're having issues getting the above steps to work, see the [Troubleshooting](https://reactnative.dev/docs/troubleshooting) page.
392
+ The library supports completely custom alarm UI screens with custom data payloads.
88
393
 
89
- # Learn More
394
+ ### Basic Custom Screen Example
395
+
396
+ ```typescript
397
+ import { NativeModules } from 'react-native';
398
+ import { AlarmService } from 'react-native-alarms/service';
399
+
400
+ export function MyCustomAlarmScreen({ alarmId, title, data }) {
401
+ const customData = JSON.parse(data || '{}');
402
+
403
+ return (
404
+ <View style={{ backgroundColor: customData.color }}>
405
+ <Text>{title}</Text>
406
+ <TouchableOpacity onPress={() => AlarmService.stopAlarm(alarmId)}>
407
+ <Text>Stop</Text>
408
+ </TouchableOpacity>
409
+ </View>
410
+ );
411
+ }
412
+ ```
413
+
414
+ ### Passing Custom Data
415
+
416
+ ```typescript
417
+ await AlarmService.scheduleAlarm({
418
+ timestamp: Date.now() + 5 * 60 * 1000,
419
+ title: 'Important!',
420
+ data: JSON.stringify({
421
+ backgroundColor: '#FF5252',
422
+ priority: 'high',
423
+ customMessage: 'This is urgent!',
424
+ }),
425
+ });
426
+ ```
90
427
 
91
- To learn more about React Native, take a look at the following resources:
428
+ **Full Guide:** See [CUSTOM_UI_GUIDE.md](./CUSTOM_UI_GUIDE.md) for complete examples and best practices.
92
429
 
93
- - [React Native Website](https://reactnative.dev) - learn more about React Native.
94
- - [Getting Started](https://reactnative.dev/docs/environment-setup) - an **overview** of React Native and how setup your environment.
95
- - [Learn the Basics](https://reactnative.dev/docs/getting-started) - a **guided tour** of the React Native **basics**.
96
- - [Blog](https://reactnative.dev/blog) - read the latest official React Native **Blog** posts.
97
- - [`@facebook/react-native`](https://github.com/facebook/react-native) - the Open Source; GitHub **repository** for React Native.
package/index.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * React Native Alarms - Type definitions
3
+ * Cross-platform alarm management for React Native
4
+ */
5
+
6
+ export type {
7
+ AlarmRepeat,
8
+ AlarmConfig,
9
+ Alarm,
10
+ AlarmPermission,
11
+ AlarmEvent,
12
+ Spec as AlarmModuleSpec,
13
+ } from './specs/NativeAlarm';
14
+
15
+ // Default export for type compatibility
16
+ export type { Spec as default } from './specs/NativeAlarm';
package/index.ts ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * React Native Alarms - Cross-platform alarm management module
3
+ *
4
+ * Provides consistent alarm scheduling, management, and event handling
5
+ * for both Android and iOS platforms.
6
+ */
7
+
8
+ export type {
9
+ AlarmRepeat,
10
+ AlarmConfig,
11
+ Alarm,
12
+ AlarmPermission,
13
+ AlarmEvent,
14
+ Spec as AlarmModuleSpec,
15
+ } from './specs/NativeAlarm';
16
+
17
+ // Default export for backward compatibility
18
+ import NativeAlarm from './specs/NativeAlarm';
19
+ export default NativeAlarm;
@@ -0,0 +1 @@
1
+ export NODE_BINARY=/opt/homebrew/Cellar/node/26.10.0_1/bin/node
package/package.json CHANGED
@@ -1,19 +1,53 @@
1
1
  {
2
2
  "name": "react-native-alarms",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
+ "description": "A powerful, cross-platform alarm management library for React Native",
4
5
  "private": false,
6
+ "main": "index.ts",
7
+ "types": "index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./index.d.ts",
11
+ "default": "./index.ts"
12
+ },
13
+ "./service": {
14
+ "types": "./AlarmService.d.ts",
15
+ "default": "./AlarmService.ts"
16
+ }
17
+ },
5
18
  "scripts": {
6
19
  "android": "react-native run-android",
7
20
  "ios": "react-native run-ios",
8
21
  "lint": "eslint .",
9
22
  "start": "react-native start",
10
- "test": "jest"
23
+ "test": "jest",
24
+ "prepare": "npm run build",
25
+ "build": "tsc",
26
+ "clean": "rm -rf dist types *.d.ts"
11
27
  },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/surajprasad13/react-native-alarms"
31
+ },
32
+ "keywords": [
33
+ "react-native",
34
+ "alarm",
35
+ "notification",
36
+ "schedule",
37
+ "cross-platform",
38
+ "ios",
39
+ "android"
40
+ ],
12
41
  "author": {
13
42
  "name": "Suraj Prasad",
14
43
  "email": "surajvishwakarma830@gmail.com",
15
44
  "url": "https://github.com/surajprasad13"
16
45
  },
46
+ "license": "MIT",
47
+ "peerDependencies": {
48
+ "react": ">=18.0.0",
49
+ "react-native": ">=0.70.0"
50
+ },
17
51
  "dependencies": {
18
52
  "react": "19.3.0",
19
53
  "react-native": "0.88.0",
package/.eslintrc.js DELETED
@@ -1,4 +0,0 @@
1
- module.exports = {
2
- root: true,
3
- extends: '@react-native',
4
- };
package/.prettierrc.js DELETED
@@ -1,5 +0,0 @@
1
- module.exports = {
2
- arrowParens: 'avoid',
3
- singleQuote: true,
4
- trailingComma: 'all',
5
- };
package/.watchmanconfig DELETED
@@ -1 +0,0 @@
1
- {}