Skip to content

Commit

Permalink
Upgrade to latest native sdks
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemilla committed Dec 6, 2024
1 parent fa5cde1 commit 0c3a3c8
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 12 deletions.
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}

dependencies {
classpath "com.android.tools.build:gradle:7.2.1"
classpath "com.android.tools.build:gradle:8.1.4"
// noinspection DifferentKotlinGradleVersion
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
Expand Down Expand Up @@ -104,7 +104,7 @@ dependencies {
implementation 'com.google.code.gson:gson:2.11.0'

// Courier Core SDK
api 'com.github.trycourier:courier-android:4.6.7'
api 'com.github.trycourier:courier-android:5.0.2'
api 'androidx.recyclerview:recyclerview:1.3.2'

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class CourierInboxViewManager : SimpleViewManager<CourierInbox>() {
private var themedReactContext: ThemedReactContext? = null

private companion object {
const val ON_LONG_PRESS_MESSAGE_AT_INDEX = "courierLongPressMessageAtIndex"
const val ON_CLICK_MESSAGE_AT_INDEX = "courierClickMessageAtIndex"
const val ON_CLICK_ACTION_AT_INDEX = "courierClickActionAtIndex"
const val ON_SCROLL = "courierScrollInbox"
Expand All @@ -58,6 +59,18 @@ class CourierInboxViewManager : SimpleViewManager<CourierInbox>() {

}

@ReactProp(name = "onLongPressInboxMessageAtIndex")
fun setOnLongPressInboxMessageAtIndex(view: CourierInbox, callback: Boolean) {

view.setOnLongPressMessageListener { message, index ->
val map = Arguments.createMap()
map.putString("message", message.toJson())
map.putInt("index", index)
themedReactContext?.sendEvent(ON_LONG_PRESS_MESSAGE_AT_INDEX, map)
}

}

@ReactProp(name = "onClickInboxActionForMessageAtIndex")
fun setOnClickInboxActionForMessageAtIndex(view: CourierInbox, callback: Boolean) {

Expand Down Expand Up @@ -95,6 +108,11 @@ class CourierInboxViewManager : SimpleViewManager<CourierInbox>() {
view.darkTheme = theme.getMap("dark")?.toTheme(view) ?: CourierInboxTheme.DEFAULT_DARK
}

@ReactProp(name = "canSwipePages")
fun canSwipePages(view: CourierInbox, canSwipePages: Boolean) {
view.canSwipePages = canSwipePages
}

private fun ReadableMap.toTheme(view: View): CourierInboxTheme {

val android = getMap("android")
Expand Down
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

buildscript {
ext {
buildToolsVersion = "33.0.0"
buildToolsVersion = "32.0.0"
minSdkVersion = 23
compileSdkVersion = 34
targetSdkVersion = 34
Expand Down
4 changes: 2 additions & 2 deletions example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Dec 06 14:25:18 EST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-all.zip
networkTimeout=10000
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
1 change: 1 addition & 0 deletions example/ios/.xcode.env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export NODE_BINARY=/Users/mike/.nvm/versions/node/v18.18.0/bin/node
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PODS:
- boost (1.76.0)
- courier-react-native (5.1.0):
- courier-react-native (5.1.1):
- Courier_iOS (= 5.3.2)
- RCT-Folly (= 2021.07.22.00)
- React-Core
Expand Down Expand Up @@ -604,7 +604,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
boost: 57d2868c099736d80fcd648bf211b4431e51a558
courier-react-native: f900c52688b2178474f5358f98182c886c0998d1
courier-react-native: dbb00d05559b47447ae07fe4833d9d649589c622
Courier_iOS: 2d939748ae329074b58c54d707a6d2e49b1a673f
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
FBLazyVector: 5d4a3b7f411219a45a6d952f77d2c0a6c9989da5
Expand Down
6 changes: 3 additions & 3 deletions example/src/pages/inbox/InboxCustom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ const InboxCustom = () => {
onMessageChanged(feed, index, message) {
if (feed === 'feed') {
setMessages(prevMessages => {
const newMessages = [...prevMessages];
newMessages[index] = message;
return newMessages;
const newMessages = [...prevMessages];
newMessages[index] = message;
return newMessages;
});
}
},
Expand Down
52 changes: 50 additions & 2 deletions example/src/pages/inbox/InboxStyled.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Courier, { CourierInboxTheme, CourierInboxView } from '@trycourier/courier-react-native';
import Courier, { CourierInboxTheme, CourierInboxView, InboxMessage } from '@trycourier/courier-react-native';
import React from 'react';
import { View, StyleSheet } from 'react-native';
import { View, StyleSheet, ActionSheetIOS, Platform, Alert } from 'react-native';
import { Styles } from '../Styles';
import Env from '../../Env';

Expand Down Expand Up @@ -165,6 +165,51 @@ const InboxStyled = () => {
height: '100%',
},
});

const showMessageActions = (message: InboxMessage) => {
if (Platform.OS === 'android') {
Alert.alert(
'Message Actions',
'',
[
{
text: message.read ? 'Mark as Unread' : 'Mark as Read',
onPress: () => {
message.read ? Courier.shared.unreadMessage({ messageId: message.messageId }) : Courier.shared.readMessage({ messageId: message.messageId });
},
},
{
text: message.archived ? 'Unarchive' : 'Archive',
onPress: () => {
message.archived ? null : Courier.shared.archiveMessage({ messageId: message.messageId });
},
},
{
text: 'Cancel',
style: 'cancel',
},
]
);
} else if (Platform.OS === 'ios') {
ActionSheetIOS.showActionSheetWithOptions(
{
options: [message.read ? 'Mark as Unread' : 'Mark as Read', message.archived ? 'Unarchive' : 'Archive', 'Cancel'],
cancelButtonIndex: 2,
destructiveButtonIndex: 1,
},
(buttonIndex) => {
switch (buttonIndex) {
case 0:
message.read ? Courier.shared.unreadMessage({ messageId: message.messageId }) : Courier.shared.readMessage({ messageId: message.messageId });
break;
case 1:
message.archived ? null : Courier.shared.archiveMessage({ messageId: message.messageId });
break;
}
}
);
}
};

return (
<View style={styles.container}>
Expand All @@ -182,6 +227,9 @@ const InboxStyled = () => {
await Courier.shared.readMessage({ messageId: message.messageId });
}
}}
onLongPressInboxMessageAtIndex={(message, _index) => {
showMessageActions(message);
}}
onClickInboxActionForMessageAtIndex={(action, _message, _index) => {
console.log(action);
}}
Expand Down
2 changes: 2 additions & 0 deletions ios/CourierInboxReactNativeManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ @interface RCT_EXTERN_MODULE(CourierInboxViewManager, RCTViewManager)

RCT_EXPORT_VIEW_PROPERTY(onClickInboxMessageAtIndex, RCTBubblingEventBlock)

RCT_EXPORT_VIEW_PROPERTY(onLongPressInboxMessageAtIndex, RCTBubblingEventBlock)

RCT_EXPORT_VIEW_PROPERTY(onClickInboxActionForMessageAtIndex, RCTBubblingEventBlock)

RCT_EXPORT_VIEW_PROPERTY(onScrollInbox, RCTBubblingEventBlock)
Expand Down
12 changes: 12 additions & 0 deletions ios/CourierInboxReactNativeManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class CourierInboxView : UIView {
}

@objc var onClickInboxMessageAtIndex: RCTBubblingEventBlock? = nil

@objc var onLongPressInboxMessageAtIndex: RCTBubblingEventBlock? = nil

@objc var onClickInboxActionForMessageAtIndex: RCTBubblingEventBlock? = nil

Expand Down Expand Up @@ -58,6 +60,16 @@ class CourierInboxView : UIView {
Courier.shared.client?.error(error.localizedDescription)
}
},
didLongPressInboxMessageAtIndex: { [weak self] message, index in
do {
self?.onLongPressInboxMessageAtIndex?([
"message" : try message.toJson() ?? "",
"index" : index
])
} catch {
Courier.shared.client?.error(error.localizedDescription)
}
},
didClickInboxActionForMessageAtIndex: { [weak self] action, message, index in
do {
self?.onClickInboxActionForMessageAtIndex?([
Expand Down
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export { CourierInfoViewStyle } from './models/CourierInfoViewStyle';
export { iOS_CourierCell } from './models/iOS_CourierCell';
export { iOS_CourierSheet } from './models/iOS_CourierSheet';
export { InboxMessageSet } from './models/InboxMessageSet';
export { InboxMessage } from './models/InboxMessage';
export { CourierInboxButtonStyle, CourierInboxTextStyle, CourierInboxUnreadIndicatorStyle, CourierInboxTheme } from './models/CourierInboxTheme';
export { CourierPreferencesTheme, CourierPreferencesMode, CourierPreferencesChannel } from './models/CourierPreferencesTheme';
export type iOSForegroundPresentationOptions = 'sound' | 'badge' | 'list' | 'banner';
Expand Down
28 changes: 28 additions & 0 deletions src/views/CourierInboxView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type CourierInboxViewProps = {
dark?: CourierInboxTheme
};
onClickInboxMessageAtIndex?: (message: InboxMessage, index: number) => void;
onLongPressInboxMessageAtIndex?: (message: InboxMessage, index: number) => void;
onClickInboxActionForMessageAtIndex?: (action: InboxAction, message: InboxMessage, index: number) => void;
onScrollInbox?: (offsetY: number, offsetX: number) => void;
style?: ViewStyle;
Expand All @@ -22,13 +23,15 @@ const CourierInbox = Modules.getNativeComponent('CourierInboxView');
export const CourierInboxView = (props: CourierInboxViewProps) => {

let onClickInboxMessageAtIndexListener: EmitterSubscription | undefined = undefined;
let onLongPressInboxMessageAtIndexListener: EmitterSubscription | undefined = undefined;
let onClickInboxActionForMessageAtIndexListener: EmitterSubscription | undefined = undefined;
let onScrollInboxListener: EmitterSubscription | undefined = undefined;

useEffect(() => {

return () => {
onClickInboxMessageAtIndexListener?.remove();
onLongPressInboxMessageAtIndexListener?.remove();
onClickInboxActionForMessageAtIndexListener?.remove();
onScrollInboxListener?.remove();
}
Expand Down Expand Up @@ -59,6 +62,30 @@ export const CourierInboxView = (props: CourierInboxViewProps) => {

}

useEffect(() => {

onLongPressInboxMessageAtIndexListener?.remove();

if (Platform.OS === 'android' && props.onLongPressInboxMessageAtIndex) {
onLongPressInboxMessageAtIndexListener = DeviceEventEmitter.addListener('courierLongPressMessageAtIndex', onLongPressInboxMessageAtIndex);
}

}, [props.onLongPressInboxMessageAtIndex]);

const onLongPressInboxMessageAtIndex = (event: any) => {

// Parse the native event data
if (props.onLongPressInboxMessageAtIndex) {

const index = event["index"];
const message = JSON.parse(event["message"]) as InboxMessage;

props.onLongPressInboxMessageAtIndex(message, index);

}

}

useEffect(() => {

onClickInboxActionForMessageAtIndexListener?.remove();
Expand Down Expand Up @@ -111,6 +138,7 @@ export const CourierInboxView = (props: CourierInboxViewProps) => {
canSwipePages={props.canSwipePages ?? false}
theme={props.theme ?? { light: undefined, dark: undefined }}
onClickInboxMessageAtIndex={(event: any) => onClickInboxMessageAtIndex(event.nativeEvent)}
onLongPressInboxMessageAtIndex={(event: any) => onLongPressInboxMessageAtIndex(event.nativeEvent)}
onClickInboxActionForMessageAtIndex={(event: any) => onClickInboxActionForMessageAtIndex(event.nativeEvent)}
onScrollInbox={(event: any) => onScrollInbox(event.nativeEvent)}
style={props.style}
Expand Down

0 comments on commit 0c3a3c8

Please sign in to comment.