react-native-push-signal 0.1.1 → 0.1.3

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 (42) hide show
  1. package/README.md +14 -3
  2. package/README.ru.md +14 -3
  3. package/android/build.gradle +1 -0
  4. package/android/consumer-rules.pro +4 -0
  5. package/android/src/main/java/com/margelo/nitro/pushsignal/PushSignal.kt +1 -1
  6. package/android/src/main/java/com/margelo/nitro/pushsignal/PushSignalCenter.kt +170 -8
  7. package/android/src/main/java/com/margelo/nitro/pushsignal/PushSignalMessagingService.kt +5 -0
  8. package/ios/PushSignal.swift +1 -1
  9. package/ios/PushSignalCenter.swift +203 -10
  10. package/ios/PushSignalLaunchStore.m +15 -0
  11. package/lib/module/index.js.map +1 -1
  12. package/lib/module/pushSignal.js.map +1 -1
  13. package/lib/module/pushSignal.native.js +11 -2
  14. package/lib/module/pushSignal.native.js.map +1 -1
  15. package/lib/typescript/src/PushSignal.nitro.d.ts +2 -1
  16. package/lib/typescript/src/PushSignal.nitro.d.ts.map +1 -1
  17. package/lib/typescript/src/index.d.ts +1 -1
  18. package/lib/typescript/src/index.d.ts.map +1 -1
  19. package/lib/typescript/src/pushSignal.d.ts +2 -2
  20. package/lib/typescript/src/pushSignal.d.ts.map +1 -1
  21. package/lib/typescript/src/pushSignal.native.d.ts +2 -2
  22. package/lib/typescript/src/pushSignal.native.d.ts.map +1 -1
  23. package/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage.hpp +128 -0
  24. package/nitrogen/generated/android/c++/JHybridPushSignalSpec.cpp +5 -4
  25. package/nitrogen/generated/android/c++/JHybridPushSignalSpec.hpp +1 -1
  26. package/nitrogen/generated/android/kotlin/com/margelo/nitro/pushsignal/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage.kt +78 -0
  27. package/nitrogen/generated/android/kotlin/com/margelo/nitro/pushsignal/HybridPushSignalSpec.kt +2 -2
  28. package/nitrogen/generated/android/pushsignalOnLoad.cpp +2 -0
  29. package/nitrogen/generated/ios/PushSignal-Swift-Cxx-Bridge.cpp +25 -0
  30. package/nitrogen/generated/ios/PushSignal-Swift-Cxx-Bridge.hpp +91 -0
  31. package/nitrogen/generated/ios/c++/HybridPushSignalSpecSwift.hpp +1 -1
  32. package/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage.swift +61 -0
  33. package/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
  34. package/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_Promise_bool__.swift +66 -0
  35. package/nitrogen/generated/ios/swift/HybridPushSignalSpec.swift +1 -1
  36. package/nitrogen/generated/ios/swift/HybridPushSignalSpec_cxx.swift +26 -5
  37. package/nitrogen/generated/shared/c++/HybridPushSignalSpec.hpp +1 -1
  38. package/package.json +1 -1
  39. package/src/PushSignal.nitro.ts +5 -1
  40. package/src/index.tsx +1 -0
  41. package/src/pushSignal.native.tsx +18 -6
  42. package/src/pushSignal.tsx +2 -3
