[notifications] Add support for Android BigPictureStyle and BigTextStyle

This commit is contained in:
Chris Bianca
2018-03-27 16:15:31 +01:00
parent f5f08b716d
commit 6ff34f4daa
3 changed files with 94 additions and 0 deletions

View File

@@ -236,6 +236,41 @@ public class RNFirebaseNotificationManager {
Double badgeIconType = android.getDouble("badgeIconType");
nb = nb.setBadgeIconType(badgeIconType.intValue());
}
if (android.containsKey("bigPicture")) {
Bundle bigPicture = android.getBundle("bigPicture");
NotificationCompat.BigPictureStyle bp = new NotificationCompat.BigPictureStyle();
Bitmap picture = getBitmap(bigPicture.getString("picture"));
if (picture != null) {
bp = bp.bigPicture(picture);
}
if (bigPicture.containsKey("largeIcon")) {
Bitmap largeIcon = getBitmap(bigPicture.getString("largeIcon"));
if (largeIcon != null) {
bp = bp.bigLargeIcon(largeIcon);
}
}
if (bigPicture.containsKey("contentTitle")) {
bp = bp.setBigContentTitle(bigPicture.getString("contentTitle"));
}
if (bigPicture.containsKey("summaryText")) {
bp = bp.setSummaryText(bigPicture.getString("summaryText"));
}
nb = nb.setStyle(bp);
}
if (android.containsKey("bigText")) {
Bundle bigText = android.getBundle("bigText");
NotificationCompat.BigTextStyle bt = new NotificationCompat.BigTextStyle();
bt.bigText(bigText.getString("text"));
if (bigText.containsKey("contentTitle")) {
bt = bt.setBigContentTitle(bigText.getString("contentTitle"));
}
if (bigText.containsKey("summaryText")) {
bt = bt.setSummaryText(bigText.getString("summaryText"));
}
nb = nb.setStyle(bt);
}
if (android.containsKey("category")) {
nb = nb.setCategory(android.getString("category"));
}

View File

@@ -7,6 +7,8 @@ import { BadgeIconType, Category, GroupAlert, Priority } from './types';
import type Notification from './Notification';
import type {
BadgeIconTypeType,
BigPicture,
BigText,
CategoryType,
DefaultsType,
GroupAlertType,
@@ -22,6 +24,8 @@ export default class AndroidNotification {
_actions: AndroidAction[];
_autoCancel: boolean | void;
_badgeIconType: BadgeIconTypeType | void;
_bigPicture: BigPicture | void;
_bigText: BigText | void;
_category: CategoryType | void;
_channelId: string;
_clickAction: string | void;
@@ -75,6 +79,8 @@ export default class AndroidNotification {
: [];
this._autoCancel = data.autoCancel;
this._badgeIconType = data.badgeIconType;
this._bigPicture = data.bigPicture;
this._bigText = data.bigText;
this._category = data.category;
this._channelId = data.channelId;
this._clickAction = data.clickAction;
@@ -128,6 +134,14 @@ export default class AndroidNotification {
return this._badgeIconType;
}
get bigPicture(): ?BigPicture {
return this._bigPicture;
}
get bigText(): ?BigText {
return this._bigText;
}
get category(): ?CategoryType {
return this._category;
}
@@ -298,6 +312,34 @@ export default class AndroidNotification {
return this._notification;
}
setBigPicture(
picture: string,
largeIcon?: string,
contentTitle?: string,
summaryText?: string
): Notification {
this._bigPicture = {
contentTitle,
largeIcon,
picture,
summaryText,
};
return this._notification;
}
setBigText(
text: string,
contentTitle?: string,
summaryText?: string
): Notification {
this._bigText = {
contentTitle,
summaryText,
text,
};
return this._notification;
}
/**
*
* @param category
@@ -639,6 +681,8 @@ export default class AndroidNotification {
actions: this._actions.map(action => action.build()),
autoCancel: this._autoCancel,
badgeIconType: this._badgeIconType,
bigPicture: this._bigPicture,
bigText: this._bigText,
category: this._category,
channelId: this._channelId,
clickAction: this._clickAction,

View File

@@ -85,6 +85,19 @@ export type PriorityType = $Values<typeof Priority>;
export type SemanticActionType = $Values<typeof SemanticAction>;
export type VisibilityType = $Values<typeof Visibility>;
export type BigPicture = {|
contentTitle?: string,
largeIcon?: string,
picture: string,
summaryText?: string,
|};
export type BigText = {|
contentTitle?: string,
summaryText?: string,
text: string,
|};
export type Lights = {|
argb: number,
onMs: number,
@@ -129,6 +142,8 @@ export type NativeAndroidNotification = {|
actions?: NativeAndroidAction[],
autoCancel?: boolean,
badgeIconType?: BadgeIconTypeType,
bigPicture?: BigPicture,
bigText?: BigText,
category?: CategoryType,
channelId: string,
clickAction?: string,