@pinwheel/react-native-pinwheel 3.0.5 → 3.2.0-rc.0

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 (62) hide show
  1. package/PinwheelLinkSDKObjC/ObjCWrapper.xcframework/Info.plist +44 -0
  2. package/PinwheelLinkSDKObjC/ObjCWrapper.xcframework/ios-arm64/ObjCWrapper.framework/Headers/ObjCWrapper.h +18 -0
  3. package/PinwheelLinkSDKObjC/ObjCWrapper.xcframework/ios-arm64/ObjCWrapper.framework/Headers/PinwheelVCWrapper.h +14 -0
  4. package/PinwheelLinkSDKObjC/ObjCWrapper.xcframework/ios-arm64/ObjCWrapper.framework/Info.plist +0 -0
  5. package/PinwheelLinkSDKObjC/ObjCWrapper.xcframework/ios-arm64/ObjCWrapper.framework/Modules/module.modulemap +6 -0
  6. package/PinwheelLinkSDKObjC/ObjCWrapper.xcframework/ios-arm64/ObjCWrapper.framework/ObjCWrapper +0 -0
  7. package/PinwheelLinkSDKObjC/ObjCWrapper.xcframework/ios-arm64/ObjCWrapper.framework/README.md +15 -0
  8. package/PinwheelLinkSDKObjC/ObjCWrapper.xcframework/ios-arm64/ObjCWrapper.framework/_CodeSignature/CodeResources +146 -0
  9. package/PinwheelLinkSDKObjC/ObjCWrapper.xcframework/ios-arm64_x86_64-simulator/ObjCWrapper.framework/Headers/ObjCWrapper.h +18 -0
  10. package/PinwheelLinkSDKObjC/ObjCWrapper.xcframework/ios-arm64_x86_64-simulator/ObjCWrapper.framework/Headers/PinwheelVCWrapper.h +14 -0
  11. package/PinwheelLinkSDKObjC/ObjCWrapper.xcframework/ios-arm64_x86_64-simulator/ObjCWrapper.framework/Info.plist +0 -0
  12. package/PinwheelLinkSDKObjC/ObjCWrapper.xcframework/ios-arm64_x86_64-simulator/ObjCWrapper.framework/Modules/module.modulemap +6 -0
  13. package/PinwheelLinkSDKObjC/ObjCWrapper.xcframework/ios-arm64_x86_64-simulator/ObjCWrapper.framework/ObjCWrapper +0 -0
  14. package/PinwheelLinkSDKObjC/ObjCWrapper.xcframework/ios-arm64_x86_64-simulator/ObjCWrapper.framework/README.md +15 -0
  15. package/PinwheelLinkSDKObjC/ObjCWrapper.xcframework/ios-arm64_x86_64-simulator/ObjCWrapper.framework/_CodeSignature/CodeResources +146 -0
  16. package/RNPinwheelSDK.podspec +21 -17
  17. package/android/build.gradle +26 -35
  18. package/android/src/main/java/com/rtnpinwheel/Pinwheel.kt +103 -0
  19. package/android/src/main/java/com/{underdog_tech/react/PinwheelViewManager.kt → rtnpinwheel/PinwheelEventsModule.kt} +55 -120
  20. package/android/src/main/java/com/rtnpinwheel/PinwheelManager.kt +54 -0
  21. package/android/src/main/java/com/{underdog_tech/react → rtnpinwheel}/PinwheelPackage.kt +7 -9
  22. package/ios/RTNPinwheelEvents.h +13 -0
  23. package/ios/{RNTPinwheelEvents.m → RTNPinwheelEvents.mm} +15 -3
  24. package/ios/RTNPinwheelManager.mm +21 -0
  25. package/ios/RTNPinwheelView.h +17 -0
  26. package/ios/RTNPinwheelView.mm +102 -0
  27. package/package.json +32 -9
  28. package/src/NativePinwheelEvents.ts +62 -0
  29. package/src/Pinwheel.tsx +80 -0
  30. package/src/PinwheelEvents.ts +23 -0
  31. package/src/RTNPinwheelNativeComponent.ts +15 -0
  32. package/src/client-events/client.ts +17 -0
  33. package/src/client-events/registry/v2.3.ts +166 -0
  34. package/src/client-events/registry/v3.ts +47 -0
  35. package/src/client-events/utils.ts +12 -0
  36. package/src/index.ts +3 -0
  37. package/.vscode/settings.json +0 -4
  38. package/CHANGELOG.md +0 -152
  39. package/android/src/main/AndroidManifest.xml +0 -6
  40. package/android/src/main/java/com/underdog_tech/react/RNTPinwheelEvents.kt +0 -51
  41. package/dist/client-events/client.d.ts +0 -10
  42. package/dist/client-events/client.js +0 -1
  43. package/dist/client-events/registry/v2.3.d.ts +0 -125
  44. package/dist/client-events/registry/v2.3.js +0 -1
  45. package/dist/client-events/registry/v3.d.ts +0 -25
  46. package/dist/client-events/registry/v3.js +0 -4
  47. package/dist/client-events/utils.d.ts +0 -9
  48. package/dist/client-events/utils.js +0 -1
  49. package/dist/constants.d.ts +0 -4
  50. package/dist/constants.js +0 -4
  51. package/dist/index.d.ts +0 -5
  52. package/dist/index.js +0 -49
  53. package/dist/pinwheel-view.d.ts +0 -6
  54. package/dist/pinwheel-view.js +0 -2
  55. package/dist/pinwheel-wrapper.android.d.ts +0 -4
  56. package/dist/pinwheel-wrapper.android.js +0 -33
  57. package/dist/pinwheel-wrapper.ios.d.ts +0 -4
  58. package/dist/pinwheel-wrapper.ios.js +0 -17
  59. package/ios/RNTPinwheelEvents.h +0 -9
  60. package/ios/RNTPinwheelManager.m +0 -21
  61. package/ios/RNTPinwheelView.h +0 -12
  62. package/ios/RNTPinwheelView.m +0 -65
