pushwoosh-react-native-plugin 1.2.5 → 2.2.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.yml +135 -0
  2. package/.github/ISSUE_TEMPLATE/feature_request.yml +31 -0
  3. package/.github/ISSUE_TEMPLATE/question.yml +28 -0
  4. package/InlineInApp.js +71 -0
  5. package/README.md +35 -85
  6. package/docs/README.md +230 -11
  7. package/index.d.ts +91 -0
  8. package/index.js +536 -154
  9. package/package.json +12 -1
  10. package/pushwoosh-react-native-plugin.podspec +20 -0
  11. package/react-native.config.js +9 -0
  12. package/scripts/add_inbox_ios_resources.js +42 -0
  13. package/src/android/build.gradle +40 -10
  14. package/src/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  15. package/src/android/gradle/wrapper/gradle-wrapper.properties +6 -0
  16. package/src/android/gradlew +160 -0
  17. package/src/android/gradlew.bat +90 -0
  18. package/src/android/src/main/AndroidManifest.xml +19 -54
  19. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/ConversionUtil.java +214 -148
  20. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/CustomFirebaseMessagingService.java +29 -0
  21. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/EventDispatcher.java +10 -2
  22. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/InboxUiStyleManager.java +162 -0
  23. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/InlineInAppManager.java +48 -0
  24. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/PushwooshNotificationServiceExtension.java +44 -0
  25. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/PushwooshPackage.java +4 -2
  26. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/PushwooshPlugin.java +608 -297
  27. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/RCTInlineInAppView.java +75 -0
  28. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/internal/ReactNativePluginProvider.java +15 -0
  29. package/src/ios/PWAppDelegate.h +20 -0
  30. package/src/ios/PWGDPRManager.h +46 -0
  31. package/src/ios/PWIInboxStyle.h +122 -0
  32. package/src/ios/PWIInboxUI.h +39 -0
  33. package/src/ios/PWInAppManager.h +176 -0
  34. package/src/ios/PWInbox.h +147 -0
  35. package/src/ios/PWInlineInAppView.h +26 -0
  36. package/src/ios/PWLog.h +23 -0
  37. package/src/ios/PWMessaging.h +20 -0
  38. package/src/ios/PWNotificationExtensionManager.h +46 -0
  39. package/src/ios/PWRichMediaManager.h +123 -0
  40. package/src/ios/PWRichMediaStyle.h +122 -0
  41. package/src/ios/PushNotificationManager.h +234 -111
  42. package/src/ios/Pushwoosh.h +623 -0
  43. package/src/ios/PushwooshInboxBundle.bundle/Info.plist +0 -0
  44. package/src/ios/PushwooshInboxBundle.bundle/PWIInboxAttachmentViewController.nib +0 -0
  45. package/src/ios/PushwooshInboxBundle.bundle/PWIInboxMessageViewCell.nib +0 -0
  46. package/src/ios/PushwooshInboxBundle.bundle/PWIInboxViewController.nib +0 -0
  47. package/src/ios/PushwooshInboxBundle.bundle/errorMessage@2x.png +0 -0
  48. package/src/ios/PushwooshInboxBundle.bundle/inbox_icon.png +0 -0
  49. package/src/ios/PushwooshInboxBundle.bundle/noMessage@2x.png +0 -0
  50. package/src/ios/PushwooshInboxBundle.bundle/unread.png +0 -0
  51. package/src/ios/PushwooshInboxUI.h +19 -0
  52. package/src/ios/PushwooshPlugin/PWEventDispatcher.h +1 -1
  53. package/src/ios/PushwooshPlugin/PWInlineInAppManager.h +17 -0
  54. package/src/ios/PushwooshPlugin/PWInlineInAppManager.m +54 -0
  55. package/src/ios/PushwooshPlugin/Pushwoosh.h +19 -2
  56. package/src/ios/PushwooshPlugin/Pushwoosh.m +552 -75
  57. package/src/ios/PushwooshPlugin.xcodeproj/project.pbxproj +27 -6
  58. package/src/ios/libPushwoosh.a +0 -0
  59. package/src/ios/libPushwooshInboxUI.a +0 -0
  60. package/.npmignore +0 -3
  61. package/src/android/.npmignore +0 -1
  62. package/src/android/pushwooshplugin.iml +0 -145
  63. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/NotificationReceiver.java +0 -42
  64. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/PostEventActivity.java +0 -45
  65. package/src/ios/Pushwoosh.a +0 -0
  66. package/src/ios/PushwooshPlugin.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
