@simba-dev/react-native-media-player 3.1.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.1.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",
@@ -113,14 +113,12 @@ export interface LaunchParams {
113
113
  }
114
114
 
115
115
  /**
116
- * All 27 events emitted by the Kotlin bridge.
116
+ * All 26 events emitted by the Kotlin bridge.
117
117
  *
118
- * `onUserLeaveHint` is the 27th: the native side telling the consumer
119
- * that the user is leaving the app. It exists because a consumer that
120
- * draws its own chrome over the picture has to be able to remove that
121
- * chrome BEFORE the Activity enters Picture-in-Picture. See
122
- * `PipManager`'s note on why the OS-initiated transition cannot be used
123
- * for that.
118
+ * The HOME path is NOT one of them. The library enters Picture-in-Picture
119
+ * itself on that path (see `pip.autoEnterOnLeave`), so there is no "the
120
+ * user is leaving" event for a consumer to react to — the event's only
121
+ * consumer was the JS-driven entry the library took over.
124
122
  */
125
123
  export type PlayerEventName =
126
124
  | 'onFileLoaded'
@@ -148,8 +146,7 @@ export type PlayerEventName =
148
146
  | 'onPipModeChanged'
149
147
  | 'onPipPlayPause'
150
148
  | 'onPipExpand'
151
- | 'onPipClose'
152
- | 'onUserLeaveHint';
149
+ | 'onPipClose';
153
150
 
154
151
  /** Typed payload map for each event. */
155
152
  export interface PlayerEventPayloads {
@@ -208,17 +205,6 @@ export interface PlayerEventPayloads {
208
205
  onPipPlayPause: Record<string, never>;
209
206
  onPipExpand: Record<string, never>;
210
207
  onPipClose: Record<string, never>;
211
- /**
212
- * The user is leaving the app (home, recents, app switcher).
213
- *
214
- * A consumer that owns its own chrome over the picture uses this to
215
- * remove that chrome and THEN enter Picture-in-Picture itself. The
216
- * order is not negotiable: an Activity in PiP does not redraw, so
217
- * whatever its window contained at the moment of the transition is
218
- * what the PiP window keeps showing — frozen, dead and scaled down.
219
- * See `PipManager`'s note on the same thing.
220
- */
221
- onUserLeaveHint: Record<string, never>;
222
208
  }
223
209
 
224
210
  // ═══════════════════════════════════════════════════════════════════════════
@@ -539,6 +525,24 @@ export interface MpvPlayerModuleBridge {
539
525
  * happen — the native side has the answer (`enterPictureInPictureMode`
540
526
  * returns it) and the caller needs it, because a caller that hides its
541
527
  * chrome on a refused request has no way to bring it back.
528
+ *
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.
541
+ *
542
+ * This is the MANUAL path — the consumer's own button. The HOME path is
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)`.
542
546
  */
543
547
  enterPip(chapterTitle?: string | null, progressPct?: string | null): boolean;
544
548
  /** Exit PiP by bringing the activity to the front. */
@@ -1075,7 +1079,7 @@ export function removeAllListeners(event?: PlayerEventName): void {
1075
1079
  }
1076
1080
 
1077
1081
  /**
1078
- * All 27 player event names — the ONE owner of this list.
1082
+ * All 26 player event names — the ONE owner of this list.
1079
1083
  *
1080
1084
  * `<PlayerProvider>` imports it to subscribe to every event on mount,
1081
1085
  * `removeAllListeners()` iterates it when no event is named, and the
@@ -1109,5 +1113,4 @@ export const ALL_PLAYER_EVENTS: readonly PlayerEventName[] = [
1109
1113
  'onPipPlayPause',
1110
1114
  'onPipExpand',
1111
1115
  'onPipClose',
1112
- 'onUserLeaveHint',
1113
1116
  ];
@@ -52,18 +52,47 @@ export interface PipConfig {
52
52
  /** Master switch — when false, all PiP entry requests are ignored. */
53
53
  enabled: boolean;
54
54
  /**
55
- * When true, the library reports that the user is leaving the app, through
56
- * the `onUserLeaveHint` event, and the CONSUMER enters PiP itself.
55
+ * When true, the library enters Picture-in-Picture ITSELF when the user
56
+ * leaves the app (home, recents, app switcher).
57
57
  *
58
- * The library deliberately does NOT arm Android's own auto-enter switch
59
- * (`PictureInPictureParams.Builder.setAutoEnterEnabled`): that makes the OS
60
- * transition the Activity without giving the app a chance to remove its own
61
- * chrome, and an Activity in Picture-in-Picture does not redraw — so the
62
- * chrome is frozen into the PiP window as a dead layer. See the README's
63
- * Picture-in-Picture section for the two lines of Kotlin and the JS that
64
- * go with it.
58
+ * The entry happens in native code, inside the Activity's
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.
64
+ * Measured on emulator-5554 (API 37) on 2026-11-03: the JS handler ran
65
+ * immediately, the effect that would have driven the entry ran 5.7 s late,
66
+ * and the `requestAnimationFrame` never fired.
67
+ *
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.
65
77
  */
66
78
  autoEnterOnLeave: boolean;
79
+ /**
80
+ * The `nativeID` of the consumer's chrome root — the view the library hides
81
+ * natively when it enters PiP.
82
+ *
83
+ * The literal belongs to the CONSUMER: the library stores it and uses it,
84
+ * and never hardcodes one of its own. Put the same string on the
85
+ * consumer's chrome `<View nativeID="...">`.
86
+ *
87
+ * Omit it when the consumer draws no chrome of its own — then the library
88
+ * enters PiP without hiding anything.
89
+ *
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.
94
+ */
95
+ chromeNativeId?: string;
67
96
  }
68
97
 
69
98
  /** Audio playback configuration. */
@@ -1479,7 +1479,6 @@ export function applyPlayerEvent(
1479
1479
  case 'onPipPlayPause':
1480
1480
  case 'onPipExpand':
1481
1481
  case 'onPipClose':
1482
- case 'onUserLeaveHint':
1483
1482
  // No state-field mapping for these in the V13 surface (PiP state
1484
1483
  // is owned by the activity; reconfig signals a video-parameter
1485
1484
  // change that's already covered by onVideoParamsChanged).