@@ -0,0 +1,103 @@
1
+ package com.rtnpinwheel
2
+
3
+ import android.content.Context
4
+ import android.graphics.Color
5
+ import android.os.Handler
6
+ import android.os.Looper
7
+ import android.util.AttributeSet
8
+ import android.util.Log
9
+ import android.view.Choreographer
10
+ import android.view.View
11
+ import android.widget.FrameLayout
12
+ import androidx.fragment.app.FragmentActivity
13
+ import com.facebook.react.bridge.ReactApplicationContext
14
+ import com.underdog_tech.pinwheel_android.PinwheelEventListener
15
+ import com.underdog_tech.pinwheel_android.PinwheelFragment
16
+ import com.facebook.react.uimanager.ThemedReactContext
17
+
18
+ class Pinwheel : FrameLayout {
19
+ private var token: String? = null
20
+ private var pinwheelFragment: PinwheelFragment? = null
21
+ private var pinwheelEventListener: PinwheelEventListener? = null
22
+
23
+ constructor(context: Context) : super(context) {
24
+ init()
25
+ }
26
+
27
+ constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
28
+ init()
29
+ }
30
+
31
+ constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
32
+ context,
33
+ attrs,
34
+ defStyleAttr
35
+ ) {
36
+ init()
37
+ }
38
+
39
+ private fun init() {
40
+ // Match background color of Link. We may want to have a loader here in the future.
41
+ setBackgroundColor(Color.WHITE)
42
+ }
43
+
44
+ fun setToken(token: String?) {
45
+ this.token = token
46
+ }
47
+
48
+ private fun createFragment() {
49
+ Handler(Looper.getMainLooper()).post {
50
+ this.token?.let {
51
+ val pinwheelFragment = PinwheelFragment.newInstance(it, "react native", "3.1.0")
52
+ pinwheelEventListener?.let { listener ->
53
+ pinwheelFragment.pinwheelEventListener = listener
54
+ }
55
+ val reactContext = context as ThemedReactContext
56
+ val activity = reactContext.currentActivity as? FragmentActivity
57
+
58
+ activity?.supportFragmentManager
59
+ ?.beginTransaction()
60
+ ?.replace(id, pinwheelFragment, id.toString())
61
+ ?.commit()
62
+
63
+ this.pinwheelFragment = pinwheelFragment
64
+ }
65
+ }
66
+
67
+ Handler(Looper.getMainLooper()).post {
68
+ Choreographer.getInstance().postFrameCallback(object: Choreographer.FrameCallback {
69
+ override fun doFrame(frameTimeNanos: Long) {
70
+ setupLayoutSizing()
71
+ // TODO: functionality works without this line, but it was present in the old SDK code
72
+ // view.viewTreeObserver.dispatchOnGlobalLayout()
73
+ Choreographer.getInstance().postFrameCallback(this)
74
+ }
75
+ })
76
+ }
77
+ }
78
+
79
+ fun setupLayoutSizing() {
80
+ val width = this.width
81
+ val height = this.height
82
+ this.measure(
83
+ View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
84
+ View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY))
85
+
86
+ this.layout(0, 0, width, height)
87
+ }
88
+
89
+ override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
90
+ super.onLayout(changed, left, top, right, bottom)
91
+
92
+ if (changed && this.pinwheelFragment == null) {
93
+ createFragment()
94
+ }
95
+ }
96
+
97
+ fun setPinwheelEventListener(listener: PinwheelEventListener) {
98
+ pinwheelEventListener = listener
99
+ pinwheelFragment?.let {
100
+ it.pinwheelEventListener = listener
101
+ }
102
+ }
103
+ }
@@ -1,24 +1,16 @@
1
- package com.underdog_tech.react
1
+ package com.rtnpinwheel
2
2
 
