Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[User Model] Rename Events & API Changes #1524

Merged
merged 30 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
baa44cb
Bump native version dependencies
jennantilla Jun 2, 2023
c41fac9
Move Live Activities to its own namespace
jennantilla Jun 2, 2023
7b22049
Update privacy consent API names and remove public getters
jennantilla Jun 2, 2023
a69677e
Update InAppMessages event model & interfaces
jennantilla Jun 9, 2023
1800f4a
Update InAppMessages with addEventListener method for click & lifecyc…
jennantilla Jun 9, 2023
6aaa6d9
Add capability to add & remove multiple InAppMessage listeners
jennantilla Jun 9, 2023
a2dcbfd
Update inAppMessages API for iOS
jennantilla Jun 9, 2023
aedbe62
Update InAppMessages API for Android
jennantilla Jun 9, 2023
fc6f4d2
InAppMessages addTrigger(s) now only accepts String values
jennantilla Jun 9, 2023
71d691d
Fix spelling for convertReadable methods
jennantilla Jun 9, 2023
3dad4a4
Update demo app InAppMessages methods
jennantilla Jun 9, 2023
8962cdb
Update example app logging for InAppMessages events
jennantilla Jun 14, 2023
9d15328
Update Notifications API, models, and interfaces
jennantilla Jun 14, 2023
183be87
Add capability to add & remove multiple Notifications listeners
jennantilla Jun 14, 2023
8500e84
Update Notifications API for iOS
jennantilla Jun 14, 2023
24a69fa
Update Notifications API for Android
jennantilla Jun 14, 2023
d12c5ec
Clean up old imports and unused RNUtils methods on Android
jennantilla Jun 14, 2023
b44f51f
Update demo app Notifications methods
jennantilla Jun 14, 2023
7fca0a4
Update PushSubscription namespace
jennantilla Jun 14, 2023
5ee39b8
Update PushSubscription API on iOS
jennantilla Jun 14, 2023
80b4c8f
Update PushSubscription API on Android
jennantilla Jun 14, 2023
11e32de
Update demo app PushSubscription method
jennantilla Jun 14, 2023
fd0b83a
Update permission naming
jennantilla Jun 14, 2023
37b6055
Update permission API on iOS
jennantilla Jun 14, 2023
7f56b36
Update permission API on Android
jennantilla Jun 14, 2023
b8e2a7e
Update demo app permission method
jennantilla Jun 14, 2023
a787afd
Fix onNotificationPermissionDidChange on iOS
jennantilla Jun 15, 2023
9d9ea16
Add permissionNative for iOS
jennantilla Jun 15, 2023
15becb1
Update Migration Guide
jennantilla Jun 16, 2023
e20d6db
[Nit] Clean up extraneous tracked files
jennantilla Jul 13, 2023
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
147 changes: 78 additions & 69 deletions MIGRATION_GUIDE.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies {

// api is used instead of implementation so the parent :app project can access any of the OneSignal Java
// classes if needed. Such as com.onesignal.NotificationExtenderService
api 'com.onesignal:OneSignal:5.0.0-beta2'
api 'com.onesignal:OneSignal:5.0.0-beta4'

testImplementation 'junit:junit:4.12'
}
307 changes: 160 additions & 147 deletions android/src/main/java/com/geektime/rnonesignalandroid/RNOneSignal.java

Large diffs are not rendered by default.

49 changes: 13 additions & 36 deletions android/src/main/java/com/geektime/rnonesignalandroid/RNUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@
import com.facebook.react.bridge.WritableNativeArray;
import com.facebook.react.bridge.WritableNativeMap;