@@ -1,5 +1,11 @@
1
1
  package com.pushwoosh.reactnativeplugin;
2
2
 
3
+ import android.os.Bundle;
4
+ import android.util.Log;
5
+
6
+ import java.util.ArrayList;
7
+ import java.util.Iterator;
8
+
3
9
  import com.facebook.react.bridge.ReadableArray;
4
10
  import com.facebook.react.bridge.ReadableMap;
5
11
  import com.facebook.react.bridge.ReadableMapKeySetIterator;
@@ -8,160 +14,220 @@ import com.facebook.react.bridge.WritableArray;
8
14
  import com.facebook.react.bridge.WritableMap;
9
15
  import com.facebook.react.bridge.WritableNativeArray;
10
16
  import com.facebook.react.bridge.WritableNativeMap;
17
+ import com.pushwoosh.inbox.data.InboxMessage;
11
18
  import com.pushwoosh.internal.utils.JsonUtils;
12
19
  import com.pushwoosh.internal.utils.PWLog;
20
+ import com.pushwoosh.tags.TagsBundle;
13
21
 
22
+ import org.json.JSONArray;
14
23
  import org.json.JSONException;
15
24
  import org.json.JSONObject;
16
25
 
17
- import java.util.ArrayList;
18
- import java.util.Collections;
19
- import java.util.HashMap;
20
- import java.util.List;
21
- import java.util.Map;
22
-
23
26
  public final class ConversionUtil {
24
27
 
25
- public static Map<String, Object> toMap(ReadableMap readableMap) {
26
- ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
27
- Map<String, Object> result = new HashMap<>();
28
- while (iterator.hasNextKey()) {
29
- String key = iterator.nextKey();
30
- ReadableType type = readableMap.getType(key);
31
- switch (type) {
32
- case Null:
33
- result.put(key, null);
34
- break;
35
- case Boolean:
36
- result.put(key, readableMap.getBoolean(key));
37
- break;
38
- case Number:
39
- result.put(key, readableMap.getDouble(key));
40
- break;
41
- case String:
42
- result.put(key, readableMap.getString(key));
43
- break;
44
- case Map:
45
- result.put(key, toMap(readableMap.getMap(key)));
46
- break;
47
- case Array:
48
- result.put(key, toArray(readableMap.getArray(key)));
49
- break;
50
- default:
51
- PWLog.error(PushwooshPlugin.TAG, "Could not convert object with key: " + key + ".");
52
- }
53
-
54
- }
55
- return result;
56
- }
57
-
58
- public static List<Object> toArray(ReadableArray readableArray) {
59
- List<Object> result = new ArrayList<>(readableArray.size());
60
- for (int i = 0; i < readableArray.size(); i++) {
61
- ReadableType indexType = readableArray.getType(i);
62
- switch(indexType) {
63
- case Null:
64
- result.add(i, null);
65
- break;
66
- case Boolean:
67
- result.add(i, readableArray.getBoolean(i));
68
- break;
69
- case Number:
70
- result.add(i, readableArray.getDouble(i));
71
- break;
72
- case String:
73
- result.add(i, readableArray.getString(i));
74
- break;
75
- case Map:
76
- result.add(i, toMap(readableArray.getMap(i)));
77
- break;
78
- case Array:
79
- result.add(i, toArray(readableArray.getArray(i)));
80
- break;
81
- default:
82
- PWLog.error(PushwooshPlugin.TAG, "Could not convert object at index " + i + ".");
83
- }
84
- }
85
- return result;
86
- }
87
-
88
- public static Map<String, Object> stringToMap(String string) {
89
- try {
90
- JSONObject json = new JSONObject(string);
91
- return JsonUtils.jsonToMap(json);
92
- }
93
- catch (JSONException e) {
94
- PWLog.exception(e);
95
- }
96
-
97
- return Collections.<String, Object>emptyMap();
98
- }
99
-
100
- public static WritableMap toWritableMap(Map<String, Object> map) {
101
- WritableNativeMap result = new WritableNativeMap();
102
-
103
- for(Map.Entry<String, Object> entry : map.entrySet()) {
104
- String key = entry.getKey();
105
- Object value = entry.getValue();
106
- if (value == null) {
107
- result.putNull(key);
108
- }
109
- else if (value instanceof Map) {
110
- result.putMap(key, toWritableMap((Map)value));
111
- }
112
- else if (value instanceof List) {
113
- result.putArray(key, toWritableArray((List) value));
114
- }
115
- else if (value instanceof Boolean) {
116
- result.putBoolean(key, (Boolean)value);
117
- }
118
- else if (value instanceof Integer) {
119
- result.putInt(key, (Integer)value);
120
- }
121
- else if (value instanceof String) {
122
- result.putString(key, (String)value);
123
- }
124
- else if (value instanceof Double) {
125
- result.putDouble(key, (Double)value);
126
- }
127
- else {
128
- PWLog.error(PushwooshPlugin.TAG, "Could not convert object " + value.toString());
129
- }
130
- }
131
-
132
- return result;
133
- }
134
-
135
- public static WritableArray toWritableArray(List<Object> array) {
136
- WritableNativeArray result = new WritableNativeArray();
137
-
138
- for (Object value : array) {
139
- if (value == null) {
140
- result.pushNull();
141
- }
142
- else if (value instanceof Map) {
143
- result.pushMap(toWritableMap((Map) value));
144
- }
145
- else if (value instanceof List) {
146
- result.pushArray(toWritableArray((List) value));
147
- }
148
- else if (value instanceof Boolean) {
149
- result.pushBoolean((Boolean) value);
150
- }
151
- else if (value instanceof Integer) {
152
- result.pushInt((Integer) value);
153
- }
154
- else if (value instanceof String) {
155
- result.pushString((String) value);
156
- }
157
- else if (value instanceof Double) {
158
- result.pushDouble((Double) value);
159
- }
160
- else {
161
- PWLog.error(PushwooshPlugin.TAG, "Could not convert object " + value.toString());
162
- }
163
- }
164
-
165
- return result;
166
- }
28
+ public static TagsBundle convertToTagsBundle(ReadableMap readableMap) {
29
+ return new TagsBundle.Builder()
30
+ .putAll(toJsonObject(readableMap))
31
+ .build();
32
+ }
33
+
34
+ public static JSONObject toJsonObject(ReadableMap readableMap) {
35
+ ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
36
+ JSONObject result = new JSONObject();
37
+ while (iterator.hasNextKey()) {
38
+ String key = iterator.nextKey();
39
+ ReadableType type = readableMap.getType(key);
40
+ try {
41
+ switch (type) {
42
+ case Null:
43
+ result.put(key, JSONObject.NULL);
44
+ break;
45
+ case Boolean:
46
+ result.put(key, readableMap.getBoolean(key));
47
+ break;
48
+ case Number:
49
+ result.put(key, readableMap.getDouble(key));
50
+ break;
51
+ case String:
52
+ result.put(key, readableMap.getString(key));
53
+ break;
54
+ case Map:
55
+ result.put(key, toJsonObject(readableMap.getMap(key)));
56
+ break;
57
+ case Array:
58
+ result.put(key, toArray(readableMap.getArray(key)));
59
+ break;
60
+ default:
61
+ PWLog.error(PushwooshPlugin.TAG, "Could not convert object with key: " + key + ".");
62
+ }
63
+
64
+ } catch (JSONException e) {
65
+ PWLog.error(PushwooshPlugin.TAG, "Could not convert object with key: " + key + ".", e);
66
+ }
67
+
68
+ }
69
+ return result;
70
+ }
71
+
72
+ public static JSONArray toArray(ReadableArray readableArray) {
73
+ JSONArray result = new JSONArray();
74
+ for (int i = 0; i < readableArray.size(); i++) {
75
+ ReadableType indexType = readableArray.getType(i);
76
+ try {
77
+ switch (indexType) {
78
+ case Null:
79
+ result.put(i, JSONObject.NULL);
80
+ break;
81
+ case Boolean:
82
+ result.put(i, readableArray.getBoolean(i));
83
+ break;
84
+ case Number:
85
+ result.put(i, readableArray.getDouble(i));
86
+ break;
87
+ case String:
88
+ result.put(i, readableArray.getString(i));
89
+ break;
90
+ case Map:
91
+ result.put(i, toJsonObject(readableArray.getMap(i)));
92
+ break;
93
+ case Array:
94
+ result.put(i, toArray(readableArray.getArray(i)));
95
+ break;
96
+ default:
97
+ PWLog.error(PushwooshPlugin.TAG, "Could not convert object at index " + i + ".");
98
+ }
99
+ } catch (JSONException e) {
100
+ PWLog.error(PushwooshPlugin.TAG, "Could not convert object at index " + i + ".", e);
101
+ }
102
+ }
103
+ return result;
104
+ }
105
+
106
+ public static JSONObject stringToJSONObject(String string) {
107
+ try {
108
+ JSONObject json = new JSONObject(string);
109
+ return json;
110
+ } catch (JSONException e) {
111
+ PWLog.exception(e);
112
+ }
113
+
114
+ return new JSONObject();
115
+ }
116
+
117
+ public static WritableMap toWritableMap(JSONObject jsonObject) {
118
+ WritableNativeMap result = new WritableNativeMap();
119
+
120
+ Iterator<String> keys = jsonObject.keys();
121
+ while (keys.hasNext()) {
122
+ String key = keys.next();
123
+ try {
124
+ Object value = jsonObject.get(key);
125
+
126
+ if (value == null || JSONObject.NULL.equals(value)) {
127
+ result.putNull(key);
128
+ } else if (value instanceof JSONObject) {
129
+ result.putMap(key, toWritableMap((JSONObject) value));
130
+ } else if (value instanceof JSONArray) {
131
+ result.putArray(key, toWritableArray((JSONArray) value));
132
+ } else if (value instanceof Boolean) {
133
+ result.putBoolean(key, (Boolean) value);
134
+ } else if (value instanceof Integer) {
135
+ result.putInt(key, (Integer) value);
136
+ } else if (value instanceof Long) {
137
+ result.putString(key, String.valueOf(value));
138
+ } else if (value instanceof String) {
139
+ result.putString(key, (String) value);
140
+ } else if (value instanceof Double) {
141
+ result.putDouble(key, (Double) value);
142
+ } else {
143
+ PWLog.error(PushwooshPlugin.TAG, "Could not convert object " + value.toString());
144
+ }
145
+
146
+ } catch (JSONException e) {
147
+ PWLog.error(PushwooshPlugin.TAG, "Could not convert object with key " + key, e);
148
+ }
149
+ }
150
+
151
+ return result;
152
+ }
153
+
154
+ public static WritableArray toWritableArray(JSONArray array) {
155
+ WritableNativeArray result = new WritableNativeArray();
156
+
157
+ for (int i = 0; i < array.length(); i++) {
158
+ try {
159
+ Object value = array.get(i);
160
+ if (value == null) {
161
+ result.pushNull();
162
+ } else if (value instanceof JSONObject) {
163
+ result.pushMap(toWritableMap((JSONObject) value));
164
+ } else if (value instanceof JSONArray) {
165
+ result.pushArray(toWritableArray((JSONArray) value));
166
+ } else if (value instanceof Boolean) {
167
+ result.pushBoolean((Boolean) value);
168
+ } else if (value instanceof Integer) {
169
+ result.pushInt((Integer) value);
170
+ } else if (value instanceof Long) {
171
+ result.pushString(String.valueOf(value));
172
+ } else if (value instanceof String) {
173
+ result.pushString((String) value);
174
+ } else if (value instanceof Double) {
175
+ result.pushDouble((Double) value);
176
+ } else {
177
+ PWLog.error(PushwooshPlugin.TAG, "Could not convert object " + value.toString());
178
+ }
179
+ } catch (JSONException e) {
180
+ e.printStackTrace();
181
+ PWLog.error(PushwooshPlugin.TAG, "Could not convert object with index i " + i + " in array " + array.toString(), e);
182
+ }
183
+ }
184
+
185
+ return result;
186
+ }
187
+
188
+ public static WritableMap inboxMessageToWritableMap(InboxMessage message) {
189
+ return toWritableMap(inboxMessageToJson(message));
190
+ }
191
+
192
+ public static JSONObject inboxMessageToJson(InboxMessage message) {
193
+ JSONObject object = new JSONObject();
194
+ try {
195
+ object.put("code", message.getCode())
196
+ .put("title", message.getTitle())
197
+ .put("imageUrl", message.getImageUrl())
198
+ .put("message",message.getMessage())
199
+ .put("sendDate",message.getISO8601SendDate())
200
+ .put("type", message.getType().getCode())
201
+ .put("bannerUrl", message.getBannerUrl())
202
+ .put("isRead",message.isRead())
203
+ .put("actionParams",message.getActionParams())
204
+ .put("isActionPerformed",message.isActionPerformed());
205
+
206
+ Bundle bundle = JsonUtils.jsonStringToBundle( message.getActionParams());
207
+ String customData = bundle.getString("u");
208
+ if (customData != null) {
209
+ object.put("customData", customData);
210
+ }
211
+ } catch (JSONException e) {
212
+ Log.e("PushwooshInbox", "Failed to fetch inbox message :" + e.getMessage());
213
+ }
214
+ return object;
215
+ }
216
+
217
+ public static ArrayList<String> messageCodesArrayToArrayList(ReadableArray readableArray) {
218
+ ArrayList<String> result = new ArrayList<>();
219
+ for (int i = 0; i < readableArray.size(); i++) {
220
+ ReadableType indexType = readableArray.getType(i);
221
+ try {
222
+ if (indexType == ReadableType.String) {
223
+ result.add(readableArray.getString(i));
224
+ } else {
225
+ PWLog.error(PushwooshPlugin.TAG, "Could not convert object at index " + i + ".");
226
+ }
227
+ } catch (Exception e) {
228
+ PWLog.error(PushwooshPlugin.TAG, "Could not convert object at index " + i + ".", e);
229
+ }
230
+ }
231
+ return result;
232
+ }
167
233
  }