3
- import android.view.Choreographer
4
- import android.view.View
5
- import android.view.ViewGroup
6
- import android.widget.FrameLayout
7
- import androidx.fragment.app.FragmentActivity
8
3
  import com.facebook.react.bridge.Arguments
9
4
  import com.facebook.react.bridge.ReactApplicationContext
10
- import com.facebook.react.bridge.ReadableArray
5
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
6
+ import com.facebook.react.bridge.ReactMethod
11
7
  import com.facebook.react.bridge.WritableMap
12
8
  import com.facebook.react.bridge.WritableNativeMap
9
+ import com.facebook.react.module.annotations.ReactModule
13
10
  import com.facebook.react.modules.core.DeviceEventManagerModule
14
- import com.facebook.react.uimanager.ThemedReactContext
15
- import com.facebook.react.uimanager.ViewGroupManager
16
- import com.facebook.react.uimanager.annotations.ReactPropGroup
17
- import com.facebook.react.uimanager.annotations.ReactProp
18
- import com.underdog_tech.pinwheel_android.PinwheelFragment
19
11
  import com.underdog_tech.pinwheel_android.PinwheelEventListener
20
- import com.underdog_tech.pinwheel_android.model.PinwheelEventType
21
12
  import com.underdog_tech.pinwheel_android.model.PinwheelEventPayload
13
+ import com.underdog_tech.pinwheel_android.model.PinwheelEventType
22
14
  import com.underdog_tech.pinwheel_android.model.PinwheelInputAllocationPayload
23
15
  import com.underdog_tech.pinwheel_android.model.PinwheelTarget
24
16
  import com.underdog_tech.pinwheel_android.model.PinwheelAllocation
@@ -32,6 +24,56 @@ import com.underdog_tech.pinwheel_android.model.PinwheelLoginAttemptPayload
32
24
  import com.underdog_tech.pinwheel_android.model.PinwheelDDFormCreatePayload
33
25
  import com.underdog_tech.pinwheel_android.model.PinwheelScreenTransitionPayload
34
26
 
