Skip to content

Commit b0f3226

Browse files
author
Mislav Stanić
committed
Merged in release/14.1.2 (pull request #47)
Release/14.1.2
2 parents 0e4532e + 754fbae commit b0f3226

7 files changed

Lines changed: 54 additions & 22 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.shakebugs.react.utils;
2+
3+
public class Converter {
4+
public static int stringToInt(String string) {
5+
int result = 0;
6+
7+
try {
8+
result = Integer.parseInt(string);
9+
} catch (Exception e) {
10+
Logger.w("Notification id is not a valid integer.");
11+
}
12+
13+
return result;
14+
}
15+
}

android/src/main/java/com/shakebugs/react/utils/Mapper.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,27 @@ public static NetworkRequest mapToNetworkRequest(ReadableMap object) {
7777
}
7878

7979
public static NotificationEvent mapToNotificationEvent(ReadableMap object) {
80+
String id = object.hasKey("id") && !object.isNull("id") ? object.getString("id") : "";
81+
String title = object.hasKey("title") && !object.isNull("title") ? object.getString("title") : "";
82+
String description = object.hasKey("description") && !object.isNull("description") ? object.getString("description") : "";
83+
8084
NotificationEvent notificationEvent = new NotificationEvent();
81-
notificationEvent.setId(object.getInt("id"));
82-
notificationEvent.setTitle(object.getString("title"));
83-
notificationEvent.setDescription(object.getString("description"));
85+
notificationEvent.setId(Converter.stringToInt(id));
86+
notificationEvent.setTitle(title);
87+
notificationEvent.setDescription(description);
8488

8589
return notificationEvent;
8690
}
8791

8892
public static WritableMap notificationEventToMap(NotificationEvent notificationEvent) {
93+
int id = notificationEvent.getId();
94+
String title = notificationEvent.getTitle() == null ? "" : notificationEvent.getTitle();
95+
String description = notificationEvent.getDescription() == null ? "" : notificationEvent.getDescription();
96+
8997
WritableMap map = new WritableNativeMap();
90-
map.putInt("id", notificationEvent.getId());
91-
map.putString("title", notificationEvent.getTitle());
92-
map.putString("description", notificationEvent.getDescription());
98+
map.putString("id", String.valueOf(id));
99+
map.putString("title", title);
100+
map.putString("description", description);
93101

94102
return map;
95103
}

example/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
"ios:dev": "export IOS_DEPENDENCY=$npm_package_config_ios_dev && npm run clean:ios && npm run ios:run:dev",
3232
"ios:stg": "export IOS_DEPENDENCY=$npm_package_config_ios_stg && npm run clean:ios && npm run ios:run:stg",
3333
"ios:prd": "export IOS_DEPENDENCY=$npm_package_config_ios_prd && npm run clean:ios && npm run ios:run:prd",
34-
"ios:run:dev": "react-native run-ios --scheme=Development",
35-
"ios:run:stg": "react-native run-ios --scheme=Staging",
36-
"ios:run:prd": "react-native run-ios --scheme=Production",
34+
"ios:run:dev": "react-native run-ios --scheme=Development --configuration=DevelopmentDebug",
35+
"ios:run:stg": "react-native run-ios --scheme=Staging --configuration=StagingDebug",
36+
"ios:run:prd": "react-native run-ios --scheme=Production --configuration=ProductionDebug",
3737
"build:ios": "npm run build:ios:dev",
3838
"build:ios:dev": "export IOS_DEPENDENCY=$npm_package_config_ios_dev && npm run clean:ios && npm run bundle:ios && cd ios && xcodebuild archive -workspace example.xcworkspace -scheme Development -configuration DevelopmentRelease 'COMPILER_INDEX_STORE_ENABLE=NO' -archivePath example.xcarchive && xcodebuild -exportArchive -archivePath example.xcarchive -exportPath ./ -exportOptionsPlist ../export_options.plist",
3939
"build:ios:stg": "export IOS_DEPENDENCY=$npm_package_config_ios_stg && npm run clean:ios && npm run bundle:ios && cd ios && xcodebuild archive -workspace example.xcworkspace -scheme Staging -configuration StagingRelease 'COMPILER_INDEX_STORE_ENABLE=NO' -archivePath example.xcarchive && xcodebuild -exportArchive -archivePath example.xcarchive -exportPath ./ -exportOptionsPlist ../export_options.plist",

example/src/ui/shake/ShakeScreen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ const ShakeScreen = (props) => {
150150

151151
const insertNotificationEvent = () => {
152152
const notificationEventBuilder = new NotificationEventBuilder()
153-
.setId(0)
153+
.setId('0')
154154
.setDescription('Description')
155155
.setTitle('Title');
156156
Shake.insertNotificationEvent(notificationEventBuilder);

index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ declare module "react-native-shake" {
101101
}
102102

103103
export class NotificationEvent {
104-
id: number;
104+
id: string;
105105
title: string;
106106
description: string;
107107
}
@@ -119,8 +119,8 @@ declare module "react-native-shake" {
119119
}
120120

121121
export class NotificationEventBuilder {
122-
getId: () => number;
123-
setId: (id: number) => NotificationEventBuilder;
122+
getId: () => string;
123+
setId: (id: string) => NotificationEventBuilder;
124124
getTitle: () => string;
125125
setTitle: (title: string) => NotificationEventBuilder;
126126
getDescription: () => string;

ios/RNShake.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,9 @@ - (NSDictionary*)mapToNotificationEvent:(nonnull NSDictionary*)notificationDict
354354
{
355355
NSDictionary *notificationEvent = [[NSDictionary alloc] init];
356356
notificationEvent = @{
357-
@"id": notificationDict[@"id"],
358-
@"title": notificationDict[@"title"],
359-
@"description": notificationDict[@"description"]
357+
@"id": (notificationDict[@"id"] ?: @""),
358+
@"title": (notificationDict[@"title"] ?: @""),
359+
@"description": (notificationDict[@"description"] ?: @"")
360360
};
361361
return notificationEvent;
362362
}
@@ -365,9 +365,9 @@ - (NSDictionary*)notificationToMap:(nonnull SHKNotificationEventEditor*)notifica
365365
{
366366
NSDictionary *notificationDict = [[NSDictionary alloc] init];
367367
notificationDict = @{
368-
@"id": notification.identifier,
369-
@"title": notification.title,
370-
@"description": notification.description,
368+
@"id": (notification.identifier ?: @""),
369+
@"title": (notification.title ?: @""),
370+
@"description": (notification.description ?: @"")
371371
};
372372
return notificationDict;
373373
}

src/builders/NotificationEventBuilder.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class NotificationEventBuilder {
1818
this._title = notificationEvent.title;
1919
this._description = notificationEvent.description;
2020
} else {
21-
this._id = 0;
22-
this._title = "";
23-
this._description = "";
21+
this._id = '';
22+
this._title = '';
23+
this._description = '';
2424
}
2525
}
2626

@@ -30,6 +30,9 @@ class NotificationEventBuilder {
3030

3131
setId(value) {
3232
this._id = value;
33+
if (!this._id) {
34+
this._id = '';
35+
}
3336
return this;
3437
}
3538

@@ -39,6 +42,9 @@ class NotificationEventBuilder {
3942

4043
setTitle(value) {
4144
this._title = value;
45+
if (!this._title) {
46+
this._title = '';
47+
}
4248
return this;
4349
}
4450

@@ -48,6 +54,9 @@ class NotificationEventBuilder {
4854

4955
setDescription(value) {
5056
this._description = value;
57+
if (!this._description) {
58+
this._description = '';
59+
}
5160
return this;
5261
}
5362

0 commit comments

Comments
 (0)