react-native-spalla-player 0.16.2 → 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.
@@ -11,6 +11,7 @@ class SpallaPlayerPipModule(reactContext: ReactApplicationContext) : ReactContex
11
11
  companion object {
12
12
  const val NAME = "SpallaPlayerPipModule"
13
13
  private var activePlayerManager: RNSpallaPlayerManager? = null
14
+ private var instance: SpallaPlayerPipModule? = null
14
15
 
15
16
  fun registerPlayerManager(manager: RNSpallaPlayerManager) {
16
17
  activePlayerManager = manager
@@ -21,12 +22,27 @@ class SpallaPlayerPipModule(reactContext: ReactApplicationContext) : ReactContex
21
22
  activePlayerManager = null
22
23
  }
23
24
  }
25
+
26
+ /**
27
+ * A static method that MainActivity can call without needing a ReactContext.
28
+ * It safely forwards the call to the active module instance.
29
+ */
30
+ fun triggerUserLeaveHint() {
31
+ // Check if an instance exists before calling the method
32
+ instance?.onUserLeaveHint()
33
+ }
24
34
  }
25
35
 
26
36
  override fun getName(): String = NAME
27
37
 
38
+ init {
39
+ // When React Native creates the module, assign it to our static property
40
+ instance = this
41
+ }
42
+
28
43
  @ReactMethod
29
44
  fun onUserLeaveHint() {
30
45
  activePlayerManager?.triggerPipImmediate()
31
46
  }
47
+
32
48
  }
@@ -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.2",
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",
@@ -82,7 +82,6 @@
82
82
  "react": "18.3.1",
83
83
  "react-native": "0.75.4",
84
84
  "react-native-builder-bob": "^0.30.2",
85
- "react-native-safe-area-context": "^5.4.1",
86
85
  "release-it": "^15.0.0",
87
86
  "turbo": "^1.10.7",
88
87
  "typescript": "^5.2.2"
@@ -92,8 +91,7 @@
92
91
  },
93
92
  "peerDependencies": {
94
93
  "react": "*",
95
- "react-native": "*",
96
- "react-native-safe-area-context": "*"
94
+ "react-native": "*"
97
95
  },
98
96
  "workspaces": [
99
97
  "example"
@@ -47,9 +47,7 @@ import com.spallaplayer.SpallaPlayerPipModule`
47
47
  const method = `
48
48
  override fun onUserLeaveHint() {
49
49
  super.onUserLeaveHint()
50
- reactNativeHost.reactInstanceManager.currentReactContext?.let { context ->
51
- context.getNativeModule(SpallaPlayerPipModule::class.java)?.onUserLeaveHint()
52
- }
50
+ SpallaPlayerPipModule.triggerUserLeaveHint()
53
51
  }
54
52
  `;
55
53