react-native-firework-sdk 1.5.6 → 1.5.7

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.
@@ -53,10 +53,14 @@ class FWStoryBlockManager(
53
53
  val filter = IntentFilter()
54
54
  filter.addAction(FW_STORY_BLOCK_INIT_ACTION)
55
55
  LocalBroadcastManager.getInstance(reactContext).registerReceiver(broadcastReceiver, filter)
56
-
57
56
  return FrameLayout(reactContext)
58
57
  }
59
58
 
59
+ override fun onAfterUpdateTransaction(view: FrameLayout) {
60
+ super.onAfterUpdateTransaction(view)
61
+ FWLogUtils.d { "FWStoryBlockManager onAfterUpdateTransaction" }
62
+ }
63
+
60
64
  @Nullable
61
65
  override fun getCommandsMap(): Map<String, Int>? {
62
66
  return MapBuilder.of("create", COMMAND_CREATE)
@@ -107,9 +111,11 @@ class FWStoryBlockManager(
107
111
  private fun setupLayout(view: View) {
108
112
  Choreographer.getInstance().postFrameCallback(object : Choreographer.FrameCallback {
109
113
  override fun doFrame(frameTimeNanos: Long) {
110
- manuallyLayoutChildren(view)
111
- view.viewTreeObserver.dispatchOnGlobalLayout()
112
- Choreographer.getInstance().postFrameCallback(this)
114
+ if (view.isAttachedToWindow) {
115
+ manuallyLayoutChildren(view)
116
+ view.viewTreeObserver.dispatchOnGlobalLayout()
117
+ Choreographer.getInstance().postFrameCallback(this)
118
+ }
113
119
  }
114
120
  })
115
121
  }
@@ -118,10 +124,6 @@ class FWStoryBlockManager(
118
124
  * Layout all children properly
119
125
  */
120
126
  private fun manuallyLayoutChildren(view: View) {
121
- // propWidth and propHeight coming from react-native props
122
- // val width = requireNotNull(propWidth)
123
- // val height = requireNotNull(propHeight)
124
-
125
127
  view.measure(
126
128
  View.MeasureSpec.makeMeasureSpec(view.measuredWidth, View.MeasureSpec.EXACTLY),
127
129
  View.MeasureSpec.makeMeasureSpec(view.measuredHeight, View.MeasureSpec.EXACTLY)
@@ -132,6 +134,7 @@ class FWStoryBlockManager(
132
134
 
133
135
 
134
136
  private fun createFragment(root: FrameLayout, reactNativeViewId: Int?) {
137
+ FWLogUtils.d { "FWStoryBlockManager createFragment, reactNativeViewId = $reactNativeViewId" }
135
138
  reactNativeViewId ?: return
136
139
  val activity = (reactContext.currentActivity as AppCompatActivity?) ?: return
137
140
 
@@ -146,43 +149,37 @@ class FWStoryBlockManager(
146
149
  val fireworkPlayerFragment = FireworkPlayerFragment()
147
150
  this.fireworkPlayerFragment = fireworkPlayerFragment
148
151
 
149
- FWLogUtils.d { "FWStoryBlockManager createFragment doOnAttach before" }
150
- parentView.addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
151
- override fun onViewAttachedToWindow(v: View?) {
152
- FWLogUtils.d { "FWStoryBlockManager createFragment doOnAttach" }
153
- // Log.e("isAttachedToWindow", parentView.isAttachedToWindow.toString())
154
- activity.supportFragmentManager
155
- .beginTransaction()
156
- .replace(reactNativeViewId, fireworkPlayerFragment, reactNativeViewId.toString())
157
- .commitNow()
158
- parentView.requestLayout()
159
- // Log.e("isAttachedToWindow", fireworkPlayerFragment.isAdded.toString())
160
- setStoryBlockParameters()
161
- }
162
-
163
- override fun onViewDetachedFromWindow(v: View?) {
152
+ FWLogUtils.d { "FWStoryBlockManager createFragment doOnAttach before, fireworkPlayerFragment.isAdded = ${fireworkPlayerFragment.isAdded}, parentView.isAttachedToWindow = ${parentView.isAttachedToWindow}" }
153
+ if (parentView.isAttachedToWindow) {
154
+ if (fireworkPlayerFragment.isAdded) {
155
+ return
164
156
  }
157
+ activity.supportFragmentManager
158
+ .beginTransaction()
159
+ .replace(reactNativeViewId, fireworkPlayerFragment, reactNativeViewId.toString())
160
+ .commitNow()
161
+ parentView.requestLayout()
162
+ setStoryBlockParameters()
163
+ } else {
164
+ parentView.addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
165
+ override fun onViewAttachedToWindow(v: View?) {
166
+ FWLogUtils.d { "FWStoryBlockManager createFragment doOnAttach" }
167
+ if (fireworkPlayerFragment.isAdded) {
168
+ return
169
+ }
170
+ activity.supportFragmentManager
171
+ .beginTransaction()
172
+ .replace(reactNativeViewId, fireworkPlayerFragment, reactNativeViewId.toString())
173
+ .commitNow()
174
+ parentView.requestLayout()
175
+ setStoryBlockParameters()
176
+ }
165
177
 
166
- })
167
-
168
- // activity.lifecycleScope.launch {
169
- //// withContext(Dispatchers.Default) {
170
- //// while (!FwSDK.initialized) {
171
- //// delay(2000)
172
- //// }
173
- //// }
174
- //
175
- // withContext(Dispatchers.Main) {
176
- // if(FwSDK.initialized) {
177
- // delay(2000)
178
- // Log.e("isAttachedToWindow", parentView.isAttachedToWindow.toString())
179
- //// FeedFactory.getVideoFeed(13, FeedType.DISCOVER, null, null)
180
- // fireworkPlayerFragment.setStoryBlockParameters(FeedType.DISCOVER)
181
- //// fireworkPlayerFragment.setParameters(13, null)
182
- // }
183
- // }
184
- // }
178
+ override fun onViewDetachedFromWindow(v: View?) {
179
+ }
185
180
 
181
+ })
182
+ }
186
183
  }
187
184
 
188
185
  private fun addStoryBlockListener(reactContext: ReactApplicationContext) {
@@ -1,11 +1,15 @@
1
1
  package com.fireworksdk.bridge.reactnative.module
2
2
 
3
3
  import android.app.Activity
4
+ import androidx.appcompat.app.AppCompatActivity
4
5
  import com.facebook.react.bridge.*
5
6
  import com.fireworksdk.bridge.FWInitializationProvider
6
7
  import com.fireworksdk.bridge.reactnative.models.FWNavigatorInterface
7
8
  import com.fireworksdk.bridge.reactnative.utils.FWEventUtils
8
9
  import com.fireworksdk.bridge.utils.FWLogUtils
10
+ import com.loopnow.fireworklibrary.baya.ProductListFragment
11
+ import com.loopnow.fireworklibrary.views.BaseVideoViewFragment
12
+ import com.loopnow.fireworklibrary.views.FireworkPlayerFragment
9
13
 
10
14
 
11
15
  class FWNavigatorModule(
@@ -28,6 +32,7 @@ class FWNavigatorModule(
28
32
  }
29
33
 
30
34
  if (isTaskRoot(activity)) {
35
+ closeDialog(activity)
31
36
  promise.resolve(false)
32
37
  return
33
38
  }
@@ -69,6 +74,36 @@ class FWNavigatorModule(
69
74
  return false
70
75
  }
71
76
 
77
+ private fun closeDialog(activity: Activity) {
78
+ // close ProductListFragment
79
+ if (activity is AppCompatActivity) {
80
+ val fragmentList = activity.supportFragmentManager.fragments
81
+ if (fragmentList.isEmpty()) {
82
+ return
83
+ }
84
+ for (fragment in fragmentList) {
85
+ if (fragment !is FireworkPlayerFragment) {
86
+ continue
87
+ }
88
+ val childFragmentList = fragment.childFragmentManager.fragments
89
+ for (childFragment in childFragmentList) {
90
+ if (childFragment !is BaseVideoViewFragment<*>) {
91
+ continue
92
+ }
93
+ val list = childFragment.childFragmentManager.fragments
94
+ for (f in list) {
95
+ if (f !is ProductListFragment) {
96
+ continue
97
+ }
98
+ if (f.isAdded) {
99
+ f.dismiss()
100
+ }
101
+ }
102
+ }
103
+ }
104
+ }
105
+ }
106
+
72
107
  override fun getName(): String {
73
108
  return "FWNavigatorModule"
74
109
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-firework-sdk",
3
- "version": "1.5.6",
3
+ "version": "1.5.7",
4
4
  "description": "Firework React Native SDK",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",