|
1 |
| -# react-native-activity-kit |
| 1 | +# @kingstinct/react-native-activity-kit |
2 | 2 |
|
3 |
| -To install dependencies: |
| 3 | +A powerful React Native library for iOS Live Activities using ActivityKit, built with Nitro Modules for optimal performance. |
| 4 | + |
| 5 | +## 📱 Features |
| 6 | + |
| 7 | +- **iOS Live Activities**: Create and manage live activities that appear on the lock screen and Dynamic Island |
| 8 | +- **Real-time Updates**: Update activity content in real-time with push notifications or local updates |
| 9 | +- **TypeScript Support**: Fully typed API for enhanced developer experience |
| 10 | +- **Nitro Modules**: Built on Nitro for high-performance native interactions |
| 11 | +- **Expo Compatible**: Easy integration with Expo projects via plugin |
| 12 | + |
| 13 | +## 🚀 Installation |
| 14 | + |
| 15 | +```bash |
| 16 | +# npm |
| 17 | +npm install @kingstinct/react-native-activity-kit |
| 18 | + |
| 19 | +# yarn |
| 20 | +yarn add @kingstinct/react-native-activity-kit |
| 21 | + |
| 22 | +# bun |
| 23 | +bun install @kingstinct/react-native-activity-kit |
| 24 | +``` |
| 25 | + |
| 26 | +## ⚙️ Configuration |
| 27 | + |
| 28 | +### Expo Setup |
| 29 | + |
| 30 | +Add the plugin to your `app.json` or `app.config.js`: |
| 31 | + |
| 32 | +```json |
| 33 | +{ |
| 34 | + "expo": { |
| 35 | + "plugins": [ |
| 36 | + "@kingstinct/react-native-activity-kit" |
| 37 | + ] |
| 38 | + } |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +The plugin automatically enables Live Activities support in your iOS Info.plist. |
| 43 | + |
| 44 | +### Manual Setup |
| 45 | + |
| 46 | +For non-Expo projects, add this to your iOS `Info.plist`: |
| 47 | + |
| 48 | +```xml |
| 49 | +<key>NSSupportsLiveActivities</key> |
| 50 | +<true/> |
| 51 | +``` |
| 52 | + |
| 53 | +## 📖 Usage |
| 54 | + |
| 55 | +```typescript |
| 56 | +import { ActivityKit } from '@kingstinct/react-native-activity-kit'; |
| 57 | + |
| 58 | +// Check if Live Activities are available |
| 59 | +if (ActivityKit.isAvailable) { |
| 60 | + // Start a new activity |
| 61 | + const activity = ActivityKit.startActivity( |
| 62 | + // Attributes (static data) |
| 63 | + { |
| 64 | + title: "Pizza Order", |
| 65 | + orderId: "12345" |
| 66 | + }, |
| 67 | + // State (dynamic data) |
| 68 | + { |
| 69 | + status: "preparing", |
| 70 | + estimatedTime: 15 |
| 71 | + }, |
| 72 | + // Options |
| 73 | + { |
| 74 | + staleDate: new Date(Date.now() + 30 * 60 * 1000), // 30 minutes |
| 75 | + relevanceScore: 0.8 |
| 76 | + } |
| 77 | + ); |
| 78 | + |
| 79 | + // Update the activity |
| 80 | + activity.update({ |
| 81 | + status: "ready", |
| 82 | + estimatedTime: 0 |
| 83 | + }); |
| 84 | + |
| 85 | + // End the activity |
| 86 | + activity.end({ |
| 87 | + status: "completed" |
| 88 | + }); |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +### Listening to Updates |
| 93 | + |
| 94 | +```typescript |
| 95 | +// Subscribe to activity updates |
| 96 | +ActivityKit.subscribeToActivityUpdates((activity) => { |
| 97 | + console.log('Activity updated:', activity.id, activity.activityState); |
| 98 | +}); |
| 99 | + |
| 100 | +// Subscribe to enablement changes |
| 101 | +ActivityKit.subscribeToActivityEnablementUpdates((enabled) => { |
| 102 | + console.log('Live Activities enabled:', enabled); |
| 103 | +}); |
| 104 | +``` |
| 105 | + |
| 106 | +## 🏗️ Development |
| 107 | + |
| 108 | +This is a monorepo containing: |
| 109 | + |
| 110 | +- `packages/react-native-activity-kit/`: The main library |
| 111 | +- `apps/activity-kit-example/`: Example Expo app demonstrating usage |
| 112 | + |
| 113 | +### Setup |
4 | 114 |
|
5 | 115 | ```bash
|
6 | 116 | bun install
|
7 | 117 | ```
|
8 | 118 |
|
9 |
| -To run: |
| 119 | +### Development Commands |
10 | 120 |
|
11 | 121 | ```bash
|
12 |
| -bun run index.ts |
| 122 | +# Build the library |
| 123 | +bun run codegen |
| 124 | + |
| 125 | +# Lint code |
| 126 | +bun run lint |
| 127 | + |
| 128 | +# Type checking |
| 129 | +bun run typecheck |
| 130 | + |
| 131 | +# Clean build artifacts |
| 132 | +bun run clean:node_modules |
| 133 | + |
| 134 | +# Create a changeset for versioning |
| 135 | +bun run create-changeset |
13 | 136 | ```
|
14 | 137 |
|
15 |
| -This project was created using `bun init` in bun v1.2.19. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime. |
| 138 | +## 🛠️ Architecture |
| 139 | + |
| 140 | +Built on [Nitro Modules](https://github.com/mrousavy/nitro) for: |
| 141 | +- **High Performance**: Direct Swift/Kotlin bindings |
| 142 | +- **Type Safety**: Full TypeScript support |
| 143 | +- **Modern Architecture**: Uses the latest React Native architecture |
| 144 | + |
| 145 | +## 📱 Platform Support |
| 146 | + |
| 147 | +- ✅ iOS 16.1+ (Live Activities requirement) |
| 148 | +- ❌ Android (Live Activities are iOS-only) |
| 149 | + |
| 150 | +## 🤝 Contributing |
| 151 | + |
| 152 | +1. Fork the repository |
| 153 | +2. Create your feature branch (`git checkout -b feature/amazing-feature`) |
| 154 | +3. Make your changes |
| 155 | +4. Run tests and linting (`bun run lint && bun run typecheck`) |
| 156 | +5. Commit your changes (`git commit -m 'Add amazing feature'`) |
| 157 | +6. Push to the branch (`git push origin feature/amazing-feature`) |
| 158 | +7. Open a Pull Request |
| 159 | + |
| 160 | +## 📄 License |
| 161 | + |
| 162 | +MIT License - see [LICENSE](LICENSE) for details. |
| 163 | + |
| 164 | +## 🔗 Links |
| 165 | + |
| 166 | +- [GitHub Repository](https://github.com/kingstinct/react-native-activity-kit) |
| 167 | +- [npm Package](https://www.npmjs.com/package/@kingstinct/react-native-activity-kit) |
| 168 | +- [iOS ActivityKit Documentation](https://developer.apple.com/documentation/activitykit) |
0 commit comments