@simba-dev/react-native-media-player 3.2.0 → 3.3.0

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.
@@ -189,12 +189,29 @@ class MpvRenderView(context: Context) : SurfaceView(context),
189
189
  }
190
190
  val location = IntArray(2)
191
191
  getLocationInWindow(location)
192
- cachedWindowBounds = PictureFrame(
192
+ val next = PictureFrame(
193
193
  location[0],
194
194
  location[1],
195
195
  location[0] + width,
196
196
  location[1] + height,
197
197
  )
198
+ val previous = cachedWindowBounds
199
+ cachedWindowBounds = next
200
+ if (previous != null &&
201
+ previous.left == next.left &&
202
+ previous.top == next.top &&
203
+ previous.right == next.right &&
204
+ previous.bottom == next.bottom
205
+ ) {
206
+ // The rect did not move, so the committed PiP params are still
207
+ // current. Layout passes are frequent, and re-committing the
208
+ // params on every one of them would be a binder call per frame.
209
+ return
210
+ }
211
+ // The rect moved, so the PiP params — which carry this rect as the
212
+ // source rect hint the platform crops the app's window to — are
213
+ // stale. The bridge re-commits them.
214
+ MpvBridgeModule.onPictureBoundsChanged()
198
215
  }
199
216
 
200
217
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simba-dev/react-native-media-player",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "React Native video & audio player powered by libmpv — Picture-in-Picture, MediaSession, foreground service, and a customizable TypeScript UI. Built for Android. Designed as a drop-in replacement for react-native-video / react-native-track-player / expo-av. See CHANGELOG.md for per-version notes.",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -526,18 +526,23 @@ export interface MpvPlayerModuleBridge {
526
526
  * returns it) and the caller needs it, because a caller that hides its
527
527
  * chrome on a refused request has no way to bring it back.
528
528
  *
529
- * The ORDER still matters, and the reason is REACT, not the window: an
530
- * Activity in Picture-in-Picture is "paused, but rendering" (AOSP), so the
531
- * PiP window keeps whatever the Activity's window held at the transition —
532
- * but React Native pauses the React scheduler with the Activity, so a
533
- * React commit cannot land and no frame is produced. Chrome that is still
534
- * mounted at that moment therefore stays in the PiP window, dead and
535
- * scaled down.
529
+ * The ORDER still matters, and the reason is REACT, not the window. While
530
+ * the Activity is paused, the app window's UI layer stops producing frames,
531
+ * while a SurfaceView keeps compositing. What stops is REACT, in TWO ways:
532
+ * `FabricUIManager.onHostPause()` removes the DISPATCH_UI frame callback,
533
+ * so mount items are never applied to native views, and
534
+ * `JavaTimerManager.onHostPause()` freezes the timer registry, so
535
+ * `requestAnimationFrame` never fires. The JS runtime itself keeps running.
536
+ *
537
+ * So the chrome has to be unmounted BEFORE the window is asked for, and the
538
+ * consumer's own button is the only place where that is still possible:
539
+ * `onUserLeaveHint()` is called as part of the Activity's PAUSE
540
+ * transaction, and there is NO frame between it and the pause.
536
541
  *
537
542
  * This is the MANUAL path — the consumer's own button. The HOME path is
538
- * the library's own: it hides the consumer's chrome natively, inside
539
- * `onUserLeaveHint()`, and enters PiP from there, because by then no React
540
- * commit can land at all.
543
+ * the library's own: it enters PiP from `onUserLeaveHint()` (or lets the
544
+ * platform's own auto-enter switch do it on Android 12+), and hides the
545
+ * consumer's chrome from `onPictureInPictureModeChanged(true)`.
541
546
  */
542
547
  enterPip(chapterTitle?: string | null, progressPct?: string | null): boolean;
543
548
  /** Exit PiP by bringing the activity to the front. */
@@ -56,26 +56,29 @@ export interface PipConfig {
56
56
  * leaves the app (home, recents, app switcher).
57
57
  *
58
58
  * The entry happens in native code, inside the Activity's
59
- * `onUserLeaveHint()`, because by then React Native has already paused the
60
- * React scheduler with the Activity: a React commit cannot land and there
61
- * is no frame clock, so a JS-driven entry cannot hide anything in time.
59
+ * `onUserLeaveHint()`, because by then React Native has ALREADY frozen, in
60
+ * TWO ways: `FabricUIManager.onHostPause()` removes the DISPATCH_UI frame
61
+ * callback, so mount items are never applied to native views, and
62
+ * `JavaTimerManager.onHostPause()` freezes the timer registry, so
63
+ * `requestAnimationFrame` never fires. The JS runtime itself keeps running.
62
64
  * Measured on emulator-5554 (API 37) on 2026-11-03: the JS handler ran
63
65
  * immediately, the effect that would have driven the entry ran 5.7 s late,
64
66
  * and the `requestAnimationFrame` never fired.
65
67
  *
66
- * The library deliberately does NOT arm Android's own auto-enter switch
67
- * (`PictureInPictureParams.Builder.setAutoEnterEnabled`): that makes the OS
68
- * transition the Activity with no chance to remove the app's own chrome. An
69
- * Activity in Picture-in-Picture is "paused, but rendering" — what stops is
70
- * REACT, not the window — so chrome that is still mounted when the
71
- * transition happens stays in the PiP window, dead and scaled down. See the
72
- * README's Picture-in-Picture section for the two lines of Kotlin that go
73
- * with it.
68
+ * On Android 12+ the library also arms Android's own auto-enter switch
69
+ * (`PictureInPictureParams.Builder.setAutoEnterEnabled`), but ONLY while
70
+ * media is loaded — and it commits the PiP params to the Activity early,
71
+ * because the platform builds the PiP window from the LAST COMMITTED params
72
+ * and crops the app's window to their source rect hint. That crop is what
73
+ * keeps the app's chrome out of the PiP window.
74
+ *
75
+ * See the README's Picture-in-Picture section for how the two mechanisms
76
+ * fit together.
74
77
  */
75
78
  autoEnterOnLeave: boolean;
76
79
  /**
77
80
  * The `nativeID` of the consumer's chrome root — the view the library hides
78
- * natively when it enters PiP on the HOME path.
81
+ * natively when it enters PiP.
79
82
  *
80
83
  * The literal belongs to the CONSUMER: the library stores it and uses it,
81
84
  * and never hardcodes one of its own. Put the same string on the
@@ -84,9 +87,10 @@ export interface PipConfig {
84
87
  * Omit it when the consumer draws no chrome of its own — then the library
85
88
  * enters PiP without hiding anything.
86
89
  *
87
- * When it IS set and no view carries that `nativeID`, the library REFUSES
88
- * the entry and logs a warning naming the id: entering PiP with the chrome
89
- * still mounted paints the app's dead chrome into the PiP window.
90
+ * When it IS set and no view carries that `nativeID`, the chrome is ALREADY
91
+ * gone — the consumer's own button path unmounts it in React before it asks
92
+ * for the window — so the library logs that and carries on. It never refuses
93
+ * the entry over a missing view.
90
94
  */
91
95
  chromeNativeId?: string;
92
96
  }