infobip-mobile-messaging-react-native-plugin 7.0.0 → 7.0.2
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.
- package/README.md +5 -1
- package/android/build.gradle +1 -1
- package/android/src/main/java/org/infobip/reactlibrary/mobilemessaging/PermissionsRequestManager.java +158 -0
- package/android/src/main/java/org/infobip/reactlibrary/mobilemessaging/RNMMChatViewManager.java +5 -16
- package/android/src/main/java/org/infobip/reactlibrary/mobilemessaging/ReactNativeMobileMessagingModule.java +54 -16
- package/infobip-mobile-messaging-react-native-plugin-7.0.3.tgz +0 -0
- package/infobip-mobile-messaging-react-native-plugin.podspec +3 -3
- package/package.json +2 -2
- package/src/components/RNMMChatViewNativeComponent.js +58 -0
- package/{index.d.ts → src/index.d.ts} +0 -0
- package/{index.js → src/index.js} +15 -82
- package/infobip-mobile-messaging-react-native-plugin-6.4.5.tgz +0 -0
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ For iOS project:
|
|
|
22
22
|
For Android project:
|
|
23
23
|
- Android Studio (Bumblebee | 2021.1.1)
|
|
24
24
|
- Gradle (v7.3.3)
|
|
25
|
-
- Supported API Levels: 21 (Android 5.0 - [Lollipop](https://developer.android.com/about/versions/lollipop)) -
|
|
25
|
+
- Supported API Levels: 21 (Android 5.0 - [Lollipop](https://developer.android.com/about/versions/lollipop)) - 33 (Android 13.0)
|
|
26
26
|
|
|
27
27
|
## Quick start guide
|
|
28
28
|
|
|
@@ -96,6 +96,10 @@ This guide is designed to get you up and running with Mobile Messaging SDK plugi
|
|
|
96
96
|
> </manifest>
|
|
97
97
|
> ```
|
|
98
98
|
|
|
99
|
+
> ### Notice (when targeting Android 13):
|
|
100
|
+
> Starting from Android 13, Google requires to ask user for notification permission. Follow [this guide](https://github.com/infobip/mobile-messaging-react-native-plugin/wiki/Android-13-Notification-Permission-Handling) to make a permission request.
|
|
101
|
+
|
|
102
|
+
|
|
99
103
|
## Initialization configuration
|
|
100
104
|
|
|
101
105
|
Initialize Mobile Messaging React Native plugin, provide application configuration in init method:
|
package/android/build.gradle
CHANGED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
package org.infobip.reactlibrary.mobilemessaging;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.app.AlertDialog;
|
|
5
|
+
import android.content.DialogInterface;
|
|
6
|
+
import android.content.Intent;
|
|
7
|
+
import android.net.Uri;
|
|
8
|
+
|
|
9
|
+
import androidx.annotation.NonNull;
|
|
10
|
+
import androidx.annotation.StringRes;
|
|
11
|
+
import androidx.collection.ArraySet;
|
|
12
|
+
|
|
13
|
+
import com.facebook.react.modules.core.PermissionAwareActivity;
|
|
14
|
+
import com.facebook.react.modules.core.PermissionListener;
|
|
15
|
+
|
|
16
|
+
import org.infobip.mobile.messaging.R;
|
|
17
|
+
import org.infobip.mobile.messaging.logging.MobileMessagingLogger;
|
|
18
|
+
import org.infobip.mobile.messaging.permissions.PermissionsHelper;
|
|
19
|
+
|
|
20
|
+
import java.util.Set;
|
|
21
|
+
|
|
22
|
+
public class PermissionsRequestManager {
|
|
23
|
+
public interface PermissionsRequester {
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* This method will be called when required permissions are granted.
|
|
27
|
+
*/
|
|
28
|
+
void onPermissionGranted();
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Provide permissions which you need to request.
|
|
32
|
+
* <br>
|
|
33
|
+
* For example:
|
|
34
|
+
* <pre>
|
|
35
|
+
* {@code
|
|
36
|
+
* new String[]{Manifest.permission.CAMERA}
|
|
37
|
+
* </pre>
|
|
38
|
+
**/
|
|
39
|
+
@NonNull
|
|
40
|
+
String[] requiredPermissions();
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Should application show the dialog with information that not all required permissions are granted and button which leads to the settings for granting permissions after it was already shown once.
|
|
44
|
+
* Recommendations:
|
|
45
|
+
* - If you are asking for permissions by button tap, better to return true, so user will be informed, why an action can't be done, if the user didn't grant the permissions.
|
|
46
|
+
* - If you are asking for permissions on the application start, without any additional user actions, better to return false not to disturb the user constantly.
|
|
47
|
+
**/
|
|
48
|
+
boolean shouldShowPermissionsNotGrantedDialogIfShownOnce();
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* This method is for providing custom title for the permissions dialog.
|
|
52
|
+
*
|
|
53
|
+
* @return reference to string resource for permissions dialog title
|
|
54
|
+
*/
|
|
55
|
+
@StringRes
|
|
56
|
+
int permissionsNotGrantedDialogTitle();
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* This method is for providing custom message for the permissions dialog.
|
|
60
|
+
*
|
|
61
|
+
* @return reference to string resource for permissions dialog message
|
|
62
|
+
*/
|
|
63
|
+
@StringRes
|
|
64
|
+
int permissionsNotGrantedDialogMessage();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
protected PermissionsRequester permissionsRequester;
|
|
68
|
+
protected PermissionsHelper permissionsHelper;
|
|
69
|
+
protected static final int REQ_CODE_POST_NOTIFICATIONS_PERMISSIONS = 10000;
|
|
70
|
+
|
|
71
|
+
public PermissionsRequestManager(@NonNull PermissionsRequester permissionsRequester) {
|
|
72
|
+
this.permissionsRequester = permissionsRequester;
|
|
73
|
+
this.permissionsHelper = new PermissionsHelper();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public void onRequestPermissionsResult(String[] permissions, int[] grantResults) {
|
|
77
|
+
for (int result : grantResults) {
|
|
78
|
+
if (result == -1) return;
|
|
79
|
+
}
|
|
80
|
+
permissionsRequester.onPermissionGranted();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public boolean isRequiredPermissionsGranted(PermissionAwareActivity activity, PermissionListener listener) {
|
|
84
|
+
final Set<String> permissionsToAsk = new ArraySet<>();
|
|
85
|
+
final Set<String> neverAskPermissions = new ArraySet<>();
|
|
86
|
+
|
|
87
|
+
for (String permission : permissionsRequester.requiredPermissions()) {
|
|
88
|
+
if (!permissionsHelper.hasPermissionInManifest((Activity) activity, permission)) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
checkPermission(activity, permission, permissionsToAsk, neverAskPermissions);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (neverAskPermissions.size() > 0) {
|
|
95
|
+
showSettingsDialog(activity, new DialogInterface.OnClickListener() {
|
|
96
|
+
@Override
|
|
97
|
+
public void onClick(DialogInterface dialog, int which) {
|
|
98
|
+
openSettings((Activity) activity);
|
|
99
|
+
dialog.dismiss();
|
|
100
|
+
}
|
|
101
|
+
}, neverAskPermissions.toString());
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
String[] permissionsToAskArray = new String[permissionsToAsk.size()];
|
|
105
|
+
permissionsToAsk.toArray(permissionsToAskArray);
|
|
106
|
+
if (permissionsToAsk.size() > 0) {
|
|
107
|
+
activity.requestPermissions(permissionsToAskArray, REQ_CODE_POST_NOTIFICATIONS_PERMISSIONS, listener);
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
protected void checkPermission(PermissionAwareActivity activity, String permission, final Set<String> permissionsToAsk, final Set<String> neverAskPermissions) {
|
|
114
|
+
permissionsHelper.checkPermission((Activity) activity, permission, new PermissionsHelper.PermissionsRequestListener() {
|
|
115
|
+
@Override
|
|
116
|
+
public void onNeedPermission(Activity activity, String permission) {
|
|
117
|
+
permissionsToAsk.add(permission);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@Override
|
|
121
|
+
public void onPermissionPreviouslyDeniedWithNeverAskAgain(Activity activity, String permission) {
|
|
122
|
+
neverAskPermissions.add(permission);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@Override
|
|
126
|
+
public void onPermissionGranted(Activity activity, String permission) {
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
protected void showSettingsDialog(PermissionAwareActivity activity, DialogInterface.OnClickListener onPositiveButtonClick, String permission) {
|
|
132
|
+
if (!permissionsHelper.isPermissionSettingsDialogShown((Activity) activity, permission) ||
|
|
133
|
+
permissionsRequester.shouldShowPermissionsNotGrantedDialogIfShownOnce()) {
|
|
134
|
+
AlertDialog.Builder builder = new AlertDialog.Builder((Activity) activity)
|
|
135
|
+
.setMessage(permissionsRequester.permissionsNotGrantedDialogMessage())
|
|
136
|
+
.setTitle(permissionsRequester.permissionsNotGrantedDialogTitle())
|
|
137
|
+
.setPositiveButton(R.string.mm_button_settings, onPositiveButtonClick)
|
|
138
|
+
.setNegativeButton(R.string.mm_button_cancel, new DialogInterface.OnClickListener() {
|
|
139
|
+
@Override
|
|
140
|
+
public void onClick(DialogInterface dialog, int which) {
|
|
141
|
+
dialog.dismiss();
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
builder.show();
|
|
145
|
+
permissionsHelper.setPermissionSettingsDialogShown((Activity) activity, permission, true);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
protected void openSettings(Activity activity) {
|
|
150
|
+
MobileMessagingLogger.d("Will open application settings activity");
|
|
151
|
+
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
|
152
|
+
Uri uri = Uri.fromParts("package", activity.getPackageName(), null);
|
|
153
|
+
intent.setData(uri);
|
|
154
|
+
if (intent.resolveActivity(activity.getPackageManager()) != null) {
|
|
155
|
+
activity.startActivity(intent);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
package/android/src/main/java/org/infobip/reactlibrary/mobilemessaging/RNMMChatViewManager.java
CHANGED
|
@@ -8,17 +8,15 @@ import androidx.annotation.Nullable;
|
|
|
8
8
|
|
|
9
9
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
10
10
|
import com.facebook.react.bridge.ReadableArray;
|
|
11
|
-
import com.facebook.react.common.MapBuilder;
|
|
12
11
|
import com.facebook.react.uimanager.ThemedReactContext;
|
|
13
12
|
import com.facebook.react.uimanager.ViewGroupManager;
|
|
14
13
|
import com.facebook.react.uimanager.annotations.ReactProp;
|
|
15
14
|
|
|
16
|
-
import java.util.Map;
|
|
17
|
-
|
|
18
15
|
class RNMMChatViewManager extends ViewGroupManager<ReactChatView> {
|
|
16
|
+
public static final String COMMAND_ADD = "add";
|
|
17
|
+
public static final String COMMAND_REMOVE = "remove";
|
|
18
|
+
|
|
19
19
|
public static final String VIEW_GROUP_MANAGER_NAME = "RNMMChatView";
|
|
20
|
-
public static final int COMMAND_ADD = 1;
|
|
21
|
-
public static final int COMMAND_REMOVE = 2;
|
|
22
20
|
private ReactApplicationContext context;
|
|
23
21
|
|
|
24
22
|
@Nullable
|
|
@@ -41,26 +39,17 @@ class RNMMChatViewManager extends ViewGroupManager<ReactChatView> {
|
|
|
41
39
|
return chatView;
|
|
42
40
|
}
|
|
43
41
|
|
|
44
|
-
@Nullable
|
|
45
|
-
@Override
|
|
46
|
-
public Map<String, Integer> getCommandsMap() {
|
|
47
|
-
return MapBuilder.of(
|
|
48
|
-
"add", COMMAND_ADD,
|
|
49
|
-
"remove", COMMAND_REMOVE
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
42
|
@Override
|
|
54
43
|
public void receiveCommand(@NonNull ReactChatView root, String commandId, @Nullable ReadableArray args) {
|
|
55
44
|
super.receiveCommand(root, commandId, args);
|
|
56
|
-
|
|
45
|
+
|
|
57
46
|
if (args == null) {
|
|
58
47
|
Log.e(Utils.TAG, "RNMMChatViewManager received command without argumnents, Id: " + commandId);
|
|
59
48
|
return;
|
|
60
49
|
}
|
|
61
50
|
int reactNativeViewId = args.getInt(0);
|
|
62
51
|
|
|
63
|
-
switch (
|
|
52
|
+
switch (commandId) {
|
|
64
53
|
case COMMAND_ADD:
|
|
65
54
|
addChatFragment(root, reactNativeViewId);
|
|
66
55
|
break;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
package org.infobip.reactlibrary.mobilemessaging;
|
|
2
2
|
|
|
3
|
+
import android.Manifest;
|
|
3
4
|
import android.annotation.SuppressLint;
|
|
4
5
|
import android.app.Activity;
|
|
5
6
|
import android.app.Application;
|
|
@@ -10,6 +11,7 @@ import android.content.Intent;
|
|
|
10
11
|
import android.content.IntentFilter;
|
|
11
12
|
import android.graphics.Color;
|
|
12
13
|
import android.os.AsyncTask;
|
|
14
|
+
import android.os.Build;
|
|
13
15
|
import android.os.Bundle;
|
|
14
16
|
import android.util.Log;
|
|
15
17
|
|
|
@@ -28,6 +30,7 @@ import com.facebook.react.bridge.ReactMethod;
|
|
|
28
30
|
import com.facebook.react.bridge.ReadableArray;
|
|
29
31
|
import com.facebook.react.bridge.ReadableMap;
|
|
30
32
|
import com.facebook.react.modules.core.PermissionAwareActivity;
|
|
33
|
+
import com.facebook.react.modules.core.PermissionListener;
|
|
31
34
|
import com.google.android.gms.common.ConnectionResult;
|
|
32
35
|
import com.google.android.gms.common.GoogleApiAvailability;
|
|
33
36
|
|
|
@@ -76,22 +79,26 @@ import java.util.List;
|
|
|
76
79
|
import java.util.Map;
|
|
77
80
|
import java.util.concurrent.CopyOnWriteArrayList;
|
|
78
81
|
|
|
79
|
-
public class ReactNativeMobileMessagingModule extends ReactContextBaseJavaModule implements LifecycleEventListener,
|
|
82
|
+
public class ReactNativeMobileMessagingModule extends ReactContextBaseJavaModule implements LifecycleEventListener,
|
|
83
|
+
ActivityEventListener,
|
|
84
|
+
PermissionsRequestManager.PermissionsRequester,
|
|
85
|
+
PermissionListener {
|
|
80
86
|
public static final String MODULE_NAME = "ReactNativeMobileMessaging";
|
|
81
87
|
|
|
82
88
|
private final ReactApplicationContext reactContext;
|
|
83
89
|
|
|
84
90
|
private static volatile Boolean broadcastReceiverRegistered = false;
|
|
85
91
|
private static volatile Boolean pluginInitialized = false;
|
|
92
|
+
private PermissionsRequestManager permissionsRequestManager;
|
|
86
93
|
|
|
87
94
|
public ReactNativeMobileMessagingModule(ReactApplicationContext reactContext) {
|
|
88
95
|
super(reactContext);
|
|
89
|
-
|
|
90
96
|
while (getReactApplicationContext() == null) ;
|
|
91
97
|
reactContext = getReactApplicationContext();
|
|
92
98
|
|
|
93
99
|
this.reactContext = reactContext;
|
|
94
100
|
reactContext.addLifecycleEventListener(this);
|
|
101
|
+
permissionsRequestManager = new PermissionsRequestManager(this);
|
|
95
102
|
}
|
|
96
103
|
|
|
97
104
|
@Override
|
|
@@ -328,8 +335,8 @@ public class ReactNativeMobileMessagingModule extends ReactContextBaseJavaModule
|
|
|
328
335
|
PreferenceHelper.saveString(context, MobileMessagingProperty.SYSTEM_DATA_VERSION_POSTFIX, "reactNative " + configuration.reactNativePluginVersion);
|
|
329
336
|
|
|
330
337
|
MobileMessaging.Builder builder = new MobileMessaging.Builder(context)
|
|
331
|
-
.
|
|
332
|
-
.
|
|
338
|
+
.withoutRegisteringForRemoteNotifications()
|
|
339
|
+
.withApplicationCode(configuration.applicationCode);
|
|
333
340
|
|
|
334
341
|
if (configuration.privacySettings.userDataPersistingDisabled) {
|
|
335
342
|
builder.withoutStoringUserData();
|
|
@@ -717,20 +724,12 @@ public class ReactNativeMobileMessagingModule extends ReactContextBaseJavaModule
|
|
|
717
724
|
|
|
718
725
|
@ReactMethod
|
|
719
726
|
public void registerForAndroidRemoteNotifications() {
|
|
720
|
-
mobileMessaging().registerForRemoteNotifications((Activity) getPermissionAwareActivity());
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
private PermissionAwareActivity getPermissionAwareActivity() {
|
|
724
727
|
Activity activity = getCurrentActivity();
|
|
725
|
-
if (activity
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
throw new IllegalStateException(
|
|
730
|
-
"Tried to use permissions API but the host Activity doesn't"
|
|
731
|
-
+ " implement PermissionAwareActivity.");
|
|
728
|
+
if (activity != null && (activity instanceof PermissionAwareActivity)) {
|
|
729
|
+
permissionsRequestManager.isRequiredPermissionsGranted((PermissionAwareActivity) activity, this);
|
|
730
|
+
} else {
|
|
731
|
+
Log.e(Utils.TAG, "Cannot register for remote notifications because activity isn't exist");
|
|
732
732
|
}
|
|
733
|
-
return (PermissionAwareActivity) activity;
|
|
734
733
|
}
|
|
735
734
|
|
|
736
735
|
private static void runInBackground(final Runnable runnable) {
|
|
@@ -972,4 +971,43 @@ public class ReactNativeMobileMessagingModule extends ReactContextBaseJavaModule
|
|
|
972
971
|
}
|
|
973
972
|
};
|
|
974
973
|
}
|
|
974
|
+
|
|
975
|
+
// PermissionsRequester for Post Notifications Permission
|
|
976
|
+
|
|
977
|
+
@Override
|
|
978
|
+
public boolean onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
|
979
|
+
if (requestCode == PermissionsRequestManager.REQ_CODE_POST_NOTIFICATIONS_PERMISSIONS) {
|
|
980
|
+
permissionsRequestManager.onRequestPermissionsResult(permissions, grantResults);
|
|
981
|
+
}
|
|
982
|
+
return true;
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
@Override
|
|
986
|
+
public void onPermissionGranted() {
|
|
987
|
+
Log.i(Utils.TAG, "Post Notifications permission granted");
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
@NonNull
|
|
991
|
+
@Override
|
|
992
|
+
public String[] requiredPermissions() {
|
|
993
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
994
|
+
return new String[]{Manifest.permission.POST_NOTIFICATIONS};
|
|
995
|
+
}
|
|
996
|
+
return new String[0];
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
@Override
|
|
1000
|
+
public boolean shouldShowPermissionsNotGrantedDialogIfShownOnce() {
|
|
1001
|
+
return true;
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
@Override
|
|
1005
|
+
public int permissionsNotGrantedDialogTitle() {
|
|
1006
|
+
return org.infobip.mobile.messaging.resources.R.string.mm_post_notifications_settings_title;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
@Override
|
|
1010
|
+
public int permissionsNotGrantedDialogMessage() {
|
|
1011
|
+
return org.infobip.mobile.messaging.resources.R.string.mm_post_notifications_settings_message;
|
|
1012
|
+
}
|
|
975
1013
|
}
|
|
Binary file
|
|
@@ -19,8 +19,8 @@ Pod::Spec.new do |s|
|
|
|
19
19
|
s.requires_arc = true
|
|
20
20
|
|
|
21
21
|
s.dependency "React-Core"
|
|
22
|
-
s.dependency "MobileMessaging/Core", "10.
|
|
23
|
-
s.dependency "MobileMessaging/Geofencing", "10.
|
|
24
|
-
s.dependency "MobileMessaging/InAppChat", "10.
|
|
22
|
+
s.dependency "MobileMessaging/Core", "10.7.0"
|
|
23
|
+
s.dependency "MobileMessaging/Geofencing", "10.7.0"
|
|
24
|
+
s.dependency "MobileMessaging/InAppChat", "10.7.0"
|
|
25
25
|
|
|
26
26
|
end
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "infobip-mobile-messaging-react-native-plugin",
|
|
3
3
|
"title": "Infobip Mobile Messaging React Native Plugin",
|
|
4
|
-
"version": "7.0.
|
|
4
|
+
"version": "7.0.2",
|
|
5
5
|
"description": "Infobip Mobile Messaging React Native Plugin",
|
|
6
|
-
"main": "index.js",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
9
|
},
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import React, { FC, useLayoutEffect, useRef } from "react";
|
|
3
|
+
import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
|
|
4
|
+
import {findNodeHandle, requireNativeComponent} from 'react-native'
|
|
5
|
+
|
|
6
|
+
interface RNMMChatViewProps {
|
|
7
|
+
sendButtonColor: ?string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const RNMMChatViewCommands = codegenNativeCommands({
|
|
11
|
+
supportedCommands: ["add", "remove"],
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const ChatView: FC<RNMMChatViewProps> = props => {
|
|
15
|
+
const ref = useRef(null);
|
|
16
|
+
|
|
17
|
+
useLayoutEffect(() => {
|
|
18
|
+
// Not needed for iOS.
|
|
19
|
+
if (Platform.OS === "ios") return;
|
|
20
|
+
|
|
21
|
+
const chatViewRef = ref.current
|
|
22
|
+
// Nothing to do if there is no chatView reference.
|
|
23
|
+
if (!chatViewRef) return;
|
|
24
|
+
|
|
25
|
+
let addedViewId: ?number = null
|
|
26
|
+
|
|
27
|
+
// Fix for android, sometimes it can't get parent view, which is needed
|
|
28
|
+
// for proper relayout.
|
|
29
|
+
setTimeout(() => {
|
|
30
|
+
const viewId = findNodeHandle(chatViewRef);
|
|
31
|
+
if (viewId !== null && viewId !== undefined) {
|
|
32
|
+
RNMMChatViewCommands.add(chatViewRef, viewId);
|
|
33
|
+
console.log(`Adding android viewId: ${viewId}.`);
|
|
34
|
+
addedViewId = viewId;
|
|
35
|
+
}
|
|
36
|
+
}, 100);
|
|
37
|
+
|
|
38
|
+
return () => {
|
|
39
|
+
const viewId = addedViewId
|
|
40
|
+
if (viewId !== null && viewId !== undefined) {
|
|
41
|
+
console.log(`Removing android viewId: ${viewId}.`);
|
|
42
|
+
RNMMChatViewCommands.remove(chatViewRef, viewId);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}, []);
|
|
46
|
+
|
|
47
|
+
return <RNMMChatView {...props} ref={ref} />;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
ChatView.propTypes = {
|
|
51
|
+
/**
|
|
52
|
+
* Send button color can be set in hex format.
|
|
53
|
+
* If it's not provided, color from Infobip Portal widget configuration will be set.
|
|
54
|
+
*/
|
|
55
|
+
sendButtonColor: PropTypes.string,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const RNMMChatView = requireNativeComponent('RNMMChatView', ChatView);
|
|
File without changes
|
|
@@ -1,19 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
EmitterSubscription,
|
|
4
3
|
NativeEventEmitter,
|
|
5
4
|
NativeModules,
|
|
5
|
+
Permission,
|
|
6
6
|
PermissionsAndroid,
|
|
7
|
-
Platform,
|
|
8
|
-
requireNativeComponent,
|
|
9
|
-
Text,
|
|
10
|
-
View,
|
|
11
|
-
findNodeHandle,
|
|
12
|
-
UIManager,
|
|
13
|
-
EmitterSubscription,
|
|
7
|
+
Platform,
|
|
14
8
|
} from 'react-native';
|
|
15
|
-
import type {Rationale} from
|
|
16
|
-
|
|
9
|
+
import type {Rationale} from 'react-native/Libraries/PermissionsAndroid/PermissionsAndroid';
|
|
10
|
+
|
|
17
11
|
|
|
18
12
|
const { ReactNativeMobileMessaging, RNMMChat } = NativeModules;
|
|
19
13
|
|
|
@@ -248,7 +242,7 @@ class MobileMessaging {
|
|
|
248
242
|
});
|
|
249
243
|
}
|
|
250
244
|
|
|
251
|
-
config.reactNativePluginVersion = require('
|
|
245
|
+
config.reactNativePluginVersion = require('../package').version;
|
|
252
246
|
|
|
253
247
|
ReactNativeMobileMessaging.init(config, onSuccess, onError);
|
|
254
248
|
};
|
|
@@ -437,21 +431,21 @@ class MobileMessaging {
|
|
|
437
431
|
}
|
|
438
432
|
|
|
439
433
|
return {
|
|
440
|
-
find
|
|
434
|
+
find (messageId, onSuccess, onError = function() {}) {
|
|
441
435
|
ReactNativeMobileMessaging.defaultMessageStorage_find(messageId, onSuccess, onError);
|
|
442
436
|
},
|
|
443
437
|
|
|
444
|
-
findAll
|
|
438
|
+
findAll (onSuccess, onError = function() {}) {
|
|
445
439
|
ReactNativeMobileMessaging.defaultMessageStorage_findAll(onSuccess, onError);
|
|
446
440
|
},
|
|
447
441
|
|
|
448
|
-
delete
|
|
442
|
+
delete (messageId, onSuccess = function() {}, onError = function() {}) {
|
|
449
443
|
ReactNativeMobileMessaging.defaultMessageStorage_delete(messageId, onSuccess, onError);
|
|
450
444
|
},
|
|
451
445
|
|
|
452
|
-
deleteAll
|
|
446
|
+
deleteAll (onSuccess = function() {}, onError = function() {}) {
|
|
453
447
|
ReactNativeMobileMessaging.defaultMessageStorage_deleteAll(onSuccess, onError);
|
|
454
|
-
}
|
|
448
|
+
},
|
|
455
449
|
};
|
|
456
450
|
};
|
|
457
451
|
|
|
@@ -459,7 +453,7 @@ class MobileMessaging {
|
|
|
459
453
|
* Displays built-in error dialog so that user can resolve errors during SDK initialization.
|
|
460
454
|
*
|
|
461
455
|
* @name showDialogForError
|
|
462
|
-
* @param {
|
|
456
|
+
* @param {Number} errorCode to display dialog for
|
|
463
457
|
* @param {Function} onSuccess will be called upon completion
|
|
464
458
|
* @param {Function} onError will be called on error
|
|
465
459
|
*/
|
|
@@ -653,67 +647,6 @@ class MobileMessaging {
|
|
|
653
647
|
|
|
654
648
|
}
|
|
655
649
|
|
|
656
|
-
export
|
|
657
|
-
androidViewId;
|
|
658
|
-
|
|
659
|
-
componentDidMount() {
|
|
660
|
-
if (Platform.OS === "ios") {
|
|
661
|
-
this.add();
|
|
662
|
-
} else {
|
|
663
|
-
//fix for android, sometimes it can't get parent view, which is needed for properly relayout
|
|
664
|
-
let _this = this;
|
|
665
|
-
setTimeout(function() { _this.add(); }, 100);
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
componentWillUnmount() {
|
|
670
|
-
this.remove();
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
add = () => {
|
|
674
|
-
//not needed for iOS
|
|
675
|
-
if (Platform.OS === "ios") {
|
|
676
|
-
return;
|
|
677
|
-
}
|
|
678
|
-
this.androidViewId = findNodeHandle(this.refs.rnmmChatViewRef);
|
|
679
|
-
console.log('Native android viewId: ', this.androidViewId);
|
|
680
|
-
|
|
681
|
-
UIManager.dispatchViewManagerCommand(
|
|
682
|
-
this.androidViewId,
|
|
683
|
-
UIManager.RNMMChatView.Commands.add.toString(),
|
|
684
|
-
[this.androidViewId],
|
|
685
|
-
);
|
|
686
|
-
};
|
|
687
|
-
|
|
688
|
-
remove = () => {
|
|
689
|
-
//not needed for iOS
|
|
690
|
-
if (Platform.OS === "ios") {
|
|
691
|
-
return;
|
|
692
|
-
}
|
|
693
|
-
UIManager.dispatchViewManagerCommand(
|
|
694
|
-
this.androidViewId,
|
|
695
|
-
UIManager.RNMMChatView.Commands.remove.toString(),
|
|
696
|
-
[this.androidViewId],
|
|
697
|
-
);
|
|
698
|
-
};
|
|
699
|
-
|
|
700
|
-
render() {
|
|
701
|
-
return (
|
|
702
|
-
<RNMMChatView {...this.props}
|
|
703
|
-
ref="rnmmChatViewRef"
|
|
704
|
-
/>
|
|
705
|
-
);
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
ChatView.propTypes = {
|
|
710
|
-
/**
|
|
711
|
-
* Send button color can be set in hex format.
|
|
712
|
-
* If it's not provided, color from Infobip Portal widget configuration will be set.
|
|
713
|
-
*/
|
|
714
|
-
sendButtonColor: PropTypes.string,
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
export let RNMMChatView = requireNativeComponent('RNMMChatView', ChatView);
|
|
650
|
+
export {ChatView, RNMMChatView} from './components/RNMMChatViewNativeComponent';
|
|
718
651
|
|
|
719
|
-
export
|
|
652
|
+
export const mobileMessaging = new MobileMessaging();
|
|
Binary file
|