react-native-firework-sdk 1.6.0 → 1.6.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.
package/android/src/main/java/com/fireworksdk/bridge/reactnative/manager/FWStoryBlockManager.kt
CHANGED
|
@@ -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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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.
|
|
151
|
-
|
|
152
|
-
|
|
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) {
|
package/android/src/main/java/com/fireworksdk/bridge/reactnative/module/FWNavigatorModule.kt
CHANGED
|
@@ -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
|
}
|
|
@@ -104,6 +104,24 @@ class FWNavigatorModule: RCTEventEmitter, FWNavigator {
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
func getCloseButton(view: UIView) -> UIButton? {
|
|
108
|
+
if let button = view as? UIButton, let targetImage = button.image(for: .normal) {
|
|
109
|
+
let iOSSDKBundle = Bundle(for: FireworkVideoSDK.self)
|
|
110
|
+
if targetImage.isEqual(UIImage(named: "closeX", in: iOSSDKBundle, compatibleWith: nil))
|
|
111
|
+
|| targetImage.isEqual(UIImage(named: "down-arrow-light", in: iOSSDKBundle, compatibleWith: nil)) {
|
|
112
|
+
return button
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
for subview in view.subviews {
|
|
117
|
+
if let result = getCloseButton(view: subview) {
|
|
118
|
+
return result
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return nil
|
|
123
|
+
}
|
|
124
|
+
|
|
107
125
|
// swiftlint:enable function_body_length
|
|
108
126
|
|
|
109
127
|
@objc(popNativeContainer:rejecter:)
|
|
@@ -124,22 +142,36 @@ class FWNavigatorModule: RCTEventEmitter, FWNavigator {
|
|
|
124
142
|
} else if let presentedVC = RCTPresentedViewController(),
|
|
125
143
|
let presentingVC = presentedVC.presentingViewController,
|
|
126
144
|
presentingVC.presentingViewController == RCTKeyWindow()?.rootViewController {
|
|
127
|
-
|
|
128
|
-
|
|
145
|
+
let closeButton = self.getCloseButton(view: presentingVC.view)
|
|
146
|
+
if closeButton == nil {
|
|
147
|
+
FWNavigatorUtils.shared.shouldDisablePlay = true
|
|
148
|
+
}
|
|
129
149
|
presentedVC.dismiss(animated: false) {
|
|
130
150
|
DispatchQueue.main.asyncAfter(wallDeadline: .now() + 0.1) {
|
|
131
|
-
|
|
132
|
-
|
|
151
|
+
FWNavigatorUtils.shared.shouldDisablePlay = false
|
|
152
|
+
if closeButton != nil {
|
|
153
|
+
closeButton!.sendActions(for: .touchUpInside)
|
|
133
154
|
resolver(true)
|
|
134
|
-
|
|
155
|
+
} else {
|
|
156
|
+
NotificationCenter.default.post(name: gOnVideoTemporarilyReleasePipController, object: nil)
|
|
157
|
+
presentingVC.dismiss(animated: true) {
|
|
158
|
+
NotificationCenter.default.post(name: gOnVideoRestorePipController, object: nil)
|
|
159
|
+
resolver(true)
|
|
160
|
+
}
|
|
135
161
|
}
|
|
136
162
|
}
|
|
137
163
|
}
|
|
138
|
-
} else if let rootVC = RCTKeyWindow()?.rootViewController,
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
164
|
+
} else if let rootVC = RCTKeyWindow()?.rootViewController,
|
|
165
|
+
let presentedVC = rootVC.presentedViewController {
|
|
166
|
+
if let closeButton = self.getCloseButton(view: presentedVC.view) {
|
|
167
|
+
closeButton.sendActions(for: .touchUpInside)
|
|
142
168
|
resolver(true)
|
|
169
|
+
} else {
|
|
170
|
+
NotificationCenter.default.post(name: gOnVideoTemporarilyReleasePipController, object: nil)
|
|
171
|
+
presentedVC.dismiss(animated: true) {
|
|
172
|
+
NotificationCenter.default.post(name: gOnVideoRestorePipController, object: nil)
|
|
173
|
+
resolver(true)
|
|
174
|
+
}
|
|
143
175
|
}
|
|
144
176
|
} else {
|
|
145
177
|
resolver(false)
|