|
1 | 1 | <a href="https://gauthamvijay.com"> |
2 | 2 | <picture> |
3 | | - <img alt="react-native-play-age-signals" src="./docs/img/banner.png" /> |
| 3 | + <img alt="react-native-play-age-range-declaration" src="./docs/img/banner.png" /> |
4 | 4 | </picture> |
5 | 5 | </a> |
6 | 6 |
|
7 | | -# react-native-play-age-signals |
| 7 | +# react-native-play-age-range-declaration |
8 | 8 |
|
9 | | -A **React Native TurboModule** that provides a bridge to the **Google Play Age Signals API**, enabling Android apps to query **user supervision and age verification status** when available via Play Services. |
| 9 | +A **React Native TurboModule** providing a unified API for **age-appropriate experiences** on mobile — bridging: |
10 | 10 |
|
11 | | -> [!IMPORTANT] |
12 | | -> |
13 | | -> - The Play Age Signals SDK (`com.google.android.play:age-signals`) is currently in **beta** and **not yet fully implemented** by Google. |
14 | | -> - Calling `checkAgeSignals()` will currently throw: java.lang.UnsupportedOperationException: Not yet implemented |
15 | | -> - This library is ready and production-safe — it will begin returning real data **automatically** once Google enables the API in upcoming Play Services updates. |
| 11 | +* 🟢 **Google Play Age Signals API** (Android) |
| 12 | +* 🔵 **Apple Declared Age Range API** (iOS 26+) |
16 | 13 |
|
17 | 14 | --- |
18 | 15 |
|
19 | 16 | ## 📦 Installation |
20 | 17 |
|
21 | | -```tsx |
22 | | -npm install react-native-play-age-signals |
| 18 | +```bash |
| 19 | +npm install react-native-play-age-range-declaration |
23 | 20 | ``` |
24 | 21 |
|
25 | 22 | ### 🚀 Zero Config Setup |
26 | 23 |
|
27 | | -- **No manual native setup required.** |
28 | | - This library uses **React Native TurboModules**, so it works out of the box with autolinking — even inside **Expo apps (custom dev clients)**. |
| 24 | +* ✅ **Autolinking supported** (no manual native setup) |
| 25 | +* ✅ Works with **React Native New Architecture (TurboModules)** |
| 26 | +* ✅ Compatible with **Expo custom dev clients** |
29 | 27 |
|
30 | 28 | --- |
31 | 29 |
|
32 | | -## 🔗 Reference Links |
| 30 | +## 🧠 Overview |
33 | 31 |
|
34 | | -- 📘 Google Developer Docs: [Play Age Signals](https://developer.android.com/google/play/age-signals/use-age-signals-api) |
35 | | -- 🧾 Google Support: [Age-Appropriate Ads Requirements](https://support.google.com/googleplay/android-developer/answer/16569691) |
| 32 | +| Platform | API Used | Purpose | |
| 33 | +| ----------- | ------------------------------------------------------------ | -------------------------------------------------- | |
| 34 | +| **Android** | Play Age Signals API (`com.google.android.play:age-signals`) | Detect user supervision / verified status | |
| 35 | +| **iOS** | Declared Age Range API (`AgeRangeService.requestAgeRange`) | Get user’s declared age range (e.g., 13-15, 16-17) | |
36 | 36 |
|
37 | 37 | --- |
38 | 38 |
|
39 | | -## 🇺🇸 Why this library exists |
40 | | - |
41 | | -This module was built for **production use** in my work app (US-based), where new **state-level legislation** requires mobile apps to verify the user’s age before displaying certain content or ads. |
42 | | - |
43 | | -To help other developers comply with these same laws, I’ve **open-sourced** it here. |
| 39 | +## ⚙️ Usage |
44 | 40 |
|
45 | | -> The **Google Play Age Signals API** will be the official, privacy-safe method to determine user supervision and age verification status across Android devices in the United States. |
| 41 | +```tsx |
| 42 | +import { getAgeData } from 'react-native-play-age-range-declaration'; |
| 43 | +import { useEffect } from 'react'; |
| 44 | +import { Text, View } from 'react-native'; |
46 | 45 |
|
47 | | ---- |
| 46 | +export default function App() { |
| 47 | + useEffect(() => { |
| 48 | + (async () => { |
| 49 | + try { |
| 50 | + const result = await getAgeData([13, 16, 18]); // iOS uses gates, Android ignores |
| 51 | + console.log('Age Signals:', result); |
| 52 | + } catch (err) { |
| 53 | + console.error('Failed to fetch Age Signals:', err); |
| 54 | + } |
| 55 | + })(); |
| 56 | + }, []); |
48 | 57 |
|
49 | | - <picture> |
50 | | - <img alt="Age Verification Bills in US States" src="./docs/img/bills-in-us.png" /> |
51 | | - </picture> |
| 58 | + return ( |
| 59 | + <View> |
| 60 | + <Text>Check console for Play Age / Declared Range output</Text> |
| 61 | + </View> |
| 62 | + ); |
| 63 | +} |
| 64 | +``` |
52 | 65 |
|
53 | 66 | --- |
54 | 67 |
|
55 | | -## 🧠 What It Does |
| 68 | +## 📱 Platform Outputs |
56 | 69 |
|
57 | | -Once the Play Services feature is live, the module will expose the following fields via `getPlayAgeSignals()`: |
| 70 | +### 🟢 **Android – Play Age Signals** |
58 | 71 |
|
59 | | -``` |
| 72 | +```json |
60 | 73 | { |
61 | | - installId: string | null; |
62 | | - userStatus: string | null; |
63 | | - error?: string | null; |
| 74 | + "installId": "abcd-1234-efgh-5678", |
| 75 | + "userStatus": "SUPERVISED" |
64 | 76 | } |
65 | 77 | ``` |
66 | 78 |
|
67 | | -Example (future API result): |
| 79 | +### 🔵 **iOS – Declared Age Range** |
68 | 80 |
|
69 | | -``` |
| 81 | +```json |
70 | 82 | { |
71 | | - "installId": "123e4567-e89b-12d3-a456-426614174000", |
72 | | - "userStatus": "VERIFIED" |
| 83 | + "status": "sharing", |
| 84 | + "lowerBound": 16, |
| 85 | + "upperBound": 17 |
73 | 86 | } |
74 | 87 | ``` |
75 | 88 |
|
76 | 89 | --- |
77 | 90 |
|
78 | | -## ⚙️ Usage |
| 91 | +## 🧩 API Reference |
79 | 92 |
|
80 | | -``` |
81 | | -import { getPlayAgeSignals } from 'react-native-play-age-signals'; |
82 | | -import { useEffect } from 'react'; |
83 | | -import { Text, View } from 'react-native'; |
| 93 | +### `getPlayAgeSignals(ageGates?: number[])` |
84 | 94 |
|
85 | | -export default function App() { |
86 | | - useEffect(() => { |
87 | | - const fetchSignals = async () => { |
88 | | - try { |
89 | | - const result = await getPlayAgeSignals(); |
90 | | - console.log('Play Age Signals:', result); |
91 | | - } catch (error) { |
92 | | - console.error('Failed to fetch Play Age Signals:', error); |
93 | | - } |
94 | | - }; |
| 95 | +**Returns:** `Promise<PlayAgeSignalsResult | DeclaredAgeRangeResult>` |
95 | 96 |
|
96 | | - fetchSignals(); |
97 | | - }, []); |
| 97 | +#### Android (`PlayAgeSignalsResult`) |
98 | 98 |
|
99 | | - return ( |
100 | | - <View> |
101 | | - <Text>Check your logs for Play Age Signals output</Text> |
102 | | - </View> |
103 | | - ); |
104 | | -} |
105 | | -``` |
| 99 | +| Field | Type | Description | | |
| 100 | +| ------------ | ------- | ----------- | ---------------------------------------- | |
| 101 | +| `installId` | `string | null` | Install-specific identifier | |
| 102 | +| `userStatus` | `string | null` | `"SUPERVISED"`, `"VERIFIED"`, or similar | |
| 103 | +| `error` | `string | null` | Error message if API unavailable | |
| 104 | + |
| 105 | +#### iOS (`DeclaredAgeRangeResult`) |
| 106 | + |
| 107 | +| Field | Type | Description | | |
| 108 | +| ------------ | -------------------------------- | ----------------------------------- | ---------------------------- | |
| 109 | +| `status` | `'sharing' \| 'declinedSharing'` | Whether the user shared their range | | |
| 110 | +| `lowerBound` | `number | null` | Minimum declared age | |
| 111 | +| `upperBound` | `number | null` | Maximum declared age | |
| 112 | +| `error` | `string | null` | Error message if unavailable | |
| 113 | + |
| 114 | +--- |
| 115 | + |
| 116 | +## 🧾 Real-World Use Case |
| 117 | + |
| 118 | +This module enables developers to comply with **state-level digital safety laws** and **age-appropriate content regulations** in the U.S. |
| 119 | + |
| 120 | +* Android → integrates with Play Age Signals (COPPA-compliant supervision data) |
| 121 | +* iOS → integrates with Declared Age Range API (WWDC 2025 privacy-preserving method) |
| 122 | + |
| 123 | +--- |
| 124 | + |
| 125 | +## 🔗 Reference Links |
| 126 | + |
| 127 | +* 📘 [Play Age Signals – Android Developers](https://developer.android.com/google/play/age-signals/use-age-signals-api) |
| 128 | +* 📘 [Declared Age Range – Apple Developer](https://developer.apple.com/documentation/declaredagerange) |
| 129 | +* 🧾 [U.S. Age Appropriate Design Laws (Overview)](https://support.google.com/googleplay/android-developer/answer/16569691) |
106 | 130 |
|
107 | 131 | --- |
108 | 132 |
|
109 | 133 | ## 🧩 Supported Platforms |
110 | 134 |
|
111 | | -| Platform | Status | |
112 | | -| --------------------------------- | ------------------------------------- | |
113 | | -| **Android** | ✅ Supported (pending SDK activation) | |
114 | | -| **iOS** | 🚫 Not applicable (returns `null`) | |
115 | | -| **Expo (Custom Dev Client)** | ✅ Works out of the box | |
116 | | -| **AOSP Emulator (no Play Store)** | ⚠️ Not supported | |
| 135 | +| Platform | Status | |
| 136 | +| ---------------------------- | -------------------------------------- | |
| 137 | +| **Android** | ✅ Supported (SDK in beta) | |
| 138 | +| **iOS 26+** | ✅ Supported (Declared Age Range) | |
| 139 | +| **Expo (Custom Dev Client)** | ✅ Works out-of-the-box | |
| 140 | +| **AOSP Emulator** | ⚠️ Not supported (requires Play Store) | |
117 | 141 |
|
118 | 142 | --- |
119 | 143 |
|
120 | | -## 🛠️ Under the Hood |
| 144 | +## 🧱 Under the Hood |
121 | 145 |
|
122 | | -This library uses: |
| 146 | +### Android |
123 | 147 |
|
124 | | -``` |
| 148 | +Implemented in Kotlin using: |
| 149 | + |
| 150 | +```kotlin |
125 | 151 | AgeSignalsManagerFactory.create(context) |
126 | 152 | .checkAgeSignals(AgeSignalsRequest.builder().build()) |
127 | 153 | ``` |
128 | 154 |
|
129 | | -to connect to the Play Services API through a native Kotlin TurboModule and forward results to JavaScript with full error propagation and stack traces. |
| 155 | +wrapped via a React Native TurboModule with full promise-based error handling. |
| 156 | + |
| 157 | +### iOS |
| 158 | + |
| 159 | +Implemented in Swift + Objective-C++ using: |
| 160 | + |
| 161 | +```swift |
| 162 | +try await AgeRangeService.requestAgeRange(ageGates: [13, 16, 18]) |
| 163 | +``` |
| 164 | + |
| 165 | +and bridged through `RCT_EXPORT_MODULE()`. |
130 | 166 |
|
131 | 167 | --- |
132 | 168 |
|
133 | 169 | ## 📅 Roadmap |
134 | 170 |
|
135 | | -- ✅ TurboModule bridge implementation |
136 | | -- ✅ Error handling with full Java → JS stack propagation |
137 | | -- 🚧 Awaiting Play Services rollout of working backend |
138 | | -- 🔔 Auto-watch for new SDK versions via Dependabot and GitHub Actions |
| 171 | +* ✅ TurboModule bridge implementation (Android + iOS) |
| 172 | +* ✅ iOS Declared Age Range integration |
| 173 | +* ✅ TypeScript + Fabric compatibility |
| 174 | +* 🚧 Awaiting full rollout of Google Play Age Signals API |
| 175 | +* 🔔 Auto-update support for new SDK versions via GitHub Actions |
139 | 176 |
|
140 | 177 | --- |
141 | 178 |
|
142 | 179 | ## 🤝 Contributing |
143 | 180 |
|
144 | | -Pull requests are welcome — especially once Google enables this API! |
| 181 | +Pull requests are welcome once both APIs are live! |
145 | 182 |
|
146 | | -- [Development workflow](CONTRIBUTING.md#development-workflow) |
147 | | -- [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request) |
148 | | -- [Code of conduct](CODE_OF_CONDUCT.md) |
| 183 | +* [Development Workflow](CONTRIBUTING.md#development-workflow) |
| 184 | +* [Sending a PR](CONTRIBUTING.md#sending-a-pull-request) |
| 185 | +* [Code of Conduct](CODE_OF_CONDUCT.md) |
149 | 186 |
|
150 | 187 | --- |
151 | 188 |
|
152 | 189 | ## 🪪 License |
153 | 190 |
|
154 | | -MIT © [Gautham Vijayan](https://gauthamvijay.com) |
| 191 | +MIT © [**Gautham Vijayan**](https://gauthamvijay.com) |
155 | 192 |
|
156 | 193 | --- |
157 | 194 |
|
158 | | -Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob) |
| 195 | +Made with [**create-react-native-library**](https://github.com/callstack/react-native-builder-bob) |
159 | 196 |
|
160 | 197 | --- |
0 commit comments