react-native-alarms 0.0.1 → 0.0.2

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,386 @@
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
26
51
 
27
- ```sh
28
- # Using npm
29
- npm run android
52
+ ### Basic Usage
30
53
 
31
- # OR using Yarn
32
- yarn android
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);
33
76
  ```
34
77
 
35
- ### iOS
78
+ ### Listening to Alarm Events
36
79
 
37
- For iOS, remember to install CocoaPods dependencies (this only needs to be run on first clone or after updating native deps).
80
+ ```typescript
81
+ import { AlarmService } from 'react-native-alarms/service';
38
82
 
39
- The first time you create a new project, run the Ruby bundler to install CocoaPods itself:
83
+ // Listen for when alarm fires
84
+ const unsubscribeFired = AlarmService.onAlarmFired((alarm) => {
85
+ console.log('Alarm fired:', alarm.title);
86
+ });
40
87
 
41
- ```sh
42
- bundle install
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();
43
102
  ```
44
103
 
45
- Then, and every time you update your native dependencies, run:
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);
117
+
118
+ // Update an alarm
119
+ await AlarmService.updateAlarm(alarmId, {
120
+ timestamp: Date.now() + 20 * 60 * 1000,
121
+ title: 'Updated alarm',
122
+ });
123
+
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);
46
132
 
47
- ```sh
48
- bundle exec pod install
133
+ // Cancel all alarms
134
+ await AlarmService.cancelAllAlarms();
49
135
  ```
50
136
 
51
- For more information, please visit [CocoaPods Getting Started guide](https://guides.cocoapods.org/using/getting-started.html).
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
+
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
211
+
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
219
+
220
+ ### None (One-time)
221
+ ```typescript
222
+ { type: 'none' }
223
+ ```
52
224
 
53
- ```sh
54
- # Using npm
55
- npm run ios
225
+ ### Daily
226
+ Rings at the same time every day.
227
+ ```typescript
228
+ { type: 'daily' }
229
+ ```
56
230
 
57
- # OR using Yarn
58
- yarn ios
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
+ }
59
238
  ```
60
239
 
61
- If everything is set up correctly, you should see your new app running in the Android Emulator, iOS Simulator, or your connected device.
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
+ }
247
+ ```
62
248
 
63
- This is one way to run your app — you can also build it directly from Android Studio or Xcode.
249
+ ## Complete Example
250
+
251
+ ```typescript
252
+ import React, { useEffect, useState } from 'react';
253
+ import { View, Text, TouchableOpacity, StyleSheet } from 'react-native';
254
+ import { AlarmService } from 'react-native-alarms/service';
255
+
256
+ export function AlarmScreen() {
257
+ const [alarms, setAlarms] = useState([]);
258
+ const [permissions, setPermissions] = useState(null);
259
+
260
+ useEffect(() => {
261
+ initializeAlarms();
262
+ }, []);
263
+
264
+ const initializeAlarms = async () => {
265
+ const perms = await AlarmService.checkPermission();
266
+ setPermissions(perms);
267
+
268
+ if (perms.status !== 'granted') {
269
+ await AlarmService.requestPermission();
270
+ }
271
+
272
+ const allAlarms = await AlarmService.getAllAlarms();
273
+ setAlarms(allAlarms);
274
+
275
+ const unsubFired = AlarmService.onAlarmFired((alarm) => {
276
+ console.log('🔔 Alarm fired:', alarm.title);
277
+ });
278
+
279
+ const unsubSnoozed = AlarmService.onAlarmSnoozed((alarm) => {
280
+ console.log('😴 Alarm snoozed:', alarm.title);
281
+ });
282
+
283
+ return () => {
284
+ unsubFired();
285
+ unsubSnoozed();
286
+ };
287
+ };
288
+
289
+ const scheduleAlarm = async () => {
290
+ const alarmId = await AlarmService.scheduleAlarm({
291
+ timestamp: Date.now() + 5 * 60 * 1000,
292
+ title: 'Time for a break!',
293
+ body: 'Take a moment to rest',
294
+ vibrate: true,
295
+ snoozeEnabled: true,
296
+ snoozeMinutes: 5,
297
+ });
298
+
299
+ const updated = await AlarmService.getAllAlarms();
300
+ setAlarms(updated);
301
+ };
302
+
303
+ return (
304
+ <View style={styles.container}>
305
+ <Text style={styles.title}>Alarm Manager</Text>
306
+
307
+ <TouchableOpacity
308
+ style={styles.button}
309
+ onPress={scheduleAlarm}
310
+ >
311
+ <Text style={styles.buttonText}>Schedule Alarm</Text>
312
+ </TouchableOpacity>
313
+
314
+ <View style={styles.list}>
315
+ {alarms.map((alarm) => (
316
+ <View key={alarm.alarmId} style={styles.alarmItem}>
317
+ <Text>{alarm.title}</Text>
318
+ <Text>{new Date(alarm.timestamp).toLocaleTimeString()}</Text>
319
+ </View>
320
+ ))}
321
+ </View>
322
+ </View>
323
+ );
324
+ }
325
+
326
+ const styles = StyleSheet.create({
327
+ container: { flex: 1, padding: 20 },
328
+ title: { fontSize: 24, fontWeight: 'bold', marginBottom: 20 },
329
+ button: { backgroundColor: '#007AFF', padding: 12, borderRadius: 8 },
330
+ buttonText: { color: '#fff', fontWeight: 'bold', textAlign: 'center' },
331
+ list: { marginTop: 20 },
332
+ alarmItem: { padding: 12, borderBottomWidth: 1, borderBottomColor: '#eee' },
333
+ });
334
+ ```
64
335
 