@@ -0,0 +1,46 @@
1
+ ///
2
+ /// Func_void_bool.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ /**
11
+ * Wraps a Swift `(_ value: Bool) -> Void` as a class.
12
+ * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
13
+ */
14
+ public final class Func_void_bool {
15
+ public typealias bridge = margelo.nitro.pushsignal.bridge.swift
16
+
17
+ private let closure: (_ value: Bool) -> Void
18
+
19
+ public init(_ closure: @escaping (_ value: Bool) -> Void) {
20
+ self.closure = closure
21
+ }
22
+
23
+ @inline(__always)
24
+ public func call(value: Bool) -> Void {
25
+ self.closure(value)
26
+ }
27
+
28
+ /**
29
+ * Casts this instance to a retained unsafe raw pointer.
30
+ * This acquires one additional strong reference on the object!
31
+ */
32
+ @inline(__always)
33
+ public func toUnsafe() -> UnsafeMutableRawPointer {
34
+ return Unmanaged.passRetained(self).toOpaque()
35
+ }
36
+
37
+ /**
38
+ * Casts an unsafe pointer to a `Func_void_bool`.
39
+ * The pointer has to be a retained opaque `Unmanaged<Func_void_bool>`.
40
+ * This removes one strong reference from the object!
41
+ */
42
+ @inline(__always)
43
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_bool {
44
+ return Unmanaged<Func_void_bool>.fromOpaque(pointer).takeRetainedValue()
45
+ }
46
+ }
@@ -0,0 +1,66 @@
1
+ ///
2
+ /// Func_void_std__shared_ptr_Promise_bool__.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ /**
11
+ * Wraps a Swift `(_ value: Promise<Bool>) -> Void` as a class.
12
+ * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
13
+ */
14
+ public final class Func_void_std__shared_ptr_Promise_bool__ {
15
+ public typealias bridge = margelo.nitro.pushsignal.bridge.swift
16
+
17
+ private let closure: (_ value: Promise<Bool>) -> Void
18
+
19
+ public init(_ closure: @escaping (_ value: Promise<Bool>) -> Void) {
20
+ self.closure = closure
21
+ }
22
+
23
+ @inline(__always)
24
+ public func call(value: bridge.std__shared_ptr_Promise_bool__) -> Void {
25
+ self.closure({ () -> Promise<Bool> in
26
+ let __promise = Promise<Bool>()
27
+ let __resolver = { (__result: Bool) in
28
+ __promise.resolve(withResult: __result)
29
+ }
30
+ let __rejecter = { (__error: Error) in
31
+ __promise.reject(withError: __error)
32
+ }
33
+ let __resolverCpp = { () -> bridge.Func_void_bool in
34
+ let __closureWrapper = Func_void_bool(__resolver)
35
+ return bridge.create_Func_void_bool(__closureWrapper.toUnsafe())
36
+ }()
37
+ let __rejecterCpp = { () -> bridge.Func_void_std__exception_ptr in
38
+ let __closureWrapper = Func_void_std__exception_ptr(__rejecter)
39
+ return bridge.create_Func_void_std__exception_ptr(__closureWrapper.toUnsafe())
40
+ }()
41
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_bool__(value)
42
+ __promiseHolder.addOnResolvedListenerCopy(__resolverCpp)
43
+ __promiseHolder.addOnRejectedListener(__rejecterCpp)
44
+ return __promise
45
+ }())
46
+ }
47
+
48
+ /**
49
+ * Casts this instance to a retained unsafe raw pointer.
50
+ * This acquires one additional strong reference on the object!
51
+ */
52
+ @inline(__always)
53
+ public func toUnsafe() -> UnsafeMutableRawPointer {
54
+ return Unmanaged.passRetained(self).toOpaque()
55
+ }
56
+
57
+ /**
58
+ * Casts an unsafe pointer to a `Func_void_std__shared_ptr_Promise_bool__`.
59
+ * The pointer has to be a retained opaque `Unmanaged<Func_void_std__shared_ptr_Promise_bool__>`.
60
+ * This removes one strong reference from the object!
61
+ */
62
+ @inline(__always)
63
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__shared_ptr_Promise_bool__ {
64
+ return Unmanaged<Func_void_std__shared_ptr_Promise_bool__>.fromOpaque(pointer).takeRetainedValue()
65
+ }
66
+ }
@@ -15,7 +15,7 @@ public protocol HybridPushSignalSpec_protocol: HybridObject {
15
15
  // Methods
16
16
  func initialize(config: AndroidFirebaseConfig) throws -> Promise<Void>
17
17
  func getCredentials() throws -> Promise<PushCredentials>
18
- func setOnMessage(callback: @escaping (_ message: PushMessage) -> Void) throws -> Void
18
+ func setOnMessage(callback: @escaping (_ message: PushMessage) -> Promise<Promise<Bool>>) throws -> Void
19
19
  func setOnNotificationPress(callback: @escaping (_ message: PushMessage) -> Void) throws -> Void
20
20
  }
