@pinwheel/react-native-pinwheel 3.2.2 → 3.2.4-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.
@@ -41,6 +41,24 @@ class Pinwheel : FrameLayout {
41
41
  private fun init() {
42
42
  // Match background color of Link. We may want to have a loader here in the future.
43
43
  setBackgroundColor(Color.WHITE)
44
+ if (isAttachedToWindow) {
45
+ createFragment()
46
+ } else {
47
+ addOnAttachStateChangeListener(object : OnAttachStateChangeListener {
48
+ override fun onViewAttachedToWindow(v: View) {
49
+ createFragment()
50
+ removeOnAttachStateChangeListener(this)
51
+ }
52
+
53
+ override fun onViewDetachedFromWindow(v: View) {}
54
+ })
55
+
56
+ // Check again after adding the listener in case the the view attached before the listener
57
+ // was added.
58
+ if (isAttachedToWindow) {
59
+ createFragment()
60
+ }
61
+ }
44
62
  }
45
63
 
46
64
  fun setToken(token: String?) {
@@ -58,20 +76,22 @@ class Pinwheel : FrameLayout {
58
76
 
59
77
  private fun createFragment() {
60
78
  Handler(Looper.getMainLooper()).post {
61
- this.token?.let {
62
- val pinwheelFragment = PinwheelFragment.newInstance(it, "react native", "3.2.2", getReactNativeVersion(), this.handleInsets)
63
- pinwheelEventListener?.let { listener ->
64
- pinwheelFragment.pinwheelEventListener = listener
79
+ if (this.pinwheelFragment == null) {
80
+ this.token?.let {
81
+ val pinwheelFragment = PinwheelFragment.newInstance(it, "react native", "3.2.4", getReactNativeVersion(), this.handleInsets)
82
+ pinwheelEventListener?.let { listener ->
83
+ pinwheelFragment.pinwheelEventListener = listener
84
+ }
85
+ val reactContext = context as ThemedReactContext
86
+ val activity = reactContext.currentActivity as? FragmentActivity
87
+
88
+ activity?.supportFragmentManager
89
+ ?.beginTransaction()
90
+ ?.replace(id, pinwheelFragment, id.toString())
91
+ ?.commit()
92
+
93
+ this.pinwheelFragment = pinwheelFragment
65
94
  }
66
- val reactContext = context as ThemedReactContext
67
- val activity = reactContext.currentActivity as? FragmentActivity
68
-
69
- activity?.supportFragmentManager
70
- ?.beginTransaction()
71
- ?.replace(id, pinwheelFragment, id.toString())
72
- ?.commit()
73
-
74
- this.pinwheelFragment = pinwheelFragment
75
95
  }
76
96
  }
77
97
 
@@ -99,14 +119,6 @@ class Pinwheel : FrameLayout {
99
119
  this.layout(left, top, left + width, top + height)
100
120
  }
101
121
 
102
- override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
103
- super.onLayout(changed, left, top, right, bottom)
104
-
105
- if (changed && this.pinwheelFragment == null) {
106
- createFragment()
107
- }
108
- }
109
-
110
122
  fun setPinwheelEventListener(listener: PinwheelEventListener) {
111
123
  pinwheelEventListener = listener
112
124
  pinwheelFragment?.let {
@@ -21,8 +21,8 @@ NS_ASSUME_NONNULL_BEGIN
21
21
  #endif
22
22
 
23
23
 
24
- @property (nonatomic, strong) PinwheelWrapperVC *pinwheelWrapperVC;
25
- @property (nonatomic, assign) NSString *token;
24
+ @property (nonatomic, strong, nullable) PinwheelWrapperVC *pinwheelWrapperVC;
25
+ @property (nonatomic, strong) NSString *token;
26
26
 
27
27
  - (instancetype)initWithFrame:(CGRect)frame token:(NSString *)token;
28
28
 
@@ -37,8 +37,13 @@ using namespace facebook::react;
37
37
  }
38
38
 
39
39
  - (void)initPinwheelWrapperVC {
40
- if (self.token != nil && self.pinwheelWrapperVC == nil) {
41
- self.pinwheelWrapperVC = [[PinwheelWrapperVC alloc] initWithToken:self.token delegate:self sdk:@"react native" version: @"3.2.2"];
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.2.4"];
42
47
  [self addSubview:self.pinwheelWrapperVC.view];
43
48
  }
44
49
  }
@@ -46,7 +51,6 @@ using namespace facebook::react;
46
51
  - (void)setToken:(NSString *)newToken {
47
52
  if (![_token isEqualToString:newToken]) {
48
53
  _token = newToken;
49
- [self initPinwheelWrapperVC];
50
54
  }
51
55
  }
52
56
 
@@ -59,14 +63,20 @@ using namespace facebook::react;
59
63
  NSString* convertedToken = [NSString stringWithUTF8String:newViewProps.token.c_str()];
60
64
  [self setToken:convertedToken];
61
65
  }
66
+ // Ensures that the view is always re-initialized whenever the props change, or the React Native component is
67
+ // re-mounted. On the new architecture, there are optimizations which causes the view to be re-used in these
68
+ // scenarios, whereas the ideal functionality here is to have the Link modal reset to the starting state.
69
+ [self initPinwheelWrapperVC];
62
70
 
63
71
  [super updateProps:props oldProps:oldProps];
64
72
  }
65
73
 
66
74
  - (void)layoutSubviews
67
75
  {
68
- [super layoutSubviews];
69
- self.pinwheelWrapperVC.view.frame = self.bounds;
76
+ [super layoutSubviews];
77
+ if (self.pinwheelWrapperVC != nil) {
78
+ self.pinwheelWrapperVC.view.frame = self.bounds;
79
+ }
70
80
  }
71
81
 
72
82
  - (void)onEventWithName:(NSString *)name event:(NSDictionary<NSString *, id> *)event {
@@ -125,7 +135,7 @@ Class<RCTComponentViewProtocol> RTNPinwheelCls(void)
125
135
 
126
136
  - (void)initPinwheelWrapperVC {
127
137
  if (self.token != nil && self.pinwheelWrapperVC == nil) {
128
- self.pinwheelWrapperVC = [[PinwheelWrapperVC alloc] initWithToken:self.token delegate:self sdk:@"react native" version: @"3.2.2"];
138
+ self.pinwheelWrapperVC = [[PinwheelWrapperVC alloc] initWithToken:self.token delegate:self sdk:@"react native" version: @"3.2.4"];
129
139
  [self addSubview:self.pinwheelWrapperVC.view];
130
140
  }
131
141
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pinwheel/react-native-pinwheel",
3
- "version": "3.2.2",
3
+ "version": "3.2.4-rc.0",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",