65
- ## Step 3: Modify your app
336
+ ## Troubleshooting
66
337
 
67
- Now that you have successfully run the app, let's make changes!
338
+ ### "Alarm Native module is not linked"
339
+ Ensure the native module is properly linked:
340
+ ```bash
341
+ cd ios && pod install && cd ..
342
+ ```
68
343
 
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).
344
+ ### Alarms not triggering
345
+ 1. Check permissions: `await AlarmService.checkPermission()`
346
+ 2. Ensure app has necessary permissions:
347
+ - Android: `SCHEDULE_EXACT_ALARM`, `POST_NOTIFICATIONS`
348
+ - iOS: Allow notifications in Settings
70
349
 
71
- When you want to forcefully reload, for example to reset the state of your app, you can perform a full reload:
350
+ ### iOS-specific: Notifications instead of full-screen alarm
351
+ - Full-screen alarms (AlarmKit) require iOS 26+
352
+ - Older devices use local notifications
353
+ - Check `permission.backend` to see which is active
72
354
 
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.
355
+ ### Android-specific: Alarm doesn't ring when app is killed
356
+ - Enable Autostart permissions on device
357
+ - Check device's battery optimization settings
358
+ - Some OEMs require manual approval in their app management screens
75
359
 
76
- ## Congratulations! :tada:
360
+ ## Contributing
77
361
 
78
- You've successfully run and modified your React Native App. :partying_face:
362
+ Contributions are welcome! Please feel free to submit a Pull Request.
79
363
 
80
- ### Now what?
364
+ ## License
81
365
 
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).
366
+ MIT © 2024 Suraj Prasad
84
367
 
85
- # Troubleshooting
368
+ ## Support
86
369
 
87
- If you're having issues getting the above steps to work, see the [Troubleshooting](https://reactnative.dev/docs/troubleshooting) page.
370
+ For issues and questions, please visit:
371
+ - GitHub Issues: https://github.com/surajprasad13/react-native-alarms/issues
372
+ - Email: surajvishwakarma830@gmail.com
88
373
 
89
- # Learn More
374
+ ## Changelog
90
375
 
91
- To learn more about React Native, take a look at the following resources:
376
+ ### v0.1.0
377
+ - Improved TypeScript support with proper type exports
378
+ - Added AlarmService convenience class
379
+ - Comprehensive documentation
380
+ - Fixed module linking issues
92
381
 
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.
382
+ ### v0.0.1
383
+ - Initial release
384
+ - Cross-platform alarm scheduling
385
+ - Event-driven architecture
386
+ - Permission management
package/index.d.ts ADDED
@@ -0,0 +1,20 @@
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
+ } from './specs/NativeAlarm';
13
+
14
+ export type { Spec as AlarmModuleSpec } from './specs/NativeAlarm';
15
+
16
+ export { AlarmDemo } from './AlarmDemo';
17
+
18
+ // Default export for backward compatibility
19
+ import type NativeAlarm from './specs/NativeAlarm';
20
+ export default NativeAlarm;
package/index.ts ADDED
@@ -0,0 +1,21 @@
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
+ export { AlarmDemo } from './AlarmDemo';
18
+
19
+ // Default export for backward compatibility
20
+ import NativeAlarm from './specs/NativeAlarm';
21
+ export default NativeAlarm;
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.2",
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
- {}