react-native-spalla-player 0.16.3 → 0.16.4

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.
@@ -6,7 +6,6 @@ import androidx.appcompat.app.AppCompatActivity
6
6
  import androidx.core.app.PictureInPictureModeChangedInfo
7
7
  import androidx.core.util.Consumer
8
8
  import com.facebook.react.bridge.Arguments
9
- import com.facebook.react.bridge.LifecycleEventListener
10
9
  import com.facebook.react.bridge.ReactContext
11
10
  import com.facebook.react.bridge.WritableMap
12
11
  import com.facebook.react.uimanager.ViewGroupManager
@@ -46,12 +45,15 @@ class RNSpallaPlayerManager() : ViewGroupManager<SpallaPlayerContainerView>(),
46
45
  // Reset the flag when PiP mode changes
47
46
  pipTriggered = false
48
47
 
49
- _container?.let { container ->
50
- _reactContext?.getJSModule(RCTEventEmitter::class.java)?.receiveEvent(
51
- container.id,
52
- "onPlayerEvent",
53
- map
54
- )
48
+ // we will only dispatch exits for now
49
+ if(!info.isInPictureInPictureMode) {
50
+ _container?.let { container ->
51
+ _reactContext?.getJSModule(RCTEventEmitter::class.java)?.receiveEvent(
52
+ container.id,
53
+ "onPlayerEvent",
54
+ map
55
+ )
56
+ }
55
57
  }
56
58
  _reactContext?.currentActivity?.let { activity ->
57
59
  _playerView?.onPictureInPictureModeChanged(activity, info.isInPictureInPictureMode)
@@ -93,7 +95,11 @@ class RNSpallaPlayerManager() : ViewGroupManager<SpallaPlayerContainerView>(),
93
95
 
94
96
  override fun onDropViewInstance(view: SpallaPlayerContainerView) {
95
97
  Log.v("RNSpallaPlayerManager", "onDropViewInstance")
96
- //_reactContext?.removeLifecycleEventListener(this)
98
+
99
+ if (_reactContext?.currentActivity is AppCompatActivity) {
100
+ val activity = _reactContext?.currentActivity as? AppCompatActivity
101
+ activity?.removeOnPictureInPictureModeChangedListener(pipModeListener)
102
+ }
97
103
 
98
104
  // Unregister this manager
99
105
  SpallaPlayerPipModule.unregisterPlayerManager(this)
@@ -307,6 +313,19 @@ class RNSpallaPlayerManager() : ViewGroupManager<SpallaPlayerContainerView>(),
307
313
  fun triggerPipImmediate() {
308
314
  if (pipTriggered) return
309
315
 
316
+ // dispatch early, as waiting for the callback on piplistener may be too late
317
+ val map: WritableMap = Arguments.createMap()
318
+ map.putString("event", "enterPiP")
319
+ map.putBoolean("isInPictureInPictureMode", true)
320
+
321
+ _container?.let { container ->
322
+ _reactContext?.getJSModule(RCTEventEmitter::class.java)?.receiveEvent(
323
+ container.id,
324
+ "onPlayerEvent",
325
+ map
326
+ )
327
+ }
328
+
310
329
  _playerView?.let { player ->
311
330
  val activity = _reactContext?.currentActivity
312
331
  if (activity != null && isPlaying) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-spalla-player",
3
- "version": "0.16.3",
3
+ "version": "0.16.4",
4
4
  "description": "Spalla SDK for RN",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/commonjs/index.js",