Skip to content

Commit

Permalink
Listen to pip ui state changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tvanlaerhoven committed Oct 23, 2024
1 parent eabf60e commit 2ffb066
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.reactnativetheoplayer

import android.app.PictureInPictureUiState
import android.content.Intent
import android.content.res.Configuration
import android.media.AudioManager
Expand Down Expand Up @@ -39,11 +40,18 @@ open class MainActivity : ReactActivity() {
override fun createReactActivityDelegate(): ReactActivityDelegate =
DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)

/**
* Called as part of the activity lifecycle when an activity is about to go into the background
* as the result of user choice.
*/
public override fun onUserLeaveHint() {
this.sendBroadcast(Intent("onUserLeaveHint"))
super.onUserLeaveHint()
}

/**
* Called by the system when the activity changes to and from picture-in-picture mode.
*/
override fun onPictureInPictureModeChanged(
isInPictureInPictureMode: Boolean,
newConfig: Configuration
Expand All @@ -55,4 +63,21 @@ open class MainActivity : ReactActivity() {
intent.putExtra("isInPictureInPictureMode", isInPictureInPictureMode)
this.sendBroadcast(intent)
}

/**
* Called by the system when the activity is in PiP and has state changes. Compare to
* onPictureInPictureModeChanged, which is only called when PiP mode changes (meaning, enters
* or exits PiP), this can be called at any time while the activity is in PiP mode.
*/
override fun onPictureInPictureUiStateChanged(pipState: PictureInPictureUiState) {
super.onPictureInPictureUiStateChanged(pipState)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM &&
pipState.isTransitioningToPip
) {
Intent("onPictureInPictureModeChanged").also {
it.putExtra("isTransitioningToPip", true)
sendBroadcast(it)
}
}
}
}

0 comments on commit 2ffb066

Please sign in to comment.