27
+ @ReactModule(name = PinwheelEventsModule.NAME)
28
+ class PinwheelEventsModule(private val context: ReactApplicationContext) : ReactContextBaseJavaModule(context), PinwheelEventListener {
29
+ init {
30
+ Companion.context = context
31
+ }
32
+
33
+ override fun getName(): String = NAME
34
+
35
+ @ReactMethod
36
+ fun setListener() {
37
+ hasListeners = true;
38
+ }
39
+
40
+ @ReactMethod
41
+ fun removeListener() {
42
+ hasListeners = false;
43
+ }
44
+
45
+ @ReactMethod
46
+ fun addListener(eventName: String) {
47
+ // Keep: Required for RN built in Event Emitter Calls.
48
+ }
49
+
50
+ @ReactMethod
51
+ fun removeListeners(count: Int) {
52
+ // Keep: Required for RN built in Event Emitter Calls.
53
+ }
54
+
55
+ override fun onEvent(eventName: PinwheelEventType, payload: PinwheelEventPayload?) {
56
+ if (!hasListeners) return
57
+
58
+ val params = WritableNativeMap()
59
+ params.putString("name", eventName.toString())
60
+ if (payload != null) {
61
+ params.putMap("payload", payload.toWritableMap())
62
+ }
63
+
64
+ context
65
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
66
+ .emit(Companion.PinwheelEventName, params)
67
+ }
68
+
69
+ companion object {
70
+ const val NAME = "RTNPinwheelEvents"
71
+ const val PinwheelEventName = "PINWHEEL_EVENT"
72
+ private var context: ReactApplicationContext? = null
73
+ private var hasListeners = false;
74
+ }
75
+ }
76
+
35
77
  fun PinwheelTarget.toWritableMap(): WritableMap {
36
78
  return Arguments.createMap().apply {
37
79
  putString("accountType", this@toWritableMap.accountType)
@@ -100,110 +142,3 @@ fun PinwheelEventPayload.toWritableMap(): WritableMap = when (this) {
100
142
  }
101
143
  else -> throw IllegalArgumentException("Unsupported PinwheelEventPayload type")
102
144
  }
103
-
104
- class PinwheelViewManager(
105
- private val reactContext: ReactApplicationContext
106
- ) : ViewGroupManager<FrameLayout>(), PinwheelEventListener {
107
- private var propWidth: Int? = reactContext.resources.displayMetrics.widthPixels
108
- private var propHeight: Int? = reactContext.resources.displayMetrics.heightPixels
109
- private var token: String? = null
110
-
111
- override fun getName() = REACT_CLASS
112
-
113
- /**
114
- * Return a FrameLayout which will later hold the Fragment
115
- */
116
- override fun createViewInstance(reactContext: ThemedReactContext): FrameLayout {
117
- return FrameLayout(reactContext)
118
- }
119
-
120
- /**
121
- * Map the "create" command to an integer
122
- */
123
- override fun getCommandsMap() = mapOf("create" to COMMAND_CREATE)
124
-
125
- /**
126
- * Handle "create" command (called from JS) and call createFragment method
127
- */
128
- override fun receiveCommand(
129
- root: FrameLayout,
130
- commandId: String,
131
- args: ReadableArray?
132
- ) {
133
- super.receiveCommand(root, commandId, args)
134
- val reactNativeViewId = requireNotNull(args).getInt(0)
135
-
136
- when (commandId.toInt()) {
137
- COMMAND_CREATE -> createFragment(root, reactNativeViewId)
138
- }
139
- }
140
-
141
- @ReactPropGroup(names = ["width", "height"], customType = "Style")
142
- fun setStyle(view: FrameLayout, index: Int, value: Int) {
143
- if (index == 0) propWidth = value
144
- if (index == 1) propHeight = value
145
- }
146
-
147
- @ReactProp(name="token")
148
- fun setToken(view: FrameLayout, token: String) {
149
- this.token = token
150
- }
151
-
152
- /**
153
- * Replace your React Native view with a custom fragment
154
- */
155
- fun createFragment(root: FrameLayout, reactNativeViewId: Int) {
156
- val parentView = root.findViewById<ViewGroup>(reactNativeViewId)
157
- setupLayout(parentView)
158
-
159
-
160
- this.token?.let {
161
- val pinwheelFragment = PinwheelFragment.newInstance(it, "react native", "3.0.5")
162
- pinwheelFragment.pinwheelEventListener = this
163
- val activity = reactContext.currentActivity as FragmentActivity
164
- activity.supportFragmentManager
165
- .beginTransaction()
166
- .replace(reactNativeViewId, pinwheelFragment, reactNativeViewId.toString())
167
- .commit()
168
- }
169
- }
170
-
171
- fun setupLayout(view: View) {
172
- Choreographer.getInstance().postFrameCallback(object: Choreographer.FrameCallback {
173
- override fun doFrame(frameTimeNanos: Long) {
174
- manuallyLayoutChildren(view)
175
- view.viewTreeObserver.dispatchOnGlobalLayout()
176
- Choreographer.getInstance().postFrameCallback(this)
177
- }
178
- })
179
- }
180
-
181
- override fun onEvent(eventName: PinwheelEventType, payload: PinwheelEventPayload?) {
182
- val params = WritableNativeMap()
183
- params.putString("name", eventName.toString())
184
- params.putMap("payload", payload?.toWritableMap())
185
- reactContext
186
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
187
- .emit("PINWHEEL_EVENT", params)
188
- }
189
-
190
- /**
191
- * Layout all children properly
192
- */
193
- private fun manuallyLayoutChildren(view: View) {
194
- // propWidth and propHeight coming from react-native props
195
- val width = requireNotNull(propWidth)
196
- val height = requireNotNull(propHeight)
197
-
198
- view.measure(
199
- View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
200
- View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY))
201
-
202
- view.layout(0, 0, width, height)
203
- }
204
-
205
- companion object {
206
- private const val REACT_CLASS = "RNTPinwheel"
207
- private const val COMMAND_CREATE = 1
208
- }
209
- }
@@ -0,0 +1,54 @@
1
+ package com.rtnpinwheel
2
+
3
+ import android.view.ViewGroup
4
+ import com.facebook.react.bridge.ReactApplicationContext
5
+ import com.facebook.react.module.annotations.ReactModule
6
+ import com.facebook.react.uimanager.SimpleViewManager
7
+ import com.facebook.react.uimanager.ThemedReactContext
8
+ import com.facebook.react.uimanager.ViewManagerDelegate
9
+ import com.facebook.react.uimanager.annotations.ReactProp
10
+ import com.facebook.react.uimanager.annotations.ReactPropGroup
11
+ import com.facebook.react.viewmanagers.RTNPinwheelManagerInterface
12
+ import com.facebook.react.viewmanagers.RTNPinwheelManagerDelegate
13
+
14
+ @ReactModule(name = PinwheelManager.NAME)
15
+ class PinwheelManager(private val reactContext: ReactApplicationContext) :
16
+ SimpleViewManager<Pinwheel>(),
17
+ RTNPinwheelManagerInterface<Pinwheel> {
18
+
19
+ private val delegate: RTNPinwheelManagerDelegate<Pinwheel, PinwheelManager> = RTNPinwheelManagerDelegate(this)
20
+ private var propWidth: Int? = null
21
+ private var propHeight: Int? = null
22
+
23
+ override fun getDelegate(): ViewManagerDelegate<Pinwheel> = delegate
24
+
25
+ override fun getName(): String = NAME
26
+
27
+ override fun createViewInstance(context: ThemedReactContext): Pinwheel {
28
+ val view = Pinwheel(context)
29
+ (reactContext.getNativeModule(PinwheelEventsModule::class.java) as? PinwheelEventsModule)?.let { module ->
30
+ view.setPinwheelEventListener(module)
31
+ }
32
+
33
+ return view
34
+ }
35
+
36
+ @ReactProp(name = "token")
37
+ override fun setToken(view: Pinwheel, token: String?) {
38
+ view.setToken(token)
39
+ }
40
+
41
+ @ReactPropGroup(names = ["width", "height"], customType = "Style")
42
+ fun setStyle(view: Pinwheel, index: Int, value: Int) {
43
+ if (index == 0) propWidth = value
44
+ if (index == 1) propHeight = value
45
+ view.layoutParams = ViewGroup.LayoutParams(
46
+ if (propWidth != null) propWidth!! else ViewGroup.LayoutParams.WRAP_CONTENT,
47
+ if (propHeight != null) propHeight!! else ViewGroup.LayoutParams.WRAP_CONTENT
48
+ )
49
+ }
50
+
51
+ companion object {
52
+ const val NAME = "RTNPinwheel"
53
+ }
54
+ }
@@ -1,16 +1,14 @@
1
- package com.underdog_tech.react
1
+ package com.rtnpinwheel
2
2
 
