Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 57be563

Browse files
author
Boris Tacyniak
authored
Merge pull request #2067 from silencer07/master
Allow HTML tags to be used for styling in bigText field only
2 parents 381889d + ed46423 commit 57be563

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ PushNotification.localNotification({
307307
largeIcon: "ic_launcher", // (optional) default: "ic_launcher". Use "" for no large icon.
308308
largeIconUrl: "https://www.example.tld/picture.jpg", // (optional) default: undefined
309309
smallIcon: "ic_notification", // (optional) default: "ic_notification" with fallback for "ic_launcher". Use "" for default small icon.
310-
bigText: "My big text that will be shown when notification is expanded", // (optional) default: "message" prop
310+
bigText: "My big text that will be shown when notification is expanded. Styling can be done using HTML tags(see android docs for details)", // (optional) default: "message" prop
311311
subText: "This is a subText", // (optional) default: none
312312
bigPictureUrl: "https://www.example.tld/picture.jpg", // (optional) default: undefined
313313
bigLargeIcon: "ic_launcher", // (optional) default: undefined

android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
import android.os.Build;
2323
import android.os.Bundle;
2424
import android.service.notification.StatusBarNotification;
25+
import android.text.Spanned;
2526
import android.util.Log;
2627
import androidx.core.app.RemoteInput;
2728

2829
import androidx.annotation.RequiresApi;
2930
import androidx.core.app.NotificationCompat;
31+
import androidx.core.text.HtmlCompat;
3032

3133
import com.facebook.react.bridge.Arguments;
3234
import com.facebook.react.bridge.ReadableArray;
@@ -369,12 +371,6 @@ public void sendToNotificationCentreWithPicture(Bundle bundle, Bitmap largeIconB
369371
if (subText != null) {
370372
notification.setSubText(subText);
371373
}
372-
373-
String bigText = bundle.getString("bigText");
374-
375-
if (bigText == null) {
376-
bigText = message;
377-
}
378374

379375
NotificationCompat.Style style;
380376

@@ -401,7 +397,14 @@ public void sendToNotificationCentreWithPicture(Bundle bundle, Bitmap largeIconB
401397
.bigLargeIcon(bigLargeIconBitmap);
402398
}
403399
else {
404-
style = new NotificationCompat.BigTextStyle().bigText(bigText);
400+
String bigText = bundle.getString("bigText");
401+
402+
if (bigText == null) {
403+
style = new NotificationCompat.BigTextStyle().bigText(message);
404+
} else {
405+
Spanned styledText = HtmlCompat.fromHtml(bigText, HtmlCompat.FROM_HTML_MODE_LEGACY);
406+
style = new NotificationCompat.BigTextStyle().bigText(styledText);
407+
}
405408
}
406409

407410
notification.setStyle(style);

0 commit comments

Comments
 (0)