Skip to content

Commit a6cea10

Browse files
authored
chore: fix ios side for example project (#1877)
1 parent 2beb506 commit a6cea10

File tree

12 files changed

+358
-24
lines changed

12 files changed

+358
-24
lines changed

examples/RNOneSignalTS/OSConsole.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,7 @@
99
*/
1010

1111
import React, { useCallback, useRef } from 'react';
12-
import {
13-
Platform,
14-
SafeAreaView,
15-
ScrollView,
16-
StyleSheet,
17-
Text,
18-
View,
19-
} from 'react-native';
12+
import { Platform, ScrollView, StyleSheet, Text, View } from 'react-native';
2013

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

3225
return (
33-
<SafeAreaView style={styles.body}>
26+
<View style={styles.body}>
3427
<ScrollView
3528
nestedScrollEnabled={true}
3629
style={styles.scrollView}
30+
contentContainerStyle={styles.scrollViewContent}
3731
ref={scrollViewRef}
3832
onContentSizeChange={scrollToEnd}
3933
>
@@ -47,19 +41,21 @@ const OSConsole: React.FC<Props> = ({ value }) => {
4741
</Text>
4842
</View>
4943
</ScrollView>
50-
</SafeAreaView>
44+
</View>
5145
);
5246
};
5347

5448
const styles = StyleSheet.create({
5549
scrollView: {
50+
flex: 1,
5651
backgroundColor: '#f8f9fa',
5752
},
53+
scrollViewContent: {
54+
flexGrow: 1,
55+
},
5856
body: {
59-
backgroundColor: 'grey',
57+
backgroundColor: '#f8f9fa',
6058
flex: 1,
61-
flexGrow: 1,
62-
flexDirection: 'row',
6359
},
6460
console: {
6561
flexWrap: 'wrap',
@@ -71,11 +67,13 @@ const styles = StyleSheet.create({
7167
flex: 1,
7268
flexWrap: 'wrap',
7369
fontSize: 10,
70+
color: '#000',
7471
},
7572
textAndroid: {
7673
flex: 1,
7774
flexWrap: 'wrap',
7875
fontSize: 10,
76+
color: '#000',
7977
},
8078
});
8179

examples/RNOneSignalTS/OSDemo.tsx

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { useFocusEffect } from '@react-navigation/native';
22
import React, { useCallback, useEffect, useState } from 'react';
33
import {
44
Alert,
5-
SafeAreaView,
65
ScrollView,
76
StyleSheet,
87
Text,
98
TextInput,
9+
TouchableOpacity,
1010
View,
1111
} from 'react-native';
1212
import { LogLevel, OneSignal } from 'react-native-onesignal';
13-
import { renderButtonView } from './Helpers';
13+
import { SafeAreaView } from 'react-native-safe-area-context';
1414
import OSButtons from './OSButtons';
1515
import OSConsole from './OSConsole';
1616

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

235235
return (
236-
<SafeAreaView style={styles.container}>
236+
<SafeAreaView style={styles.container} edges={['bottom', 'left', 'right']}>
237237
<View style={styles.header}>
238238
<Text style={styles.title}>OneSignal</Text>
239239
<OSConsole value={consoleValue} />
240240
<View style={styles.clearButton}>
241-
{renderButtonView('X', () => {
242-
setConsoleValue('');
243-
})}
241+
<TouchableOpacity
242+
style={styles.clearButtonTouchable}
243+
onPress={() => {
244+
setConsoleValue('');
245+
}}
246+
>
247+
<Text style={styles.clearButtonText}>X</Text>
248+
</TouchableOpacity>
244249
</View>
245250
<TextInput
246251
style={styles.input}
@@ -273,12 +278,30 @@ const styles = StyleSheet.create({
273278
title: {
274279
fontSize: 40,
275280
alignSelf: 'center',
276-
paddingVertical: 10,
281+
paddingTop: 4,
282+
paddingBottom: 10,
277283
},
278284
clearButton: {
279285
position: 'absolute',
280-
right: 0,
286+
right: 10,
281287
top: 70,
288+
width: 44,
289+
height: 44,
290+
alignItems: 'center',
291+
justifyContent: 'center',
292+
},
293+
clearButtonTouchable: {
294+
width: 44,
295+
height: 44,
296+
backgroundColor: '#007bff',
297+
borderRadius: 8,
298+
alignItems: 'center',
299+
justifyContent: 'center',
300+
},
301+
clearButtonText: {
302+
color: 'white',
303+
fontSize: 18,
304+
fontWeight: '600',
282305
},
283306
input: {
284307
marginTop: 10,

examples/RNOneSignalTS/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
This is a new [**React Native**](https://reactnative.dev) project, bootstrapped using [`@react-native-community/cli`](https://github.com/react-native-community/cli).
22

3+
NOTE: DO NOT USE iOS26 + iPhone17 FOR SIMULATORS. This will not subscribe properly.
4+
35
# Getting Started
46

57
> **Note**: Make sure you have completed the [Set Up Your Environment](https://reactnative.dev/docs/set-up-your-environment) guide before proceeding.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>NSExtension</key>
6+
<dict>
7+
<key>NSExtensionPointIdentifier</key>
8+
<string>com.apple.usernotifications.service</string>
9+
<key>NSExtensionPrincipalClass</key>
10+
<string>$(PRODUCT_MODULE_NAME).NotificationService</string>
11+
</dict>
12+
<key>RCTNewArchEnabled</key>
13+
<true/>
14+
</dict>
15+
</plist>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import UserNotifications
2+
import OneSignalExtension
3+
4+
class NotificationService: UNNotificationServiceExtension {
5+
var contentHandler: ((UNNotificationContent) -> Void)?
6+
var receivedRequest: UNNotificationRequest!
7+
var bestAttemptContent: UNMutableNotificationContent?
8+
9+
// Note this extension only runs when `mutable_content` is set
10+
// Setting an attachment or action buttons automatically sets the property to true
11+
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
12+
self.receivedRequest = request
13+
self.contentHandler = contentHandler
14+
self.bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
15+
16+
if let bestAttemptContent = bestAttemptContent {
17+
// DEBUGGING: Uncomment the 2 lines below to check this extension is executing
18+
// print("Running NotificationServiceExtension")
19+
// bestAttemptContent.body = "[Modified] " + bestAttemptContent.body
20+
21+
OneSignalExtension.didReceiveNotificationExtensionRequest(self.receivedRequest, with: bestAttemptContent, withContentHandler: self.contentHandler)
22+
}
23+
}
24+
25+
override func serviceExtensionTimeWillExpire() {
26+
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
27+
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
28+
OneSignalExtension.serviceExtensionTimeWillExpireRequest(self.receivedRequest, with: self.bestAttemptContent)
29+
contentHandler(bestAttemptContent)
30+
}
31+
}
32+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.application-groups</key>
6+
<array>
7+
<string>group.com.onesignal.example.onesignal</string>
8+
</array>
9+
</dict>
10+
</plist>

examples/RNOneSignalTS/ios/Podfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ target 'RNOneSignalTS' do
3333
)
3434
end
3535
end
36+
37+
target 'OneSignalNotificationServiceExtension' do
38+
pod 'OneSignalXCFramework', '>= 5.0.0', '< 6.0'
39+
end

examples/RNOneSignalTS/ios/Podfile.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2527,6 +2527,7 @@ DEPENDENCIES:
25272527
- fmt (from `../node_modules/react-native/third-party-podspecs/fmt.podspec`)
25282528
- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
25292529
- hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`)
2530+
- OneSignalXCFramework (< 6.0, >= 5.0.0)
25302531
- RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`)
25312532
- RCTDeprecation (from `../node_modules/react-native/ReactApple/Libraries/RCTFoundation/RCTDeprecation`)
25322533
- RCTRequired (from `../node_modules/react-native/Libraries/Required`)
@@ -2839,6 +2840,6 @@ SPEC CHECKSUMS:
28392840
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
28402841
Yoga: 689c8e04277f3ad631e60fe2a08e41d411daf8eb
28412842

2842-
PODFILE CHECKSUM: 55f78c40d4a0661b8ccbf5604f1cf5b702ca4ea4
2843+
PODFILE CHECKSUM: 6ac3d17bc5c92580526c5376b6d35aacda108018
28432844

28442845
COCOAPODS: 1.16.2

0 commit comments

Comments
 (0)