@pinwheel/react-native-pinwheel 3.2.3 → 3.2.4-rc.1

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.
@@ -10,7 +10,6 @@ import android.view.Choreographer
10
10
  import android.view.View
11
11
  import android.widget.FrameLayout
12
12
  import androidx.fragment.app.FragmentActivity
13
- import com.facebook.react.bridge.ReactApplicationContext
14
13
  import com.underdog_tech.pinwheel_android.PinwheelEventListener
15
14
  import com.underdog_tech.pinwheel_android.PinwheelFragment
16
15
  import com.facebook.react.uimanager.ThemedReactContext
@@ -21,6 +20,7 @@ class Pinwheel : FrameLayout {
21
20
  private var pinwheelFragment: PinwheelFragment? = null
22
21
  private var pinwheelEventListener: PinwheelEventListener? = null
23
22
  private var handleInsets: Boolean = true
23
+ private var fragmentContainer: FrameLayout? = null
24
24
 
25
25
  constructor(context: Context) : super(context) {
26
26
  init()
@@ -41,6 +41,30 @@ 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
+
45
+ // Create a FrameLayout to act as the fragment container
46
+ fragmentContainer = FrameLayout(context)
47
+ fragmentContainer!!.id = View.generateViewId()
48
+ addView(fragmentContainer, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT))
49
+
50
+ if (isAttachedToWindow) {
51
+ createFragment()
52
+ } else {
53
+ addOnAttachStateChangeListener(object : OnAttachStateChangeListener {
54
+ override fun onViewAttachedToWindow(v: View) {
55
+ createFragment()
56
+ removeOnAttachStateChangeListener(this)
57
+ }
58
+
59
+ override fun onViewDetachedFromWindow(v: View) {}
60
+ })
61
+
62
+ // Check again after adding the listener in case the the view attached before the listener
63
+ // was added.
64
+ if (isAttachedToWindow) {
65
+ createFragment()
66
+ }
67
+ }
44
68
  }
45
69
 
46
70
  fun setToken(token: String?) {
@@ -58,20 +82,23 @@ class Pinwheel : FrameLayout {
58
82
 
59
83
  private fun createFragment() {
60
84
  Handler(Looper.getMainLooper()).post {
61
- this.token?.let {
62
- val pinwheelFragment = PinwheelFragment.newInstance(it, "react native", "3.2.3", getReactNativeVersion(), this.handleInsets)
63
- pinwheelEventListener?.let { listener ->
64
- pinwheelFragment.pinwheelEventListener = listener
85
+ if (this.pinwheelFragment == null) {
86
+ this.token?.let {
87
+ val pinwheelFragment = PinwheelFragment.newInstance(it, "react native", "3.2.4", getReactNativeVersion(), this.handleInsets)
88
+ pinwheelEventListener?.let { listener ->
89
+ pinwheelFragment.pinwheelEventListener = listener
90
+ }
91
+ val reactContext = context as ThemedReactContext
92
+ val activity = reactContext.currentActivity as? FragmentActivity
93
+
94
+ val transaction = activity?.supportFragmentManager?.beginTransaction()
95
+ transaction?.runOnCommit {
96
+ fragmentContainer?.addView(pinwheelFragment.view)
97
+ }
98
+ transaction?.add(pinwheelFragment, pinwheelFragment.id.toString())?.commit()
99
+
100
+ this.pinwheelFragment = pinwheelFragment
65
101
  }
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
102
  }
76
103
  }
77
104
 
@@ -99,14 +126,6 @@ class Pinwheel : FrameLayout {
99
126
  this.layout(left, top, left + width, top + height)
100
127
  }
101
128
 
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
129
  fun setPinwheelEventListener(listener: PinwheelEventListener) {
111
130
  pinwheelEventListener = listener
112
131
  pinwheelFragment?.let {
@@ -43,7 +43,7 @@ using namespace facebook::react;
43
43
  }
44
44
 
45
45
  if (self.token != nil) {
46
- self.pinwheelWrapperVC = [[PinwheelWrapperVC alloc] initWithToken:self.token delegate:self sdk:@"react native" version: @"3.2.3"];
46
+ self.pinwheelWrapperVC = [[PinwheelWrapperVC alloc] initWithToken:self.token delegate:self sdk:@"react native" version: @"3.2.4"];
47
47
  [self addSubview:self.pinwheelWrapperVC.view];
48
48
  }
49
49
  }
@@ -135,7 +135,7 @@ Class<RCTComponentViewProtocol> RTNPinwheelCls(void)
135
135
 
136
136
  - (void)initPinwheelWrapperVC {
137
137
  if (self.token != nil && self.pinwheelWrapperVC == nil) {
138
- self.pinwheelWrapperVC = [[PinwheelWrapperVC alloc] initWithToken:self.token delegate:self sdk:@"react native" version: @"3.2.3"];
138
+ self.pinwheelWrapperVC = [[PinwheelWrapperVC alloc] initWithToken:self.token delegate:self sdk:@"react native" version: @"3.2.4"];
139
139
  [self addSubview:self.pinwheelWrapperVC.view];
140
140
  }
141
141
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pinwheel/react-native-pinwheel",
3
- "version": "3.2.3",
3
+ "version": "3.2.4-rc.1",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",