@@ -0,0 +1,29 @@
1
+ package com.pushwoosh.plugin.pushnotifications;
2
+
3
+ import androidx.annotation.NonNull;
4
+
5
+ import com.google.firebase.messaging.FirebaseMessagingService;
6
+ import com.google.firebase.messaging.RemoteMessage;
7
+ import com.pushwoosh.firebase.PushwooshFcmHelper;
8
+
9
+ public class CustomFirebaseMessagingService extends FirebaseMessagingService {
10
+ @Override
11
+ public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
12
+ if (PushwooshFcmHelper.isPushwooshMessage(remoteMessage)){
13
+ PushwooshFcmHelper.onMessageReceived(this, remoteMessage);
14
+ } else {
15
+ //handle push from a different service here
16
+ }
17
+ }
18
+
19
+ @Override
20
+ public void onNewToken(@NonNull String s) {
21
+ super.onNewToken(s);
22
+ PushwooshFcmHelper.onTokenRefresh(s);
23
+ sendTokenToAnotherService();
24
+ }
25
+
26
+ public void sendTokenToAnotherService() {
27
+ //handle push registration of another service here
28
+ }
29
+ }
@@ -1,12 +1,15 @@
1
1
  package com.pushwoosh.reactnativeplugin;
2
2
 
3
- import com.facebook.react.bridge.Callback;
4
-
5
3
  import java.util.ArrayList;
