diff --git a/example/android/app/src/main/java/com/reactnativetheoplayer/MainActivity.kt b/example/android/app/src/main/java/com/reactnativetheoplayer/MainActivity.kt index 7876d2a21..2a178f4dc 100644 --- a/example/android/app/src/main/java/com/reactnativetheoplayer/MainActivity.kt +++ b/example/android/app/src/main/java/com/reactnativetheoplayer/MainActivity.kt @@ -1,5 +1,6 @@ package com.reactnativetheoplayer +import android.app.PictureInPictureUiState import android.content.Intent import android.content.res.Configuration import android.media.AudioManager @@ -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 @@ -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) + } + } + } }