// import com.onesignal.OSInAppMessage;
import com.onesignal.inAppMessages.IInAppMessage;
import com.onesignal.inAppMessages.IInAppMessageClickResult;
import com.onesignal.inAppMessages.IInAppMessageWillDisplayEvent;
jennantilla marked this conversation as resolved.
Show resolved Hide resolved
import com.onesignal.inAppMessages.IInAppMessageDidDisplayEvent;
import com.onesignal.inAppMessages.IInAppMessageWillDismissEvent;
import com.onesignal.inAppMessages.IInAppMessageDidDismissEvent;
import com.onesignal.notifications.INotification;
import com.onesignal.notifications.INotificationAction;
import com.onesignal.notifications.INotificationClickResult;
import com.onesignal.notifications.INotificationReceivedEvent;
import com.onesignal.user.subscriptions.IPushSubscription;
import com.onesignal.user.subscriptions.ISubscription;
import com.onesignal.user.subscriptions.PushSubscriptionState;

import org.json.JSONArray;
import org.json.JSONException;
Expand Down Expand Up @@ -109,15 +111,6 @@ public static HashMap<String, Object> convertNotificationToMap(INotification not
return hash;
}

public static HashMap<String, Object> convertNotificationClickResultToMap(INotificationClickResult openResult) throws JSONException {
HashMap<String, Object> hash = new HashMap<>();

hash.put("notification", convertNotificationToMap(openResult.getNotification()));
hash.put("action", convertNotificationActionToMap(openResult.getAction()));

return hash;
}