21
21
 
@@ -163,12 +163,33 @@ open class HybridPushSignalSpec_cxx {
163
163
  }
164
164
 
165
165
  @inline(__always)
166
- public final func setOnMessage(callback: bridge.Func_void_PushMessage) -> bridge.Result_void_ {
166
+ public final func setOnMessage(callback: bridge.Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage) -> bridge.Result_void_ {
167
167
  do {
168
- try self.__implementation.setOnMessage(callback: { () -> (PushMessage) -> Void in
169
- let __wrappedFunction = bridge.wrap_Func_void_PushMessage(callback)
170
- return { (__message: PushMessage) -> Void in
171
- __wrappedFunction.call(__message)
168
+ try self.__implementation.setOnMessage(callback: { () -> (PushMessage) -> Promise<Promise<Bool>> in
169
+ let __wrappedFunction = bridge.wrap_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_bool_____PushMessage(callback)
170
+ return { (__message: PushMessage) -> Promise<Promise<Bool>> in
171
+ let __result = __wrappedFunction.call(__message)
172
+ return { () -> Promise<Promise<Bool>> in
173
+ let __promise = Promise<Promise<Bool>>()
174
+ let __resolver = { (__result: Promise<Bool>) in
175
+ __promise.resolve(withResult: __result)
176
+ }
177
+ let __rejecter = { (__error: Error) in
178
+ __promise.reject(withError: __error)
179
+ }
180
+ let __resolverCpp = { () -> bridge.Func_void_std__shared_ptr_Promise_bool__ in
181
+ let __closureWrapper = Func_void_std__shared_ptr_Promise_bool__(__resolver)
182
+ return bridge.create_Func_void_std__shared_ptr_Promise_bool__(__closureWrapper.toUnsafe())
183
+ }()
184
+ let __rejecterCpp = { () -> bridge.Func_void_std__exception_ptr in
185
+ let __closureWrapper = Func_void_std__exception_ptr(__rejecter)
186
+ return bridge.create_Func_void_std__exception_ptr(__closureWrapper.toUnsafe())
187
+ }()
188
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__shared_ptr_Promise_bool____(__result)
189
+ __promiseHolder.addOnResolvedListener(__resolverCpp)
190
+ __promiseHolder.addOnRejectedListener(__rejecterCpp)
191
+ return __promise
192
+ }()
172
193
  }
173
194
  }())
174
195
  return bridge.create_Result_void_()
@@ -59,7 +59,7 @@ namespace margelo::nitro::pushsignal {
59
59
  // Methods
60
60
  virtual std::shared_ptr<Promise<void>> initialize(const AndroidFirebaseConfig& config) = 0;
61
61
  virtual std::shared_ptr<Promise<PushCredentials>> getCredentials() = 0;
62
- virtual void setOnMessage(const std::function<void(const PushMessage& /* message */)>& callback) = 0;
62
+ virtual void setOnMessage(const std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<bool>>>>(const PushMessage& /* message */)>& callback) = 0;
63
63
  virtual void setOnNotificationPress(const std::function<void(const PushMessage& /* message */)>& callback) = 0;
64
64
 
65
65
  protected:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-push-signal",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Push",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -17,6 +17,10 @@ export interface PushMessage {
17
17
  data: Record<string, string>;
18
18
  }
19
19
 
20
+ export type OnMessageListener = (
21
+ message: PushMessage
22
+ ) => boolean | void | Promise<boolean | void>;
23
+
20
24
  export interface AndroidFirebaseConfig {
21
25
  project_id?: string;
22
26
  mobilesdk_app_id?: string;
@@ -30,6 +34,6 @@ export interface PushSignal extends HybridObject<{
30
34
  }> {
31
35
  initialize(config: AndroidFirebaseConfig): Promise<void>;
32
36
  getCredentials(): Promise<PushCredentials>;
33
- setOnMessage(callback: (message: PushMessage) => void): void;
37
+ setOnMessage(callback: (message: PushMessage) => Promise<boolean>): void;
34
38
  setOnNotificationPress(callback: (message: PushMessage) => void): void;
35
39
  }
package/src/index.tsx CHANGED
@@ -1,5 +1,6 @@
1
1
  export type {
2
2
  AndroidFirebaseConfig,
3
+ OnMessageListener,
3
4
  PushCredentials,
4
5
  PushEnvironment,
5
6
  PushMessage,
@@ -1,6 +1,7 @@
1
1
  import { NitroModules } from 'react-native-nitro-modules';
2
2
  import type {
3
3
  AndroidFirebaseConfig,
4
+ OnMessageListener,
4
5
  PushCredentials,
5
6
  PushMessage,
6
7
  PushSignal,
@@ -9,7 +10,7 @@ import type {
9
10
  const PushSignalHybridObject =
10
11
  NitroModules.createHybridObject<PushSignal>('PushSignal');
11
12
 
12
- const messageListeners = new Set<(message: PushMessage) => void>();
13
+ const messageListeners = new Set<OnMessageListener>();
13
14
  const pressListeners = new Set<(message: PushMessage) => void>();
14
15
  let nativeCallbacksBound = false;
15
16
 
@@ -20,8 +21,19 @@ function bindNativeCallbacks() {
20
21
 
21
22
  nativeCallbacksBound = true;
22
23
 
23
- PushSignalHybridObject.setOnMessage((message) => {
24
- messageListeners.forEach((listener) => listener(message));
24
+ PushSignalHybridObject.setOnMessage(async (message) => {
25
+ const listeners = [...messageListeners];
26
+ const results = await Promise.all(
27
+ listeners.map(async (listener) => {
28
+ try {
29
+ return await listener(message);
30
+ } catch {
31
+ return false;
32
+ }
33
+ })
34
+ );
35
+
36
+ return results.some((result) => result === true);
25
37
  });
26
38
 
27
39
  PushSignalHybridObject.setOnNotificationPress((message) => {
@@ -37,9 +49,7 @@ export function getCredentials(): Promise<PushCredentials> {
37
49
  return PushSignalHybridObject.getCredentials();
38
50
  }
39
51
 
40
- export function onMessage(
41
- listener: (message: PushMessage) => void
42
- ): () => void {
52
+ export function onMessage(listener: OnMessageListener): () => void {
43
53
  bindNativeCallbacks();
44
54
  messageListeners.add(listener);
45
55
  return () => {
@@ -56,3 +66,5 @@ export function onNotificationPress(
56
66
  pressListeners.delete(listener);
57
67
  };
58
68
  }
69
+
70
+ bindNativeCallbacks();
@@ -1,5 +1,6 @@
1
1
  import type {
2
2
  AndroidFirebaseConfig,
3
+ OnMessageListener,
3
4
  PushCredentials,
4
5
  PushMessage,
5
6
  } from './PushSignal.nitro';
@@ -12,9 +13,7 @@ export async function getCredentials(): Promise<PushCredentials> {
12
13
  throw new Error('Push credentials are not supported on web');
13
14
  }
14
15
 
15
- export function onMessage(
16
- _listener: (message: PushMessage) => void
17
- ): () => void {
16
+ export function onMessage(_listener: OnMessageListener): () => void {
18
17
  return () => {};
19
18
  }
20
19