3
3
  import com.facebook.react.ReactPackage
4
- import com.facebook.react.bridge.ReactApplicationContext
5
4
  import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
6
  import com.facebook.react.uimanager.ViewManager
7
7
 
8
8
  class PinwheelPackage : ReactPackage {
9
- override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
10
- return listOf(RNTPinwheelEvents(reactContext)).toMutableList()
11
- }
12
-
13
- override fun createViewManagers(
14
- reactContext: ReactApplicationContext
15
- ) = listOf(PinwheelViewManager(reactContext))
9
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> =
10
+ listOf(PinwheelManager(reactContext))
11
+
12
+ override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> =
13
+ listOf(PinwheelEventsModule(reactContext))
16
14
  }
@@ -0,0 +1,13 @@
1
+ #import <RTNPinwheelSpec/RTNPinwheelSpec.h>
2
+ #import <React/RCTEventEmitter.h>
3
+
4
+ NS_ASSUME_NONNULL_BEGIN
5
+
6
+ @interface RTNPinwheelEvents : RCTEventEmitter <NativePinwheelEventsSpec>
7
+
8
+ + (instancetype)sharedInstance;
9
+ - (void)handlePinwheelEvent:(NSDictionary<NSString *, id> *)payload;
10
+
11
+ @end
12
+
13
+ NS_ASSUME_NONNULL_END
@@ -1,6 +1,6 @@
1
- #import "RNTPinwheelEvents.h"
1
+ #import "RTNPinwheelEvents.h"
2
2
 