public static HashMap<String, Object> convertInAppMessageToMap(IInAppMessage message) {
HashMap<String, Object> hash = new HashMap<>();

Expand All @@ -126,18 +119,18 @@ public static HashMap<String, Object> convertInAppMessageToMap(IInAppMessage mes
return hash;
}

public static HashMap<String, Object> convertInAppMessageClickedActionToMap(IInAppMessageClickResult result) {
public static HashMap<String, Object> convertInAppMessageClickResultToMap(IInAppMessageClickResult result) {
HashMap<String, Object> hash = new HashMap<>();

hash.put("clickName", result.getAction().getClickName());
hash.put("clickUrl", result.getAction().getClickUrl());
hash.put("firstClick", result.getAction().isFirstClick());
hash.put("closesMessage", result.getAction().getClosesMessage());
hash.put("actionId", result.getActionId());
hash.put("urlTarget", result.getUrlTarget());
hash.put("url", result.getUrl());
hash.put("closingMessage", result.getClosingMessage());

return hash;
}

public static HashMap<String, Object> convertOnSubscriptionChangedToMap(IPushSubscription state) {
public static HashMap<String, Object> convertOnSubscriptionChangedToMap(PushSubscriptionState state) {
HashMap<String, Object> hash = new HashMap<>();

hash.put("token", state.getToken());
Expand Down Expand Up @@ -175,7 +168,7 @@ public static HashMap<String, Object> convertJSONObjectToHashMap(JSONObject obje
return hash;
}

public static Collection<String> convertReableArrayIntoStringCollection(ReadableArray readableArray) {
public static Collection<String> convertReadableArrayIntoStringCollection(ReadableArray readableArray) {
ArrayList<String> strings = new ArrayList<>();
for (Object object : readableArray.toArrayList()) {
if (object instanceof String)
Expand All @@ -184,7 +177,7 @@ public static Collection<String> convertReableArrayIntoStringCollection(Readable
return strings;
}

public static HashMap<String, String> convertReableMapIntoStringMap(ReadableMap readableMap) {
public static HashMap<String, String> convertReadableMapIntoStringMap(ReadableMap readableMap) {
HashMap<String, String> stringMap = new HashMap<>();
ReadableMapKeySetIterator iter = readableMap.keySetIterator();

Expand All @@ -206,22 +199,6 @@ public static HashMap<String, Object> convertPermissionToMap(boolean granted) {
return hash;
}

private static HashMap<String, Object> convertNotificationActionToMap(INotificationAction action) {
HashMap<String, Object> hash = new HashMap<>();

hash.put("id", action.getActionId());

switch (action.getType()) {
case Opened:
hash.put("type", 0);
break;
case ActionTaken:
hash.put("type", 1);
}

return hash;
}

private static List<Object> convertJSONArrayToList(JSONArray array) throws JSONException {
List<Object> list = new ArrayList<>();

Expand Down
42 changes: 12 additions & 30 deletions examples/RNOneSignalTS/src/OSButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -420,61 +420,43 @@ class OSButtons extends React.Component<Props> {
privacyConsentFields() {
const {loggingFunction} = this.props;

const getPrivacyConsentButton = renderButtonView(
'Get Privacy Consent',
async () => {
const granted = await OneSignal.getPrivacyConsent();
loggingFunction('Privacy consent granted: ', granted);
}
);

const setPrivacyConsentTrueButton = renderButtonView(
const setPrivacyConsentGivenTrueButton = renderButtonView(
'Set Privacy Consent to true',
async () => {
await OneSignal.setPrivacyConsent(true);
await OneSignal.setConsentGiven(true);
loggingFunction('Privacy Consent set to true');
}
);

const setPrivacyConsentFalseButton = renderButtonView(
const setPrivacyConsentGivenFalseButton = renderButtonView(
'Set Privacy Consent to false',
async () => {
await OneSignal.setPrivacyConsent(false);
await OneSignal.setConsentGiven(false);
loggingFunction('Privacy Consent set to false');
}
);

const getRequiresPrivacyConsentButton = renderButtonView(
'Get Requires Privacy Consent',
async () => {
const granted = await OneSignal.getRequiresPrivacyConsent();
loggingFunction('Requires Privacy Consent: ', granted);
}
);

const setRequiresPrivacyConsentTrueButton = renderButtonView(
const setPrivacyConsentRequiredTrueButton = renderButtonView(
'Set Requiers Privacy Consent to true',
async () => {
await OneSignal.setRequiresPrivacyConsent(true);
await OneSignal.setConsentRequired(true);
loggingFunction('Requires Privacy Consent set to true');
}
);

const setRequiresPrivacyConsentFalseButton = renderButtonView(
const setPrivacyConsentRequiredFalseButton = renderButtonView(
'Set Requiers Privacy Consent to false',
async () => {
await OneSignal.setRequiresPrivacyConsent(false);
await OneSignal.setConsentRequired(false);
loggingFunction('Requires Privacy Consent set to false');
}
);

return [
getPrivacyConsentButton,
setPrivacyConsentTrueButton,
setPrivacyConsentFalseButton,
getRequiresPrivacyConsentButton,
setRequiresPrivacyConsentTrueButton,
setRequiresPrivacyConsentFalseButton,
setPrivacyConsentGivenTrueButton,
setPrivacyConsentGivenFalseButton,
setPrivacyConsentRequiredTrueButton,
setPrivacyConsentRequiredFalseButton,
];
}

Expand Down
53 changes: 27 additions & 26 deletions examples/RNOneSignalTS/src/OSDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,60 +33,61 @@ class OSDemo extends React.Component<Props, State> {
OneSignal.initialize(APP_ID);
OneSignal.Debug.setLogLevel(6);

OneSignal.Notifications.setNotificationWillShowInForegroundHandler(
(notifReceivedEvent) => {
this.OSLog('OneSignal: notification will show in foreground:', notifReceivedEvent);
const notification = notifReceivedEvent.getNotification();
OneSignal.Notifications.addEventListener('foregroundWillDisplay',
(event) => {
this.OSLog('OneSignal: notification will show in foreground:', event);
let notif = event.getNotification();

const cancelButton = {
text: 'Cancel',
onPress: () => {
notifReceivedEvent.complete();
event.preventDefault();
},
style: 'cancel',
};

const completeButton = {
text: 'Complete',
text: 'Display',
onPress: () => {
notifReceivedEvent.complete(notification);
event.getNotification().display();
},
};

Alert.alert('Complete notification?', notification.title, [cancelButton, completeButton], {
Alert.alert('Display notification?', notif.title, [cancelButton, completeButton], {
cancelable: true,
});
},
);

OneSignal.Notifications.setNotificationClickHandler((notification) => {
this.OSLog('OneSignal: notification opened:', notification);
OneSignal.Notifications.addEventListener('click', (event) => {
this.OSLog('OneSignal: notification clicked:', event);
});

OneSignal.InAppMessages.setClickHandler((event) => {
OneSignal.InAppMessages.addEventListener('click', (event) =>{
this.OSLog('OneSignal IAM clicked:', event);
});

OneSignal.InAppMessages.setLifecycleHandler({
onWillDisplayInAppMessage: (message) => {
this.OSLog('OneSignal: will display IAM: ', message.messageId);
},
onDidDisplayInAppMessage: (message) => {
this.OSLog('OneSignal: did display IAM: ', message.messageId);
},
onWillDismissInAppMessage: (message) => {
this.OSLog('OneSignal: will dismiss IAM: ', message.messageId);
},
onDidDismissInAppMessage: (message) => {
this.OSLog('OneSignal: did dismiss IAM: ', message.messageId);
},
OneSignal.InAppMessages.addEventListener('willDisplay', (event) =>{
this.OSLog('OneSignal: will display IAM: ', event);
});

OneSignal.InAppMessages.addEventListener('didDisplay', (event) =>{
this.OSLog('OneSignal: did display IAM: ', event);
});

OneSignal.InAppMessages.addEventListener('willDismiss', (event) =>{
this.OSLog('OneSignal: will dismiss IAM: ', event);
});

OneSignal.InAppMessages.addEventListener('didDismiss', (event) =>{
this.OSLog('OneSignal: did dismiss IAM: ', event);
});

OneSignal.User.PushSubscription.addChangeHandler((subscription) => {
OneSignal.User.PushSubscription.addObserver((subscription) => {
this.OSLog('OneSignal: subscription changed:', subscription);
});

OneSignal.Notifications.addPermissionChangedHandler((granted) => {
OneSignal.Notifications.addPermissionObserver((granted) => {
this.OSLog('OneSignal: permission changed:', granted.permission);
});
}
Expand Down
2 changes: 1 addition & 1 deletion ios/RCTOneSignal/RCTOneSignal.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#import "../OneSignalFramework.h"
#endif

@interface RCTOneSignal : NSObject <OSPushSubscriptionObserver, OSPermissionObserver, OSInAppMessageLifecycleHandler>
@interface RCTOneSignal : NSObject <OSPushSubscriptionObserver, OSNotificationPermissionObserver, OSInAppMessageLifecycleListener, OSInAppMessageClickListener>

+ (RCTOneSignal *) sharedInstance;

Expand Down
26 changes: 13 additions & 13 deletions ios/RCTOneSignal/RCTOneSignal.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ @implementation RCTOneSignal {
BOOL didInitialize;
}

OSNotificationOpenedResult* coldStartOSNotificationOpenedResult;
OSNotificationClickResult* coldStartOSNotificationClickResult;

+ (RCTOneSignal *) sharedInstance {
static dispatch_once_t token = 0;
Expand Down Expand Up @@ -74,28 +74,28 @@ - (void)sendEvent:(NSString *)eventName withBody:(NSDictionary *)body {
[RCTOneSignalEventEmitter sendEventWithName:eventName withBody:body];
}

- (void)onOSPushSubscriptionChangedWithStateChanges:(OSPushSubscriptionStateChanges * _Nonnull)stateChanges {
[self sendEvent:OSEventString(SubscriptionChanged) withBody:[stateChanges.to jsonRepresentation]];
- (void)onPushSubscriptionDidChangeWithState:(OSPushSubscriptionChangedState * _Nonnull)state {
jennantilla marked this conversation as resolved.
Show resolved Hide resolved
[self sendEvent:OSEventString(SubscriptionChanged) withBody:[state.current jsonRepresentation]];
}

- (void)onOSPermissionChanged:(OSPermissionState *)state {
[self sendEvent:OSEventString(PermissionChanged) withBody:[state jsonRepresentation]];
- (void)onNotificationPermissionDidChange:(BOOL)permission {
[self sendEvent:OSEventString(PermissionChanged) withBody:@{@"permission": @(permission)}];
}

- (void)onWillDisplayInAppMessage:(OSInAppMessage * _Nonnull)message {
[self sendEvent:OSEventString(InAppMessageWillDisplay) withBody:[message jsonRepresentation]];
- (void)onWillDisplayInAppMessage:(OSInAppMessageWillDisplayEvent * _Nonnull)event {
jennantilla marked this conversation as resolved.
Show resolved Hide resolved
[self sendEvent:OSEventString(InAppMessageWillDisplay) withBody:[event.message jsonRepresentation]];
}

- (void)onDidDisplayInAppMessage:(OSInAppMessage * _Nonnull)message {
[self sendEvent:OSEventString(InAppMessageDidDisplay) withBody:[message jsonRepresentation]];
- (void)onDidDisplayInAppMessage:(OSInAppMessageDidDisplayEvent * _Nonnull)event {
[self sendEvent:OSEventString(InAppMessageDidDisplay) withBody:[event.message jsonRepresentation]];
}

- (void)onWillDismissInAppMessage:(OSInAppMessage * _Nonnull)message {
[self sendEvent:OSEventString(InAppMessageWillDismiss) withBody:[message jsonRepresentation]];
- (void)onWillDismissInAppMessage:(OSInAppMessageWillDismissEvent * _Nonnull)event {
[self sendEvent:OSEventString(InAppMessageWillDismiss) withBody:[event.message jsonRepresentation]];
}

- (void)onDidDismissInAppMessage:(OSInAppMessage * _Nonnull)message {
[self sendEvent:OSEventString(InAppMessageDidDismiss) withBody:[message jsonRepresentation]];
- (void)onDidDismissInAppMessage:(OSInAppMessageDidDismissEvent * _Nonnull)event {
[self sendEvent:OSEventString(InAppMessageDidDismiss) withBody:[event.message jsonRepresentation]];
}

- (void)dealloc {
Expand Down
4 changes: 2 additions & 2 deletions ios/RCTOneSignal/RCTOneSignalEventEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
typedef NS_ENUM(NSInteger, OSNotificationEventTypes) {
PermissionChanged,
SubscriptionChanged,
NotificationWillShowInForeground,
NotificationWillDisplayInForeground,
NotificationClicked,
InAppMessageClicked,
InAppMessageWillDisplay,
Expand All @@ -24,7 +24,7 @@ typedef NS_ENUM(NSInteger, OSNotificationEventTypes) {
InAppMessageDidDismiss,
};

#define OSNotificationEventTypesArray @[@"OneSignal-permissionChanged",@"OneSignal-subscriptionChanged",@"OneSignal-notificationWillShowInForeground",@"OneSignal-notificationClicked",@"OneSignal-inAppMessageClicked", @"OneSignal-inAppMessageWillDisplay", @"OneSignal-inAppMessageDidDisplay", @"OneSignal-inAppMessageWillDismiss", @"OneSignal-inAppMessageDidDismiss"]
#define OSNotificationEventTypesArray @[@"OneSignal-permissionChanged",@"OneSignal-subscriptionChanged",@"OneSignal-notificationWillDisplayInForeground",@"OneSignal-notificationClicked",@"OneSignal-inAppMessageClicked", @"OneSignal-inAppMessageWillDisplay", @"OneSignal-inAppMessageDidDisplay", @"OneSignal-inAppMessageWillDismiss", @"OneSignal-inAppMessageDidDismiss"]

#define OSEventString(enum) [OSNotificationEventTypesArray objectAtIndex:enum]

Expand Down
Loading