Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions examples/RNOneSignalTS/OSConsole.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@
*/

import React, { useCallback, useRef } from 'react';
import {
Platform,
SafeAreaView,
ScrollView,
StyleSheet,
Text,
View,
} from 'react-native';
import { Platform, ScrollView, StyleSheet, Text, View } from 'react-native';

export interface Props {
value: string;
Expand All @@ -30,10 +23,11 @@ const OSConsole: React.FC<Props> = ({ value }) => {
}, []);

return (
<SafeAreaView style={styles.body}>
<View style={styles.body}>
<ScrollView
nestedScrollEnabled={true}
style={styles.scrollView}
contentContainerStyle={styles.scrollViewContent}
ref={scrollViewRef}
onContentSizeChange={scrollToEnd}
>
Expand All @@ -47,19 +41,21 @@ const OSConsole: React.FC<Props> = ({ value }) => {
</Text>
</View>
</ScrollView>
</SafeAreaView>
</View>
);
};

const styles = StyleSheet.create({
scrollView: {
flex: 1,
backgroundColor: '#f8f9fa',
},
scrollViewContent: {
flexGrow: 1,
},
body: {
backgroundColor: 'grey',
backgroundColor: '#f8f9fa',
flex: 1,
flexGrow: 1,
flexDirection: 'row',
},
console: {
flexWrap: 'wrap',
Expand All @@ -71,11 +67,13 @@ const styles = StyleSheet.create({
flex: 1,
flexWrap: 'wrap',
fontSize: 10,
color: '#000',
},
textAndroid: {
flex: 1,
flexWrap: 'wrap',
fontSize: 10,
color: '#000',
},
});

Expand Down
39 changes: 31 additions & 8 deletions examples/RNOneSignalTS/OSDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { useFocusEffect } from '@react-navigation/native';
import React, { useCallback, useEffect, useState } from 'react';
import {
Alert,
SafeAreaView,
ScrollView,
StyleSheet,
Text,
TextInput,
TouchableOpacity,
View,
} from 'react-native';
import { LogLevel, OneSignal } from 'react-native-onesignal';
import { renderButtonView } from './Helpers';
import { SafeAreaView } from 'react-native-safe-area-context';
import OSButtons from './OSButtons';
import OSConsole from './OSConsole';

Expand Down Expand Up @@ -233,14 +233,19 @@ const OSDemo: React.FC = () => {
}, []);

return (
<SafeAreaView style={styles.container}>
<SafeAreaView style={styles.container} edges={['bottom', 'left', 'right']}>
<View style={styles.header}>
<Text style={styles.title}>OneSignal</Text>
<OSConsole value={consoleValue} />
<View style={styles.clearButton}>
{renderButtonView('X', () => {
setConsoleValue('');
})}
<TouchableOpacity
style={styles.clearButtonTouchable}
onPress={() => {
setConsoleValue('');
}}
>
<Text style={styles.clearButtonText}>X</Text>
</TouchableOpacity>
</View>
<TextInput
style={styles.input}
Expand Down Expand Up @@ -273,12 +278,30 @@ const styles = StyleSheet.create({
title: {
fontSize: 40,
alignSelf: 'center',
paddingVertical: 10,
paddingTop: 4,
paddingBottom: 10,
},
clearButton: {
position: 'absolute',
right: 0,
right: 10,
top: 70,
width: 44,
height: 44,
alignItems: 'center',
justifyContent: 'center',
},
clearButtonTouchable: {
width: 44,
height: 44,
backgroundColor: '#007bff',
borderRadius: 8,
alignItems: 'center',
justifyContent: 'center',
},
clearButtonText: {
color: 'white',
fontSize: 18,
fontWeight: '600',
},
input: {
marginTop: 10,
Expand Down
2 changes: 2 additions & 0 deletions examples/RNOneSignalTS/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
This is a new [**React Native**](https://reactnative.dev) project, bootstrapped using [`@react-native-community/cli`](https://github.com/react-native-community/cli).

NOTE: DO NOT USE iOS26 + iPhone17 FOR SIMULATORS. This will not subscribe properly.

# Getting Started

> **Note**: Make sure you have completed the [Set Up Your Environment](https://reactnative.dev/docs/set-up-your-environment) guide before proceeding.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.usernotifications.service</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).NotificationService</string>
</dict>
<key>RCTNewArchEnabled</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import UserNotifications
import OneSignalExtension

class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var receivedRequest: UNNotificationRequest!
var bestAttemptContent: UNMutableNotificationContent?

// Note this extension only runs when `mutable_content` is set
// Setting an attachment or action buttons automatically sets the property to true
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.receivedRequest = request
self.contentHandler = contentHandler
self.bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

if let bestAttemptContent = bestAttemptContent {
// DEBUGGING: Uncomment the 2 lines below to check this extension is executing
// print("Running NotificationServiceExtension")
// bestAttemptContent.body = "[Modified] " + bestAttemptContent.body

OneSignalExtension.didReceiveNotificationExtensionRequest(self.receivedRequest, with: bestAttemptContent, withContentHandler: self.contentHandler)
}
}

override func serviceExtensionTimeWillExpire() {
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
OneSignalExtension.serviceExtensionTimeWillExpireRequest(self.receivedRequest, with: self.bestAttemptContent)
contentHandler(bestAttemptContent)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.onesignal.example.onesignal</string>
</array>
</dict>
</plist>
4 changes: 4 additions & 0 deletions examples/RNOneSignalTS/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ target 'RNOneSignalTS' do
)
end
end

target 'OneSignalNotificationServiceExtension' do
pod 'OneSignalXCFramework', '>= 5.0.0', '< 6.0'
end
3 changes: 2 additions & 1 deletion examples/RNOneSignalTS/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2527,6 +2527,7 @@ DEPENDENCIES:
- fmt (from `../node_modules/react-native/third-party-podspecs/fmt.podspec`)
- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
- hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`)
- OneSignalXCFramework (< 6.0, >= 5.0.0)
- RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`)
- RCTDeprecation (from `../node_modules/react-native/ReactApple/Libraries/RCTFoundation/RCTDeprecation`)
- RCTRequired (from `../node_modules/react-native/Libraries/Required`)
Expand Down Expand Up @@ -2839,6 +2840,6 @@ SPEC CHECKSUMS:
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Yoga: 689c8e04277f3ad631e60fe2a08e41d411daf8eb

PODFILE CHECKSUM: 55f78c40d4a0661b8ccbf5604f1cf5b702ca4ea4
PODFILE CHECKSUM: 6ac3d17bc5c92580526c5376b6d35aacda108018

COCOAPODS: 1.16.2
Loading
Loading