@trycourier/courier-react-native 2.0.0-beta7 → 2.0.0-beta8

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.
@@ -3,9 +3,9 @@ package com.courierreactnative
3
3
  import android.content.Context
4
4
  import android.graphics.Color
5
5
  import android.graphics.Typeface
6
+ import android.os.Handler
6
7
  import android.view.View
7
8
  import androidx.recyclerview.widget.DividerItemDecoration
8
- import com.courier.android.inbox.CourierInbox
9
9
  import com.courier.android.inbox.CourierInboxButtonStyles
10
10
  import com.courier.android.inbox.CourierInboxFont
11
11
  import com.courier.android.inbox.CourierInboxTheme
@@ -16,7 +16,7 @@ import com.facebook.react.uimanager.ThemedReactContext
16
16
  import com.facebook.react.uimanager.annotations.ReactProp
17
17
 
18
18
 
19
- class CourierReactNativeViewManager : SimpleViewManager<CourierInbox>() {
19
+ class CourierReactNativeViewManager : SimpleViewManager<ReactNativeCourierInbox>() {
20
20
 
21
21
  private companion object {
22
22
  const val ON_CLICK_MESSAGE_AT_INDEX = "courierClickMessageAtIndex"
@@ -26,16 +26,14 @@ class CourierReactNativeViewManager : SimpleViewManager<CourierInbox>() {
26
26
 
27
27
  override fun getName() = "CourierReactNativeView"
28
28
 
29
- override fun createViewInstance(reactContext: ThemedReactContext): CourierInbox {
30
- return CourierInbox(reactContext)
31
- }
29
+ override fun createViewInstance(reactContext: ThemedReactContext): ReactNativeCourierInbox = ReactNativeCourierInbox(reactContext)
32
30
 
33
31
  private val View.reactContext: ThemedReactContext get() = context as ThemedReactContext
34
32
 
35
33
  @ReactProp(name = "onClickInboxMessageAtIndex")
36
- fun setOnClickInboxMessageAtIndex(view: CourierInbox, callback: Boolean) {
34
+ fun setOnClickInboxMessageAtIndex(view: ReactNativeCourierInbox, callback: Boolean) {
37
35
 
38
- view.setOnClickMessageListener { message, index ->
36
+ view.inbox.setOnClickMessageListener { message, index ->
39
37
 
40
38
  val map = Arguments.createMap()
41
39
  map.putMap("message", message.toWritableMap())
@@ -48,9 +46,9 @@ class CourierReactNativeViewManager : SimpleViewManager<CourierInbox>() {
48
46
  }
49
47
 
50
48
  @ReactProp(name = "onClickInboxActionForMessageAtIndex")
51
- fun setOnClickInboxActionForMessageAtIndex(view: CourierInbox, callback: Boolean) {
49
+ fun setOnClickInboxActionForMessageAtIndex(view: ReactNativeCourierInbox, callback: Boolean) {
52
50
 
53
- view.setOnClickActionListener { action, message, index ->
51
+ view.inbox.setOnClickActionListener { action, message, index ->
54
52
 
55
53
  val map = Arguments.createMap()
56
54
  map.putMap("action", action.toWritableMap())
@@ -64,9 +62,9 @@ class CourierReactNativeViewManager : SimpleViewManager<CourierInbox>() {
64
62
  }
65
63
 
66
64
  @ReactProp(name = "onScrollInbox")
67
- fun setOnScrollInbox(view: CourierInbox, callback: Boolean) {
65
+ fun setOnScrollInbox(view: ReactNativeCourierInbox, callback: Boolean) {
68
66
 
69
- view.setOnScrollInboxListener { offsetInDp ->
67
+ view.inbox.setOnScrollInboxListener { offsetInDp ->
70
68
 
71
69
  val offset = Arguments.createMap()
72
70
  offset.putInt("y", offsetInDp)
@@ -82,9 +80,9 @@ class CourierReactNativeViewManager : SimpleViewManager<CourierInbox>() {
82
80
  }
83
81
 
84
82
  @ReactProp(name = "theme")
85
- fun setTheme(view: CourierInbox, theme: ReadableMap) {
86
- view.lightTheme = theme.getMap("light")?.toTheme(view) ?: CourierInboxTheme.DEFAULT_LIGHT
87
- view.darkTheme = theme.getMap("dark")?.toTheme(view) ?: CourierInboxTheme.DEFAULT_DARK
83
+ fun setTheme(view: ReactNativeCourierInbox, theme: ReadableMap) {
84
+ view.inbox.lightTheme = theme.getMap("light")?.toTheme(view) ?: CourierInboxTheme.DEFAULT_LIGHT
85
+ view.inbox.darkTheme = theme.getMap("dark")?.toTheme(view) ?: CourierInboxTheme.DEFAULT_DARK
88
86
  }
89
87
 
90
88
  private fun ReadableMap.toTheme(view: View): CourierInboxTheme {
@@ -0,0 +1,49 @@
1
+ package com.courierreactnative
2
+
3
+ import android.annotation.SuppressLint
4
+ import android.content.Context
5
+ import android.util.AttributeSet
6
+ import android.widget.FrameLayout
7
+ import com.courier.android.inbox.CourierInbox
8
+
9
+ class ReactNativeCourierInbox @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : FrameLayout(context, attrs, defStyleAttr) {
10
+
11
+ var inbox: CourierInbox
12
+
13
+ init {
14
+
15
+ // Create an instance of CourierInbox
16
+ inbox = CourierInbox(context, attrs, defStyleAttr)
17
+
18
+ // Set layout parameters to fill parent
19
+ val layoutParams = LayoutParams(
20
+ LayoutParams.MATCH_PARENT,
21
+ LayoutParams.MATCH_PARENT
22
+ )
23
+
24
+ // Apply the layout parameters
25
+ inbox.layoutParams = layoutParams
26
+
27
+ // Add it as a child of this custom view
28
+ addView(inbox)
29
+
30
+ }
31
+
32
+ // private var mRequestedLayout = false
33
+ //
34
+ // @SuppressLint("WrongCall")
35
+ // override fun requestLayout() {
36
+ // super.requestLayout()
37
+ // // We need to intercept this method because if we don't our children will never update
38
+ // // Check https://stackoverflow.com/questions/49371866/recyclerview-wont-update-child-until-i-scroll
39
+ // if (!mRequestedLayout) {
40
+ // mRequestedLayout = true
41
+ // post {
42
+ // mRequestedLayout = false
43
+ // layout(left, top, right, bottom)
44
+ // onLayout(false, left, top, right, bottom)
45
+ // }
46
+ // }
47
+ // }
48
+
49
+ }
@@ -65,10 +65,14 @@ NSUInteger notificationPresentationOptions = UNNotificationPresentationOptionNon
65
65
  }
66
66
  ];
67
67
 
68
- NSDictionary *pushNotification = [Courier formatPushNotificationWithContent:content];
69
- [[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationDelivered" object:nil userInfo:pushNotification];
68
+ dispatch_async(dispatch_get_main_queue(), ^{
70
69
 
71
- completionHandler(notificationPresentationOptions);
70
+ NSDictionary *pushNotification = [Courier formatPushNotificationWithContent:content];
71
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationDelivered" object:nil userInfo:pushNotification];
72
+
73
+ completionHandler(notificationPresentationOptions);
74
+
75
+ });
72
76
 
73
77
  }
74
78
 
@@ -86,11 +90,13 @@ NSUInteger notificationPresentationOptions = UNNotificationPresentationOptionNon
86
90
  }
87
91
  ];
88
92
 
89
- NSDictionary *pushNotification = [Courier formatPushNotificationWithContent:content];
90
- [[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationClicked" object:nil userInfo:pushNotification];
91
-
92
93
  dispatch_async(dispatch_get_main_queue(), ^{
94
+
95
+ NSDictionary *pushNotification = [Courier formatPushNotificationWithContent:content];
96
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotificationClicked" object:nil userInfo:pushNotification];
97
+
93
98
  completionHandler();
99
+
94
100
  });
95
101
 
96
102
  }
@@ -95,8 +95,13 @@ RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
95
95
  setInboxPaginationLimit: (double)limit
96
96
  )
97
97
 
98
- RCT_EXTERN__BLOCKING_SYNCHRONOUS_METHOD(
98
+ RCT_EXTERN_METHOD(
99
99
  registerPushNotificationClickedOnKilledState
100
100
  )
101
101
 
102
+ + (BOOL)requiresMainQueueSetup
103
+ {
104
+ return YES;
105
+ }
106
+
102
107
  @end
@@ -129,17 +129,13 @@ class CourierReactNativeModule: RCTEventEmitter {
129
129
 
130
130
  }
131
131
 
132
- @objc func registerPushNotificationClickedOnKilledState() -> String {
133
-
134
- let event = CourierReactNativeModule.PushEvents.CLICKED_EVENT
132
+ @objc func registerPushNotificationClickedOnKilledState() {
135
133
 
136
134
  sendMessage(
137
- name: event,
135
+ name: CourierReactNativeModule.PushEvents.CLICKED_EVENT,
138
136
  message: lastClickedMessage
139
137
  )
140
138
 
141
- return event
142
-
143
139
  }
144
140
 
145
141
  @objc(getNotificationPermissionStatus: withRejecter:)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/courier-react-native",
3
- "version": "2.0.0-beta7",
3
+ "version": "2.0.0-beta8",
4
4
  "description": "Inbox & Push Notifications for React Native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",