3
- @implementation RNTPinwheelEvents
3
+ @implementation RTNPinwheelEvents
4
4
  {
5
5
  bool hasListeners; // This is an instance variable declaration.
6
6
  }
@@ -11,7 +11,7 @@ RCT_EXPORT_MODULE();
11
11
  }
12
12
 
13
13
  + (instancetype)sharedInstance {
14
- static RNTPinwheelEvents *sharedInstance = nil;
14
+ static RTNPinwheelEvents *sharedInstance = nil;
15
15
  static dispatch_once_t onceToken;
16
16
  dispatch_once(&onceToken, ^{
17
17
  sharedInstance = [[super allocWithZone:NULL] init];
@@ -59,4 +59,16 @@ RCT_EXPORT_MODULE();
59
59
  return @[@"PINWHEEL_EVENT"]; // Add more event names here.
60
60
  }
61
61
 
62
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params {
63
+ return std::make_shared<facebook::react::NativePinwheelEventsSpecJSI>(params);
64
+ }
65
+
66
+ - (void)removeListener {
67
+ [self stopObserving];
68
+ }
69
+
70
+ - (void)setListener {
71
+ [self startObserving];
72
+ }
73
+
62
74
  @end
@@ -0,0 +1,21 @@
1
+ #import <React/RCTLog.h>
2
+ #import <React/RCTUIManager.h>
3
+ #import <React/RCTViewManager.h>
4
+ #import "RTNPinwheelView.h"
5
+
6
+ @interface RTNPinwheelManager : RCTViewManager
7
+ @end
8
+
9
+ @implementation RTNPinwheelManager
10
+
11
+ RCT_EXPORT_MODULE(RTNPinwheelView)
12
+
13
+ - (UIView *)view
14
+ {
15
+ RTNPinwheelView *pv = [[RTNPinwheelView alloc] init];
16
+ return pv;
17
+ }
18
+
19
+ RCT_EXPORT_VIEW_PROPERTY(token, NSString);
20
+
21
+ @end
@@ -0,0 +1,17 @@
1
+ #import <React/RCTViewComponentView.h>
2
+ #import <UIKit/UIKit.h>
3
+ #import <ObjCWrapper/PinwheelVCWrapper.h>
4
+
5
+ NS_ASSUME_NONNULL_BEGIN
6
+
7
+ @interface RTNPinwheelView : RCTViewComponentView <PinwheelVCWrapperDelegate>
8
+
9
+ @property (nonatomic, strong) PinwheelVCWrapper *pinwheelWrapperVC;
10
+ @property (nonatomic, assign) NSString *token;
11
+
12
+ - (instancetype)initWithFrame:(CGRect)frame token:(NSString *)token;
13
+
14
+ @end
15
+
16
+ NS_ASSUME_NONNULL_END
17
+
@@ -0,0 +1,102 @@
1
+ #import "RTNPinwheelView.h"
2
+
3
+ #import <react/renderer/components/RTNPinwheelSpec/ComponentDescriptors.h>
4
+ #import <react/renderer/components/RTNPinwheelSpec/EventEmitters.h>
5
+ #import <react/renderer/components/RTNPinwheelSpec/Props.h>
6
+ #import <react/renderer/components/RTNPinwheelSpec/RCTComponentViewHelpers.h>
7
+
8
+ #import "RTNPinwheelEvents.h"
9
+ #import "RCTFabricComponentsPlugins.h"
10
+
11
+ using namespace facebook::react;
12
+
13
+ @interface RTNPinwheelView () <RCTRTNPinwheelViewProtocol>
14
+ @end
15
+
16
+ @implementation RTNPinwheelView
17
+
18
+ + (ComponentDescriptorProvider)componentDescriptorProvider
19
+ {
20
+ return concreteComponentDescriptorProvider<RTNPinwheelComponentDescriptor>();
21
+ }
22
+
23
+ - (instancetype)initWithFrame:(CGRect)frame {
24
+ if ((self = [super initWithFrame:frame])) {
25
+ [self initPinwheelWrapperVC];
26
+ }
27
+ return self;
28
+ }
29
+
30
+ - (instancetype)initWithFrame:(CGRect)frame token:(NSString *)token {
31
+ if ((self = [super initWithFrame:frame])) {
32
+ _token = token;
33
+ }
34
+ return self;
35
+ }
36
+
37
+ - (void)initPinwheelWrapperVC {
38
+ if (self.token != nil && self.pinwheelWrapperVC == nil) {
39
+ self.pinwheelWrapperVC = [[PinwheelVCWrapper alloc] initWithToken:self.token delegate:self sdk:@"react native" version: @"3.0.5"];
40
+ [self addSubview:self.pinwheelWrapperVC.view];
41
+ }
42
+ }
43
+
44
+ - (void)setToken:(NSString *)newToken {
45
+ if (![_token isEqualToString:newToken]) {
46
+ _token = newToken;
47
+ [self initPinwheelWrapperVC];
48
+ }
49
+ }
50
+
51
+ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
52
+ {
53
+ const auto &oldViewProps = *std::static_pointer_cast<RTNPinwheelProps const>(_props);
54
+ const auto &newViewProps = *std::static_pointer_cast<RTNPinwheelProps const>(props);
55
+
56
+ if (oldViewProps.token != newViewProps.token) {
57
+ NSString* convertedToken = [NSString stringWithUTF8String:newViewProps.token.c_str()];
58
+ [self setToken:convertedToken];
59
+ }
60
+
61
+ [super updateProps:props oldProps:oldProps];
62
+ }
63
+
64
+ - (void)layoutSubviews
65
+ {
66
+ [super layoutSubviews];
67
+ self.pinwheelWrapperVC.view.frame = self.bounds;
68
+ }
69
+
70
+ - (void)onEventWithName:(NSString *)name event:(NSDictionary<NSString *, id> *)event {
71
+ NSLog(@"%@", name);
72
+ NSDictionary *dataToSend = @{@"name": name, @"payload": event};
73
+ [RTNPinwheelEvents.sharedInstance handlePinwheelEvent:dataToSend];
74
+ }
75
+
76
+ - (void)onExit:(NSDictionary<NSString *, id> *)error {
77
+ NSLog(@"%@", error);
78
+ }
79
+
80
+ - (void)onSuccess:(NSDictionary<NSString *, id> *)result {
81
+ NSLog(@"%@", result);
82
+ }
83
+
84
+ - (void)onLogin:(NSDictionary<NSString *, id> *)result {
85
+ NSLog(@"%@", result);
86
+ }
87
+
88
+ - (void)onLoginAttempt:(NSDictionary<NSString *, id> *)result {
89
+ NSLog(@"%@", result);
90
+ }
91
+
92
+ - (void)onError:(NSDictionary<NSString *, id> *)error {
93
+ NSLog(@"%@", error);
94
+ }
95
+
96
+ @end
97
+
98
+ Class<RCTComponentViewProtocol> RTNPinwheelCls(void)
99
+ {
100
+ return RTNPinwheelView.class;
101
+ }
102
+
package/package.json CHANGED
@@ -1,24 +1,47 @@
1
1
  {
2
2
  "name": "@pinwheel/react-native-pinwheel",
3
- "version": "3.0.5",
3
+ "version": "3.2.0-rc.0",
4
4
  "type": "module",
5
5
  "description": "Pinwheel React Native SDK",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
6
+ "homepage": "https://github.com/underdog-tech/react-native-pinwheel",
7
+ "react-native": "src/index",
8
+ "source": "src/index",
9
+ "files": [
10
+ "src",
11
+ "android",
12
+ "ios",
13
+ "RNPinwheelSDK.podspec",
14
+ "PinwheelLinkSDKObjC",
15
+ "!android/build",
16
+ "!ios/build",
17
+ "!**/__tests__",
18
+ "!**/__fixtures__",
19
+ "!**/__mocks__"
20
+ ],
8
21
  "scripts": {
9
- "build": "tsc",
10
- "bump-pkg-version": "./scripts/bump-pkg-version.sh",
11
- "dev": "./scripts/dev.sh"
22
+ "dev": "./scripts/dev_expo.sh"
12
23
  },
13
24
  "author": "Pinwheel",
14
25
  "license": "MIT",
15
26
  "peerDependencies": {
16
- "react": "^16.13.1 || ^17 || ^18",
17
- "react-native": "*",
18
- "react-native-webview": "*"
27
+ "react": "*",
28
+ "react-native": "*"
19
29
  },
20
30
  "devDependencies": {
21
31
  "@types/react-native": "^0.72.2",
32
+ "prettier": "^3.3.3",
22
33
  "typescript": "^4.0.3"
34
+ },
35
+ "codegenConfig": {
36
+ "name": "RTNPinwheelSpec",
37
+ "type": "all",
38
+ "jsSrcsDir": "./src",
39
+ "outputDir": {
40
+ "ios": "ios/generated",
41
+ "android": "android/generated"
42
+ },
43
+ "android": {
44
+ "javaPackageName": "com.rtnpinwheel"
45
+ }
23
46
  }
24
47
  }
@@ -0,0 +1,62 @@
1
+ import {
2
+ TurboModule,
3
+ TurboModuleRegistry,
4
+ EmitterSubscription,
5
+ NativeEventEmitter,
6
+ } from "react-native";
7
+ import type {Int32} from 'react-native/Libraries/Types/CodegenTypes';
8
+
9
+ export interface Spec extends TurboModule {
10
+ setListener(): void;
11
+ removeListener(): void;
12
+ addListener(eventName: string): void;
13
+ removeListeners(count: Int32): void;
14
+ }
15
+
16
+ const PinwheelEventsTurboModule = TurboModuleRegistry.getEnforcing<Spec>("RTNPinwheelEvents");
17
+ export default PinwheelEventsTurboModule;
18
+
19
+ const EVENT_NAME = 'PINWHEEL_EVENT';
20
+ const eventEmitter = new NativeEventEmitter(PinwheelEventsTurboModule);
21
+
22
+ let listenerCount = eventEmitter.listenerCount;
23
+
24
+ // listenerCount is only available from RN 0.64
25
+ // Older versions only have `listeners`
26
+ if (!listenerCount) {
27
+ listenerCount = (eventType: string) => {
28
+ // @ts-ignore
29
+ return eventEmitter.listeners(eventType).length;
30
+ };
31
+ } else {
32
+ listenerCount = eventEmitter.listenerCount.bind(eventEmitter);
33
+ }
34
+
35
+ const addListener = (callback: (event: any) => void): EmitterSubscription => {
36
+ if (listenerCount(EVENT_NAME) === 0) {
37
+ PinwheelEventsTurboModule.setListener();
38
+ }
39
+
40
+ let res = eventEmitter.addListener(EVENT_NAME, callback);
41
+
42
+ // Path the remove call to also remove the native listener
43
+ // if we no longer have listeners
44
+ // @ts-ignore
45
+ res._remove = res.remove;
46
+ res.remove = function () {
47
+ // @ts-ignore
48
+ this._remove();
49
+ if (listenerCount(EVENT_NAME) === 0) {
50
+ PinwheelEventsTurboModule.removeListener();
51
+ }
52
+ };
53
+
54
+ return res;
55
+ };
56
+
57
+ const removeAllListeners = () => {
58
+ eventEmitter.removeAllListeners(EVENT_NAME);
59
+ PinwheelEventsTurboModule.removeListener();
60
+ };
61
+
62
+ export {addListener, removeAllListeners};