@pinwheel/react-native-pinwheel 3.5.0 → 3.5.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.
@@ -17,5 +17,5 @@ Pod::Spec.new do |s|
17
17
 
18
18
  install_modules_dependencies(s)
19
19
 
20
- s.dependency 'PinwheelSDK', '3.4.0'
20
+ s.dependency 'PinwheelSDK', '3.4.1'
21
21
  end
@@ -32,7 +32,7 @@ repositories {
32
32
  google()
33
33
  }
34
34
 
35
- def PW_ANDROID_SDK_VERSION = '3.5.0'
35
+ def PW_ANDROID_SDK_VERSION = '3.5.1'
36
36
 
37
37
  dependencies {
38
38
  def pwVersion = rootProject.hasProperty('pwVersion') ? rootProject.pwVersion : PW_ANDROID_SDK_VERSION
@@ -89,7 +89,7 @@ class Pinwheel : FrameLayout {
89
89
  Handler(Looper.getMainLooper()).post {
90
90
  if (this.pinwheelFragment == null) {
91
91
  this.token?.let {
92
- val pinwheelFragment = PinwheelFragment.newInstanceWithAdvancedOptions(it, "react native", "3.5.0", getReactNativeVersion(), this.handleInsets, this.useDarkMode)
92
+ val pinwheelFragment = PinwheelFragment.newInstanceWithAdvancedOptions(it, "react native", "3.5.2", getReactNativeVersion(), this.handleInsets, this.useDarkMode)
93
93
  pinwheelEventListener?.let { listener ->
94
94
  pinwheelFragment.pinwheelEventListener = listener
95
95
  }
@@ -7,8 +7,8 @@
7
7
  #import <react/renderer/components/RTNPinwheelSpec/Props.h>
8
8
  #import <react/renderer/components/RTNPinwheelSpec/RCTComponentViewHelpers.h>
9
9
 
10
- #import "RTNPinwheelEvents.h"
11
10
  #import "RCTFabricComponentsPlugins.h"
11
+ #import "RTNPinwheelEvents.h"
12
12
 
13
13
  using namespace facebook::react;
14
14
 
@@ -17,186 +17,306 @@ using namespace facebook::react;
17
17
 
18
18
  @implementation RTNPinwheelView
19
19
 
20
- + (ComponentDescriptorProvider)componentDescriptorProvider
21
- {
22
- return concreteComponentDescriptorProvider<RTNPinwheelComponentDescriptor>();
20
+ + (ComponentDescriptorProvider)componentDescriptorProvider {
21
+ return concreteComponentDescriptorProvider<RTNPinwheelComponentDescriptor>();
23
22
  }
24
23
 
25
24
  - (instancetype)initWithFrame:(CGRect)frame {
26
- if ((self = [super initWithFrame:frame])) {
27
- [self initPinwheelWrapperVC];
28
- }
29
- return self;
25
+ if ((self = [super initWithFrame:frame])) {
26
+ [self initPinwheelWrapperVC];
27
+ }
28
+ return self;
30
29
  }
31
30
 
32
31
  - (instancetype)initWithFrame:(CGRect)frame token:(NSString *)token {
33
- if ((self = [super initWithFrame:frame])) {
34
- _token = token;
35
- }
36
- return self;
32
+ if ((self = [super initWithFrame:frame])) {
33
+ _token = token;
34
+ }
35
+ return self;
37
36
  }
38
37
 
39
- - (void)initPinwheelWrapperVC {
40
- if (self.pinwheelWrapperVC != nil) {
41
- [self.pinwheelWrapperVC.view removeFromSuperview];
42
- self.pinwheelWrapperVC = nil;
43
- }
44
-
45
- if (self.token != nil) {
46
- self.pinwheelWrapperVC = [[PinwheelWrapperVC alloc] initWithToken:self.token delegate:self sdk:@"react native" version:@"3.5.0" useDarkMode:self.useDarkMode useAppBoundDomains:NO useAppBoundDomainsForNativeLink:NO];
47
- [self addSubview:self.pinwheelWrapperVC.view];
38
+ // Helper to find parent VC from a UIView
39
+ - (UIViewController *)getParentViewController {
40
+ UIResponder *responder = self.nextResponder;
41
+ while (responder) {
42
+ if ([responder isKindOfClass:[UIViewController class]]) {
43
+ return (UIViewController *)responder;
48
44
  }
45
+ responder = responder.nextResponder;
46
+ }
47
+ return nil;
49
48
  }
50
49
 
51
- - (void)setToken:(NSString *)newToken {
52
- if (![_token isEqualToString:newToken]) {
53
- _token = newToken;
54
- }
50
+ - (void)cleanUpPinwheelWrapperVC {
51
+ if (self.pinwheelWrapperVC != nil) {
52
+ [self.pinwheelWrapperVC willMoveToParentViewController:nil];
53
+ [self.pinwheelWrapperVC.view removeFromSuperview];
54
+ [self.pinwheelWrapperVC removeFromParentViewController];
55
+ self.pinwheelWrapperVC = nil;
56
+ }
55
57
  }
56
58
 
57
- - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
58
- {
59
- const auto &oldViewProps = *std::static_pointer_cast<RTNPinwheelProps const>(_props);
60
- const auto &newViewProps = *std::static_pointer_cast<RTNPinwheelProps const>(props);
59
+ - (void)initPinwheelWrapperVC {
60
+ [self cleanUpPinwheelWrapperVC];
61
+
62
+ if (self.token == nil) {
63
+ return;
64
+ }
65
+
66
+ UIViewController *parentVC = [self getParentViewController];
67
+ if (!parentVC) {
68
+ // Not yet attached to the hierarchy, skip for now and `didMoveToWindow`
69
+ // will retry later.
70
+ return;
71
+ }
72
+
73
+ self.pinwheelWrapperVC =
74
+ [[PinwheelWrapperVC alloc] initWithToken:self.token
75
+ delegate:self
76
+ sdk:@"react native"
77
+ version:@"3.5.2"
78
+ useDarkMode:self.useDarkMode
79
+ useAppBoundDomains:NO
80
+ useAppBoundDomainsForNativeLink:NO];
81
+
82
+ // Guard against double-attachment (shouldn’t happen after cleanup, but safe).
83
+ if (self.pinwheelWrapperVC.parentViewController == parentVC) {
84
+ self.pinwheelWrapperVC.view.frame = self.bounds;
85
+ return;
86
+ }
87
+
88
+ [parentVC addChildViewController:self.pinwheelWrapperVC];
89
+ [self addSubview:self.pinwheelWrapperVC.view];
90
+ self.pinwheelWrapperVC.view.frame = self.bounds;
91
+ [self.pinwheelWrapperVC didMoveToParentViewController:parentVC];
92
+ }
61
93
 
62
- if (oldViewProps.token != newViewProps.token) {
63
- NSString* convertedToken = [NSString stringWithUTF8String:newViewProps.token.c_str()];
64
- [self setToken:convertedToken];
94
+ - (void)didMoveToWindow {
95
+ [super didMoveToWindow];
96
+ if (self.window) {
97
+ if (!self.pinwheelWrapperVC) {
98
+ [self initPinwheelWrapperVC];
65
99
  }
100
+ } else {
101
+ [self cleanUpPinwheelWrapperVC];
102
+ }
103
+ }
66
104
 
67
- if (oldViewProps.useDarkMode != newViewProps.useDarkMode) {
68
- self.useDarkMode = newViewProps.useDarkMode;
69
- }
105
+ - (void)dealloc {
106
+ [self cleanUpPinwheelWrapperVC];
107
+ }
70
108
 
71
- // Ensures that the view is always re-initialized whenever the props change, or the React Native component is
72
- // re-mounted. On the new architecture, there are optimizations which causes the view to be re-used in these
73
- // scenarios, whereas the ideal functionality here is to have the Link modal reset to the starting state.
74
- [self initPinwheelWrapperVC];
109
+ - (void)setToken:(NSString *)newToken {
110
+ if (![_token isEqualToString:newToken]) {
111
+ _token = newToken;
112
+ }
113
+ }
75
114
 
76
- [super updateProps:props oldProps:oldProps];
115
+ - (void)updateProps:(Props::Shared const &)props
116
+ oldProps:(Props::Shared const &)oldProps {
117
+ const auto &oldViewProps =
118
+ *std::static_pointer_cast<RTNPinwheelProps const>(_props);
119
+ const auto &newViewProps =
120
+ *std::static_pointer_cast<RTNPinwheelProps const>(props);
121
+
122
+ if (oldViewProps.token != newViewProps.token) {
123
+ NSString *convertedToken =
124
+ [NSString stringWithUTF8String:newViewProps.token.c_str()];
125
+ [self setToken:convertedToken];
126
+ }
127
+
128
+ if (oldViewProps.useDarkMode != newViewProps.useDarkMode) {
129
+ self.useDarkMode = newViewProps.useDarkMode;
130
+ }
131
+
132
+ // Ensures that the view is always re-initialized whenever the props change,
133
+ // or the React Native component is re-mounted. On the new architecture, there
134
+ // are optimizations which causes the view to be re-used in these scenarios,
135
+ // whereas the ideal functionality here is to have the Link modal reset to the
136
+ // starting state.
137
+ [self initPinwheelWrapperVC];
138
+
139
+ [super updateProps:props oldProps:oldProps];
77
140
  }
78
141
 
79
- - (void)layoutSubviews
80
- {
81
- [super layoutSubviews];
82
- if (self.pinwheelWrapperVC != nil) {
83
- self.pinwheelWrapperVC.view.frame = self.bounds;
84
- }
142
+ - (void)layoutSubviews {
143
+ [super layoutSubviews];
144
+ if (self.pinwheelWrapperVC != nil) {
145
+ self.pinwheelWrapperVC.view.frame = self.bounds;
146
+ }
85
147
  }
86
148
 
87
- - (void)onEventWithName:(NSString *)name event:(NSDictionary<NSString *, id> *)event {
88
- NSLog(@"%@", name);
89
- NSDictionary *dataToSend = @{@"name": name, @"payload": event};
90
- [RTNPinwheelEvents.sharedInstance handlePinwheelEvent:dataToSend];
149
+ - (void)onEventWithName:(NSString *)name
150
+ event:(NSDictionary<NSString *, id> *)event {
151
+ NSLog(@"%@", name);
152
+ NSDictionary *dataToSend = @{@"name" : name, @"payload" : event};
153
+ [RTNPinwheelEvents.sharedInstance handlePinwheelEvent:dataToSend];
91
154
  }
92
155
 
93
156
  - (void)onExit:(NSDictionary<NSString *, id> *)error {
94
- NSLog(@"%@", error);
157
+ NSLog(@"%@", error);
95
158
  }
96
159
 
97
160
  - (void)onSuccess:(NSDictionary<NSString *, id> *)result {
98
- NSLog(@"%@", result);
161
+ NSLog(@"%@", result);
99
162
  }
100
163
 
101
164
  - (void)onLogin:(NSDictionary<NSString *, id> *)result {
102
- NSLog(@"%@", result);
165
+ NSLog(@"%@", result);
103
166
  }
104
167
 
105
168
  - (void)onLoginAttempt:(NSDictionary<NSString *, id> *)result {
106
- NSLog(@"%@", result);
169
+ NSLog(@"%@", result);
107
170
  }
108
171
 
109
172
  - (void)onError:(NSDictionary<NSString *, id> *)error {
110
- NSLog(@"%@", error);
173
+ NSLog(@"%@", error);
111
174
  }
112
175
 
113
176
  @end
114
177
 
115
- Class<RCTComponentViewProtocol> RTNPinwheelCls(void)
116
- {
178
+ Class<RCTComponentViewProtocol> RTNPinwheelCls(void) {
117
179
  return RTNPinwheelView.class;
118
180
  }
119
181
 
120
182
  #else
121
183
 
122
- #import "RTNPinwheelView.h"
123
184
  #import "RTNPinwheelEvents.h"
185
+ #import "RTNPinwheelView.h"
124
186
 
125
187
  @implementation RTNPinwheelView
126
188
 
127
189
  - (instancetype)initWithFrame:(CGRect)frame {
128
- if ((self = [super initWithFrame:frame])) {
129
- [self initPinwheelWrapperVC];
130
- }
131
- return self;
190
+ if ((self = [super initWithFrame:frame])) {
191
+ [self initPinwheelWrapperVC];
192
+ }
193
+ return self;
132
194
  }
133
195
 
134
196
  - (instancetype)initWithFrame:(CGRect)frame token:(NSString *)token {
135
- if ((self = [super initWithFrame:frame])) {
136
- _token = token;
197
+ if ((self = [super initWithFrame:frame])) {
198
+ _token = token;
199
+ }
200
+ return self;
201
+ }
202
+
203
+ // Helper to find parent VC from a UIView
204
+ - (UIViewController *)getParentViewController {
205
+ UIResponder *responder = self.nextResponder;
206
+ while (responder) {
207
+ if ([responder isKindOfClass:[UIViewController class]]) {
208
+ return (UIViewController *)responder;
137
209
  }
138
- return self;
210
+ responder = responder.nextResponder;
211
+ }
212
+ return nil;
213
+ }
214
+
215
+ - (void)cleanUpPinwheelWrapperVC {
216
+ if (self.pinwheelWrapperVC != nil) {
217
+ [self.pinwheelWrapperVC willMoveToParentViewController:nil];
218
+ [self.pinwheelWrapperVC.view removeFromSuperview];
219
+ [self.pinwheelWrapperVC removeFromParentViewController];
220
+ self.pinwheelWrapperVC = nil;
221
+ }
139
222
  }
140
223
 
141
224
  - (void)initPinwheelWrapperVC {
142
- if (self.pinwheelWrapperVC != nil) {
143
- [self.pinwheelWrapperVC.view removeFromSuperview];
144
- self.pinwheelWrapperVC = nil;
145
- }
225
+ [self cleanUpPinwheelWrapperVC];
226
+
227
+ if (self.token == nil) {
228
+ return;
229
+ }
230
+
231
+ UIViewController *parentVC = [self getParentViewController];
232
+ if (!parentVC) {
233
+ // Not yet attached to the hierarchy, skip for now and `didMoveToWindow`
234
+ // will retry later.
235
+ return;
236
+ }
237
+
238
+ self.pinwheelWrapperVC =
239
+ [[PinwheelWrapperVC alloc] initWithToken:self.token
240
+ delegate:self
241
+ sdk:@"react native"
242
+ version:@"3.5.2"
243
+ useDarkMode:self.useDarkMode
244
+ useAppBoundDomains:NO
245
+ useAppBoundDomainsForNativeLink:NO];
246
+
247
+ // Guard against double-attachment (shouldn’t happen after cleanup, but safe).
248
+ if (self.pinwheelWrapperVC.parentViewController == parentVC) {
249
+ self.pinwheelWrapperVC.view.frame = self.bounds;
250
+ return;
251
+ }
252
+
253
+ [parentVC addChildViewController:self.pinwheelWrapperVC];
254
+ [self addSubview:self.pinwheelWrapperVC.view];
255
+ self.pinwheelWrapperVC.view.frame = self.bounds;
256
+ [self.pinwheelWrapperVC didMoveToParentViewController:parentVC];
257
+ }
146
258
 
147
- if (self.token != nil) {
148
- self.pinwheelWrapperVC = [[PinwheelWrapperVC alloc] initWithToken:self.token delegate:self sdk:@"react native" version:@"3.4.0" useDarkMode:self.useDarkMode useAppBoundDomains:NO useAppBoundDomainsForNativeLink:NO];
149
- [self addSubview:self.pinwheelWrapperVC.view];
259
+ - (void)didMoveToWindow {
260
+ [super didMoveToWindow];
261
+ if (self.window) {
262
+ if (!self.pinwheelWrapperVC) {
263
+ [self initPinwheelWrapperVC];
150
264
  }
265
+ } else {
266
+ [self cleanUpPinwheelWrapperVC];
267
+ }
268
+ }
269
+
270
+ - (void)dealloc {
271
+ [self cleanUpPinwheelWrapperVC];
151
272
  }
152
273
 
153
274
  - (void)setToken:(NSString *)newToken {
154
- if (![_token isEqualToString:newToken]) {
155
- _token = newToken;
156
- [self initPinwheelWrapperVC];
157
- }
275
+ if (![_token isEqualToString:newToken]) {
276
+ _token = newToken;
277
+ [self initPinwheelWrapperVC];
278
+ }
158
279
  }
159
280
 
160
281
  - (void)setUseDarkMode:(BOOL)newUseDarkMode {
161
- if (_useDarkMode != newUseDarkMode) {
162
- _useDarkMode = newUseDarkMode;
163
- [self initPinwheelWrapperVC];
164
- }
282
+ if (_useDarkMode != newUseDarkMode) {
283
+ _useDarkMode = newUseDarkMode;
284
+ [self initPinwheelWrapperVC];
285
+ }
165
286
  }
166
287
 
167
- - (void)layoutSubviews
168
- {
288
+ - (void)layoutSubviews {
169
289
  [super layoutSubviews];
170
290
  self.pinwheelWrapperVC.view.frame = self.bounds;
171
291
  }
172
292
 
173
- - (void)onEventWithName:(NSString *)name event:(NSDictionary<NSString *, id> *)event {
174
- NSLog(@"%@", name);
175
- NSDictionary *dataToSend = @{@"name": name, @"payload": event};
176
- [RTNPinwheelEvents.sharedInstance handlePinwheelEvent:dataToSend];
293
+ - (void)onEventWithName:(NSString *)name
294
+ event:(NSDictionary<NSString *, id> *)event {
295
+ NSLog(@"%@", name);
296
+ NSDictionary *dataToSend = @{@"name" : name, @"payload" : event};
297
+ [RTNPinwheelEvents.sharedInstance handlePinwheelEvent:dataToSend];
177
298
  }
178
299
 
179
300
  - (void)onExit:(NSDictionary<NSString *, id> *)error {
180
- NSLog(@"%@", error);
301
+ NSLog(@"%@", error);
181
302
  }
182
303
 
183
304
  - (void)onSuccess:(NSDictionary<NSString *, id> *)result {
184
- NSLog(@"%@", result);
305
+ NSLog(@"%@", result);
185
306
  }
186
307
 
187
308
  - (void)onLogin:(NSDictionary<NSString *, id> *)result {
188
- NSLog(@"%@", result);
309
+ NSLog(@"%@", result);
189
310
  }
190
311
 
191
312
  - (void)onLoginAttempt:(NSDictionary<NSString *, id> *)result {
192
- NSLog(@"%@", result);
313
+ NSLog(@"%@", result);
193
314
  }
194
315
 
195
316
  - (void)onError:(NSDictionary<NSString *, id> *)error {
196
- NSLog(@"%@", error);
317
+ NSLog(@"%@", error);
197
318
  }
198
319
 
199
320
  @end
200
321
 
201
-
202
322
  #endif
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pinwheel/react-native-pinwheel",
3
- "version": "3.5.0",
3
+ "version": "3.5.2",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",