6
4
  import java.util.HashMap;
7
5
  import java.util.List;
8
6
  import java.util.Map;
9
7
 
8
+ import com.facebook.react.bridge.Callback;
9
+ import com.facebook.react.bridge.ReactContext;
10
+ import com.facebook.react.bridge.WritableMap;
11
+ import com.facebook.react.modules.core.DeviceEventManagerModule;
12
+
10
13
  public class EventDispatcher {
11
14
 
12
15
  private Map<String, List<Callback>> subscribers = new HashMap<String, List<Callback>>();
@@ -41,4 +44,9 @@ public class EventDispatcher {
41
44
  list.clear();
42
45
  }
43
46
  }
47
+
48
+ public void sendJSEvent(ReactContext reactContext, String event, WritableMap params) {
49
+ reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
50
+ .emit(event, params);
51
+ }
44
52
  }
@@ -0,0 +1,162 @@
1
+ package com.pushwoosh.reactnativeplugin;
2
+
3
+ import android.content.Context;
4
+ import android.graphics.Bitmap;
5
+ import android.graphics.BitmapFactory;
6
+ import android.graphics.drawable.BitmapDrawable;
7
+ import android.graphics.drawable.Drawable;
8
+
9
+ import com.facebook.react.bridge.ReadableMap;
10
+ import com.pushwoosh.inbox.ui.PushwooshInboxStyle;
11
+ import com.pushwoosh.inbox.ui.model.customizing.formatter.InboxDateFormatter;
12
+
13
+ import java.io.IOException;
14
+ import java.net.URL;
15
+ import java.text.SimpleDateFormat;
16
+ import java.util.Date;
17
+ import java.util.Locale;
18
+
19
+ class InboxUiStyleManager {
20
+ private static final String LIST_ERROR_MESSAGE_KEY = "listErrorMessage";
21
+ private static final String LIST_EMPTY_MESSAGE_KEY = "listEmptyMessage";
22
+ private static final String DATE_FORMAT_KEY = "dateFormat";
23
+ private static final String DEFAULT_IMAGE_ICON_KEY = "defaultImageIcon";
24
+ private static final String LIST_ERROR_IMAGE_KEY = "listErrorImage";
25
+ private static final String LIST_EMPTY_IMAGE_KEY = "listEmptyImage";
26
+ private static final String ACCENT_COLOR_KEY = "accentColor";
27
+ private static final String HIGHLIGHT_COLOR_KEY = "highlightColor";
28
+ private static final String BACKGROUND_COLOR_KEY = "backgroundColor";
29
+ private static final String DIVIDER_COLOR_KEY = "dividerColor";
30
+ private static final String DATE_COLOR_KEY = "dateColor";
31
+ private static final String READ_DATE_COLOR_KEY = "readDateColor";
32
+ private static final String TITLE_COLOR_KEY = "titleColor";
33
+ private static final String READ_TITLE_COLOR_KEY = "readTitleColor";
34
+ private static final String DESCRIPTION_COLOR_KEY = "descriptionColor";
35
+ private static final String READ_DESCRIPTION_COLOR_KEY = "readDescriptionColor";
36
+ private static final String BAR_BACKGROUND_COLOR = "barBackgroundColor";
37
+ private static final String BAR_ACCENT_COLOR = "barAccentColor";
38
+ private static final String BAR_TEXT_COLOR = "barTextColor";
39
+
40
+ public static final String URI_KEY = "uri";
41
+
42
+ private Context context;
43
+
44
+ public InboxUiStyleManager(Context context){
45
+ this.context = context;
46
+ }
47
+
48
+ public void setStyle(ReadableMap mapStyle) {
49
+ setDateFormat(mapStyle);
50
+ setImages(mapStyle);
51
+ setTexts(mapStyle);
52
+ setColors(mapStyle);
53
+ }
54
+
55
+ private void setDateFormat(ReadableMap mapStyle) {
56
+ if (!mapStyle.hasKey(DATE_FORMAT_KEY)) {
57
+ return;
58
+ }
59
+ String dateFormat = mapStyle.getString(DATE_FORMAT_KEY);
60
+ if (dateFormat != null && !dateFormat.isEmpty()) {
61
+ ReactInboxDateFormatter inboxDateFormatter = new ReactInboxDateFormatter(dateFormat);
62
+ PushwooshInboxStyle.INSTANCE.setDateFormatter(inboxDateFormatter);
63
+ }
64
+ }
65
+
66
+ private void setTexts(ReadableMap mapStyle) {
67
+ PushwooshInboxStyle PWInboxStyle = PushwooshInboxStyle.INSTANCE;
68
+ if (mapStyle.hasKey(LIST_ERROR_MESSAGE_KEY))
69
+ PWInboxStyle.setListErrorMessage(mapStyle.getString(LIST_ERROR_MESSAGE_KEY));
70
+ if (mapStyle.hasKey(LIST_EMPTY_MESSAGE_KEY))
71
+ PWInboxStyle.setListEmptyText(mapStyle.getString(LIST_EMPTY_MESSAGE_KEY));
72
+ }
73
+
74
+ private void setImages(ReadableMap mapStyle) {
75
+ PushwooshInboxStyle PWInboxStyle = PushwooshInboxStyle.INSTANCE;
76
+ Drawable defaultImageIcon = getImage(mapStyle, DEFAULT_IMAGE_ICON_KEY);
77
+ if (defaultImageIcon != null)
78
+ PWInboxStyle.setDefaultImageIconDrawable(defaultImageIcon);
79
+
80
+ Drawable listErrorImage = getImage(mapStyle, LIST_ERROR_IMAGE_KEY);
81
+ if (listErrorImage != null)
82
+ PWInboxStyle.setListErrorImageDrawable(listErrorImage);
83
+
84
+ Drawable listEmptyImage = getImage(mapStyle, LIST_EMPTY_IMAGE_KEY);
85
+ if (listEmptyImage != null)
86
+ PWInboxStyle.setListEmptyImageDrawable(listEmptyImage);
87
+ }
88
+
89
+ private Drawable getImage(ReadableMap mapStyle, String key) {
90
+ if (!mapStyle.hasKey(key)) {
91
+ return null;
92
+ }
93
+ ReadableMap defaultImageIcon = mapStyle.getMap(key);
94
+ String uri = defaultImageIcon.getString(URI_KEY);
95
+ try {
96
+ return getDrawable(uri);
97
+ } catch (IOException e) {
98
+ e.printStackTrace();
99
+ }
100
+ return null;
101
+ }
102
+
103
+ private Drawable getDrawable(String uri) throws IOException {
104
+ URL url = new URL(uri);
105
+ Bitmap bitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream());
106
+ Drawable drawable = null;
107
+ if (context != null) {
108
+ drawable = new BitmapDrawable(context.getResources(), bitmap);
109
+ }
110
+ return drawable;
111
+ }
112
+
113
+ private void setColors(ReadableMap mapStyle) {
114
+ PushwooshInboxStyle PWInboxStyle = PushwooshInboxStyle.INSTANCE;
115
+
116
+ if (mapStyle.hasKey(ACCENT_COLOR_KEY))
117
+ PWInboxStyle.setAccentColor(mapStyle.getInt(ACCENT_COLOR_KEY));
118
+ if (mapStyle.hasKey(HIGHLIGHT_COLOR_KEY))
119
+ PWInboxStyle.setHighlightColor(mapStyle.getInt(HIGHLIGHT_COLOR_KEY));
120
+ if (mapStyle.hasKey(BACKGROUND_COLOR_KEY))
121
+ PWInboxStyle.setBackgroundColor(mapStyle.getInt(BACKGROUND_COLOR_KEY));
122
+ if (mapStyle.hasKey(DIVIDER_COLOR_KEY))
123
+ PWInboxStyle.setDividerColor(mapStyle.getInt(DIVIDER_COLOR_KEY));
124
+
125
+ if (mapStyle.hasKey(DATE_COLOR_KEY))
126
+ PWInboxStyle.setDateColor(mapStyle.getInt(DATE_COLOR_KEY));
127
+ if (mapStyle.hasKey(READ_DATE_COLOR_KEY))
128
+ PWInboxStyle.setReadDateColor(mapStyle.getInt(READ_DATE_COLOR_KEY));
129
+
130
+ if (mapStyle.hasKey(TITLE_COLOR_KEY))
131
+ PWInboxStyle.setTitleColor(mapStyle.getInt(TITLE_COLOR_KEY));
132
+ if (mapStyle.hasKey(READ_TITLE_COLOR_KEY))
133
+ PWInboxStyle.setReadTitleColor(mapStyle.getInt(READ_TITLE_COLOR_KEY));
134
+
135
+ if (mapStyle.hasKey(DESCRIPTION_COLOR_KEY))
136
+ PWInboxStyle.setDescriptionColor(mapStyle.getInt(DESCRIPTION_COLOR_KEY));
137
+ if (mapStyle.hasKey(READ_DESCRIPTION_COLOR_KEY))
138
+ PWInboxStyle.setReadDescriptionColor(mapStyle.getInt(READ_DESCRIPTION_COLOR_KEY));
139
+
140
+ if (mapStyle.hasKey(BAR_BACKGROUND_COLOR))
141
+ PWInboxStyle.setBarBackgroundColor(mapStyle.getInt(BAR_BACKGROUND_COLOR));
142
+ if (mapStyle.hasKey(BAR_ACCENT_COLOR))
143
+ PWInboxStyle.setBarAccentColor(mapStyle.getInt(BAR_ACCENT_COLOR));
144
+ if (mapStyle.hasKey(BAR_TEXT_COLOR))
145
+ PWInboxStyle.setBarTextColor(mapStyle.getInt(BAR_TEXT_COLOR));
146
+ }
147
+
148
+ private class ReactInboxDateFormatter implements InboxDateFormatter {
149
+
150
+ private SimpleDateFormat simpleDateFormat;
151
+
152
+ public ReactInboxDateFormatter(String dateFormat) {
153
+ Locale aDefault = Locale.getDefault();
154
+ simpleDateFormat = new SimpleDateFormat(dateFormat, aDefault);
155
+ }
156
+
157
+ @Override
158
+ public String transform(Date date) {
159
+ return simpleDateFormat.format(date);
160
+ }
161
+ }
162
+ }
@@ -0,0 +1,48 @@
1
+ package com.pushwoosh.reactnativeplugin;
2
+
3
+ import com.facebook.react.common.MapBuilder;
4
+ import com.facebook.react.uimanager.SimpleViewManager;
5
+ import com.facebook.react.uimanager.ThemedReactContext;
6
+ import com.facebook.react.uimanager.annotations.ReactProp;
7
+
8
+ import java.util.Map;
9
+
10
+ public class InlineInAppManager extends SimpleViewManager<RCTInlineInAppView> {
11
+ public static final String REACT_CLASS = "PWInlineInAppView";
12
+
13
+ @Override
14
+ public String getName() {
15
+ return REACT_CLASS;
16
+ }
17
+
18
+ @Override
19
+ public RCTInlineInAppView createViewInstance(ThemedReactContext context) {
20
+ RCTInlineInAppView view = new RCTInlineInAppView(context);
21
+ return view;
22
+ }
23
+
24
+ @ReactProp(name = "identifier")
25
+ public void setIdentifier(final RCTInlineInAppView view, String identifier) {
26
+ view.setIdentifier(identifier);
27
+ }
28
+
29
+ public Map getExportedCustomBubblingEventTypeConstants() {
30
+ return MapBuilder.builder()
31
+ .put(
32
+ "onLoaded",
33
+ MapBuilder.of(
34
+ "phasedRegistrationNames",
35
+ MapBuilder.of("bubbled", "onLoaded")))
36
+ .put(
37
+ "onClosed",
38
+ MapBuilder.of(
39
+ "phasedRegistrationNames",
40
+ MapBuilder.of("bubbled", "onClosed")))
41
+ .put(
42
+ "onSizeChanged",
43
+ MapBuilder.of(
44
+ "phasedRegistrationNames",
45
+ MapBuilder.of("bubbled", "onSizeChanged")))
46
+ .build();
47
+ }
48
+ }