diff --git a/.gitignore b/.gitignore index 67f3212..b406a51 100644 --- a/.gitignore +++ b/.gitignore @@ -84,3 +84,6 @@ android/generated # React Native Nitro Modules nitrogen/ + +# Push relay credentials (real-device APNs — never commit) +.env.push diff --git a/example/.maestro/background_notification.yaml b/example/.maestro/background_notification.yaml new file mode 100644 index 0000000..ee2aba7 --- /dev/null +++ b/example/.maestro/background_notification.yaml @@ -0,0 +1,37 @@ +appId: nitronotification.example +--- +- launchApp: + clearState: false + +- extendedWaitUntil: + visible: + text: Nitro Notifications + timeout: 10000 + +- pressKey: Home + +- evalScript: ${new Promise(r => setTimeout(r, 1500))} + +- runScript: + file: send_push.js + env: + PUSH_TITLE: Background Test + PUSH_BODY: Tap to open the app + +- extendedWaitUntil: + visible: + text: Background Test + timeout: 8000 + +- tapOn: + text: Background Test + +- extendedWaitUntil: + visible: + id: last-event-text + timeout: 8000 + +- extendedWaitUntil: + visible: + text: 'Tapped: Background Test (com.apple.UNNotificationDefaultActionIdentifier)' + timeout: 8000 diff --git a/example/.maestro/foreground_notification.yaml b/example/.maestro/foreground_notification.yaml new file mode 100644 index 0000000..fc7d96e --- /dev/null +++ b/example/.maestro/foreground_notification.yaml @@ -0,0 +1,25 @@ +appId: nitronotification.example +--- +- launchApp: + clearState: false + +- extendedWaitUntil: + visible: + text: Nitro Notifications + timeout: 10000 + +- runScript: + file: send_push.js + env: + PUSH_TITLE: Foreground Test + PUSH_BODY: Notification received in foreground + +- extendedWaitUntil: + visible: + id: last-event-text + timeout: 8000 + +- extendedWaitUntil: + visible: + text: "Received: Foreground Test — Notification received in foreground" + timeout: 8000 diff --git a/example/.maestro/send_push.js b/example/.maestro/send_push.js new file mode 100644 index 0000000..08b8fd7 --- /dev/null +++ b/example/.maestro/send_push.js @@ -0,0 +1,10 @@ +// Maestro runScript helper - calls local push-relay +const title = typeof PUSH_TITLE !== 'undefined' ? PUSH_TITLE : 'Test'; +const body = typeof PUSH_BODY !== 'undefined' ? PUSH_BODY : 'Test body'; +const port = typeof PUSH_RELAY_PORT !== 'undefined' ? PUSH_RELAY_PORT : '8765'; +const payload = JSON.stringify({ title, body }); + +output.result = http.post(`http://127.0.0.1:${port}/push`, { + headers: { 'Content-Type': 'application/json' }, + body: payload, +}); diff --git a/example/src/App.tsx b/example/src/App.tsx index ccb64e7..c51d963 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -40,19 +40,6 @@ export default function App() { }); }; - useEffect(() => { - (async () => { - const status = await Notifications.getPermissionStatus(); - setPermStatus(status); - if (status === 'granted') { - setupNotifications(); - const t = await Notifications.getDevicePushToken(); - setToken(t); - api.login(t); - } - })(); - }, []); - const handleRequestPermissions = async () => { const status = await Notifications.requestPermissions(); setPermStatus(status); @@ -121,6 +108,19 @@ export default function App() { Alert.alert('Copied'); }; + useEffect(() => { + (async () => { + const status = await Notifications.getPermissionStatus(); + setPermStatus(status); + if (status === 'granted') { + setupNotifications(); + const t = await Notifications.getDevicePushToken(); + setToken(t); + api.login(t); + } + })(); + }, []); + return ( Nitro Notifications @@ -151,7 +151,9 @@ export default function App() {