@simba-dev/react-native-media-player 1.23.0 → 2.0.1
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.
- package/android/src/main/java/com/simba/player/mpv/MpvBridgeModule.kt +10 -2
- package/android/src/main/java/com/simba/player/mpv/MpvRenderViewManager.kt +11 -1
- package/android/src/main/java/com/simba/player/mpv/MpvRenderViewRegistry.kt +132 -0
- package/android/src/main/java/com/simba/player/mpv/PlayerSurface.kt +41 -1
- package/android/src/test/java/com/simba/player/mpv/MpvRenderViewRegistryTest.kt +120 -0
- package/package.json +1 -1
- package/src/bridge/MpvPlayerModule.ts +10 -5
- package/src/bridge/NativeMpvPlayer.ts +3 -3
- package/src/bridge/__tests__/MpvPlayerModule.test.ts +53 -0
- package/src/components/PlayerProvider.tsx +18 -15
- package/src/components/PlayerRoot.tsx +23 -46
- package/src/components/PlayerSurface.tsx +27 -37
- package/src/components/__tests__/PlayerProvider.test.tsx +4 -4
- package/src/components/__tests__/PlayerRoot.test.tsx +71 -0
- package/src/index.ts +19 -5
- package/src/types/__tests__/config.test.ts +1 -1
- package/src/types/__tests__/player.test.tsx +6 -6
- package/src/types/player.ts +10 -4
- package/src/components/DefaultControls.tsx +0 -564
- package/src/components/__tests__/DefaultControls.test.tsx +0 -253
|
@@ -3,51 +3,41 @@ import { StyleSheet, View } from 'react-native';
|
|
|
3
3
|
|
|
4
4
|
export interface PlayerSurfaceProps {
|
|
5
5
|
/**
|
|
6
|
-
* Background color for the placeholder. Defaults to
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* Consumers that want a colored backdrop (e.g. for branded
|
|
14
|
-
* splash screens while mpv initializes) can pass a non-transparent
|
|
15
|
-
* value — the actual video frames paint over it once mpv's
|
|
16
|
-
* first frame is decoded.
|
|
6
|
+
* Background color for the placeholder. Defaults to `'transparent'`,
|
|
7
|
+
* so whatever is behind it shows through to the user.
|
|
8
|
+
*
|
|
9
|
+
* **v2.0.0:** the native SurfaceView this placeholder used to stand
|
|
10
|
+
* in for is gone — the picture is `<SimbaVideo />`, in the React
|
|
11
|
+
* tree. A non-transparent value therefore paints a backdrop *over*
|
|
12
|
+
* the picture wherever the placeholder sits in front of it.
|
|
17
13
|
*/
|
|
18
14
|
backgroundColor?: string;
|
|
19
15
|
}
|
|
20
16
|
|
|
21
17
|
/**
|
|
22
|
-
*
|
|
23
|
-
* SurfaceView. The actual SurfaceView that mpv draws into lives on
|
|
24
|
-
* the Kotlin side of PlayerActivity (`MpvRenderView` in the module
|
|
25
|
-
* + `PlayerActivity.onCreate`'s `setContentView`). This JS
|
|
26
|
-
* component exists only to reserve layout space in the React tree
|
|
27
|
-
* so the controls overlay knows where to anchor.
|
|
18
|
+
* A transparent, full-size **layout placeholder**.
|
|
28
19
|
*
|
|
29
|
-
*
|
|
30
|
-
* - The native SurfaceView is attached to the activity's
|
|
31
|
-
* `android.R.id.content` FrameLayout directly (see Phase 4). It
|
|
32
|
-
* is NOT a child of the React root view, so it doesn't need a
|
|
33
|
-
* JS counterpart.
|
|
34
|
-
* - The placeholder fills the same screen rectangle as the native
|
|
35
|
-
* SurfaceView because PlayerActivity pins the React root to the
|
|
36
|
-
* same insets the SurfaceView occupies (Phase 15 — full-screen
|
|
37
|
-
* with status / nav bar handling).
|
|
38
|
-
* - Adding `position: 'absolute'` here would force the controls
|
|
39
|
-
* sibling to also be absolutely positioned. Using `flex: 1`
|
|
40
|
-
* keeps the React tree in normal flow; the controls are placed
|
|
41
|
-
* as a sibling with absolute positioning by `PlayerRoot`.
|
|
20
|
+
* ## v2.0.0 — what this is, and is not
|
|
42
21
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* tests).
|
|
22
|
+
* This component used to stand in for the native SurfaceView that mpv
|
|
23
|
+
* drew into. Back then the surface was a **sibling** of the React
|
|
24
|
+
* root — pinned to `android.R.id.content` by the library's own
|
|
25
|
+
* `PlayerActivity` — and this box reserved the screen rectangle the
|
|
26
|
+
* controls overlay was positioned against.
|
|
49
27
|
*
|
|
50
|
-
*
|
|
28
|
+
* **That arrangement is gone.** The picture is now `<SimbaVideo />`:
|
|
29
|
+
* a Fabric component (`SimbaVideoView`) inside the React tree, with
|
|
30
|
+
* React Native owning its layout, its z-order and its lifecycle.
|
|
31
|
+
* Neither the library nor a host app mounts a surface at the activity
|
|
32
|
+
* root any more — a host app's Activity says so in as many words.
|
|
33
|
+
*
|
|
34
|
+
* What is left is a transparent `flex: 1` box: a full-size rectangle
|
|
35
|
+
* for a controls overlay to anchor to. `<PlayerRoot>` renders it.
|
|
36
|
+
*
|
|
37
|
+
* Whether this component and `<PlayerRoot>` should exist at all is an
|
|
38
|
+
* open question — see `B-035` in the app's master plan. Until that is
|
|
39
|
+
* decided they stay: a published package cannot quietly drop a public
|
|
40
|
+
* export.
|
|
51
41
|
*/
|
|
52
42
|
export function PlayerSurface({
|
|
53
43
|
backgroundColor = 'transparent',
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* - useRenderControls returns null when no renderControls prop is
|
|
14
14
|
* provided, the provided function otherwise
|
|
15
15
|
* - useRenderControls does NOT throw outside provider (falls back to
|
|
16
|
-
* null so
|
|
16
|
+
* null so a consumer's controls can render)
|
|
17
17
|
* - Provider passes resolved config to native bridge via setConfig
|
|
18
18
|
* on mount and when the config prop changes
|
|
19
19
|
* - Provider does NOT call setConfig when config prop is reference-
|
|
@@ -157,9 +157,9 @@ describe('useRenderControls', () => {
|
|
|
157
157
|
|
|
158
158
|
it('returns null when called outside a provider (does NOT throw)', async () => {
|
|
159
159
|
// Important behavioural difference from usePlayerConfig/useTheme:
|
|
160
|
-
// useRenderControls is non-throwing so
|
|
161
|
-
// unconditionally. (If a consumer
|
|
162
|
-
// without a Provider, they get
|
|
160
|
+
// useRenderControls is non-throwing so a consumer's controls can render
|
|
161
|
+
// unconditionally. (If a consumer renders their own controls
|
|
162
|
+
// without a Provider, they get no chrome, not a crash.)
|
|
163
163
|
const { result } = await renderHook(() => useRenderControls());
|
|
164
164
|
expect(result.current).toBeNull();
|
|
165
165
|
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for `src/components/PlayerRoot.tsx`.
|
|
3
|
+
*
|
|
4
|
+
* v2.0.0 (the app's register item 28) — **the library draws no chrome.**
|
|
5
|
+
*
|
|
6
|
+
* `DefaultControls` was removed, so `<PlayerRoot>` has no fallback: with
|
|
7
|
+
* no `renderControls`, it renders the surface and NOTHING else. Before
|
|
8
|
+
* 2.0.0 it fell back to a 564-line control bundle the library shipped,
|
|
9
|
+
* which meant the library always had a chrome implementation a consumer
|
|
10
|
+
* could end up using by accident.
|
|
11
|
+
*
|
|
12
|
+
* Test surface:
|
|
13
|
+
* - no `renderControls` → the surface, and no second child
|
|
14
|
+
* - `renderControls` → the consumer's controls, over the surface
|
|
15
|
+
* - the package does not export a default control bundle
|
|
16
|
+
*
|
|
17
|
+
* The first test is the "must not" test: it fails if a chrome fallback
|
|
18
|
+
* ever comes back, because a fallback is a second child of the root.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import React from 'react';
|
|
22
|
+
import { Text } from 'react-native';
|
|
23
|
+
import { render, screen } from '@testing-library/react-native';
|
|
24
|
+
import { PlayerRoot } from '../PlayerRoot';
|
|
25
|
+
import { PlayerProvider } from '../PlayerProvider';
|
|
26
|
+
|
|
27
|
+
describe('PlayerRoot', () => {
|
|
28
|
+
it('renders the surface and nothing else when the consumer supplies no controls', async () => {
|
|
29
|
+
await render(
|
|
30
|
+
<PlayerProvider>
|
|
31
|
+
<PlayerRoot />
|
|
32
|
+
</PlayerProvider>,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const tree = screen.toJSON();
|
|
36
|
+
expect(tree).not.toBeNull();
|
|
37
|
+
|
|
38
|
+
// The host tree is a plain View tree, so the root is the tree's
|
|
39
|
+
// root node. `children` is typed loosely on purpose: the
|
|
40
|
+
// `test-renderer` version has changed this shape before.
|
|
41
|
+
const root = tree as unknown as { type: string; children: unknown };
|
|
42
|
+
expect(root.type).toBe('View');
|
|
43
|
+
|
|
44
|
+
// Exactly ONE child: the surface. A chrome fallback would be a
|
|
45
|
+
// second child, and this is what kills the mutation.
|
|
46
|
+
const children = Array.isArray(root.children) ? root.children : [];
|
|
47
|
+
expect(children).toHaveLength(1);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('renders the controls the consumer supplied, over the surface', async () => {
|
|
51
|
+
await render(
|
|
52
|
+
<PlayerProvider renderControls={() => <Text>my controls</Text>}>
|
|
53
|
+
<PlayerRoot />
|
|
54
|
+
</PlayerProvider>,
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
expect(screen.getByText('my controls')).toBeTruthy();
|
|
58
|
+
|
|
59
|
+
const tree = screen.toJSON();
|
|
60
|
+
expect(tree).not.toBeNull();
|
|
61
|
+
const root = tree as unknown as { children: unknown };
|
|
62
|
+
const children = Array.isArray(root.children) ? root.children : [];
|
|
63
|
+
expect(children).toHaveLength(2);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('does not export a default control bundle', async () => {
|
|
67
|
+
const lib = require('../../index') as Record<string, unknown>;
|
|
68
|
+
expect(Object.keys(lib)).not.toContain('DefaultControls');
|
|
69
|
+
expect(lib.DefaultControls).toBeUndefined();
|
|
70
|
+
});
|
|
71
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -25,6 +25,25 @@
|
|
|
25
25
|
* lookup for you. A consumer that drives the player itself wraps its
|
|
26
26
|
* tree in `<PlayerProvider>` once and renders `<SimbaVideo>` for the
|
|
27
27
|
* picture.
|
|
28
|
+
*
|
|
29
|
+
* ## v2.0.0 — the library draws no chrome
|
|
30
|
+
*
|
|
31
|
+
* `DefaultControls` and `DefaultControlsProps` are **removed**. The
|
|
32
|
+
* library shipped a 564-line default control bundle and wired it as
|
|
33
|
+
* `<PlayerRoot>`'s fallback whenever a consumer did not pass
|
|
34
|
+
* `renderControls` — which meant the library always had a chrome
|
|
35
|
+
* implementation that a consumer could end up using by accident, and
|
|
36
|
+
* that the library had to keep working.
|
|
37
|
+
*
|
|
38
|
+
* The contract now says what it means: **the library draws no chrome.**
|
|
39
|
+
* A consumer that wants controls renders them, through the
|
|
40
|
+
* `renderControls` slot on `<PlayerProvider>`. `<PlayerRoot>` renders
|
|
41
|
+
* the surface and the consumer's controls, and **nothing else** when
|
|
42
|
+
* `renderControls` is absent.
|
|
43
|
+
*
|
|
44
|
+
* This is a **breaking** change, hence the major version. `<PlayerRoot>`
|
|
45
|
+
* without `renderControls` renders no controls after 2.0.0, where it
|
|
46
|
+
* rendered `DefaultControls` before.
|
|
28
47
|
*/
|
|
29
48
|
|
|
30
49
|
export {
|
|
@@ -46,11 +65,6 @@ export {
|
|
|
46
65
|
|
|
47
66
|
export { PlayerSurface, type PlayerSurfaceProps } from './components/PlayerSurface';
|
|
48
67
|
|
|
49
|
-
export {
|
|
50
|
-
DefaultControls,
|
|
51
|
-
type DefaultControlsProps,
|
|
52
|
-
} from './components/DefaultControls';
|
|
53
|
-
|
|
54
68
|
export {
|
|
55
69
|
type AudioConfig,
|
|
56
70
|
type DebugConfig,
|
|
@@ -133,7 +133,7 @@ describe('resolvePlayerConfig', () => {
|
|
|
133
133
|
describe('DEFAULT_THEME', () => {
|
|
134
134
|
it('exposes the documented dark theme', () => {
|
|
135
135
|
// Lock the values so consumers can rely on them (and so the
|
|
136
|
-
//
|
|
136
|
+
// a consumer's visual baseline doesn't drift accidentally).
|
|
137
137
|
// `icon` is intentionally absent — it's an optional override in
|
|
138
138
|
// PlayerTheme (see types/config.ts).
|
|
139
139
|
expect(DEFAULT_THEME).toEqual({
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* tests pin the documented baseline (via `EXPECTED_DEFAULT_STATE`)
|
|
6
6
|
* and verify the contract that matters for consumers:
|
|
7
7
|
* - `usePlayer()` outside a provider returns the default state
|
|
8
|
-
* (no throw —
|
|
8
|
+
* (no throw — a consumer's controls must be able to render anywhere)
|
|
9
9
|
* - `usePlayer()` inside a provider returns the live state
|
|
10
10
|
* - `usePlayer()` returns stable command references across renders
|
|
11
11
|
* - `commands.<method>` delegates to the native bridge
|
|
@@ -98,7 +98,7 @@ describe('usePlayer (no provider)', () => {
|
|
|
98
98
|
|
|
99
99
|
it('returns the documented default state', async () => {
|
|
100
100
|
// Outside a <PlayerProvider>, usePlayer must NOT throw — it
|
|
101
|
-
// returns DEFAULT_STATE so
|
|
101
|
+
// returns DEFAULT_STATE so a consumer's controls can render in any
|
|
102
102
|
// environment (jest, web preview, Storybook).
|
|
103
103
|
const { result } = await renderHook(() => usePlayer());
|
|
104
104
|
expect(result.current.state).toEqual(DEFAULT_STATE);
|
|
@@ -107,7 +107,7 @@ describe('usePlayer (no provider)', () => {
|
|
|
107
107
|
it('returns the expected V12 fields at their baseline', async () => {
|
|
108
108
|
// Pin the V12 contract: isPlaying=false, title='Simba Player',
|
|
109
109
|
// artist='', album=''. A refactor that changes the baseline
|
|
110
|
-
// would silently break
|
|
110
|
+
// would silently break every consumer's controls.
|
|
111
111
|
const { result } = await renderHook(() => usePlayer());
|
|
112
112
|
const s = result.current.state;
|
|
113
113
|
expect(s.isPlaying).toBe(false);
|
|
@@ -144,7 +144,7 @@ describe('usePlayer (no provider)', () => {
|
|
|
144
144
|
|
|
145
145
|
it('exposes the V12 commands object', async () => {
|
|
146
146
|
// The five V12 methods remain on the new commands object —
|
|
147
|
-
//
|
|
147
|
+
// Consumer controls depend on them.
|
|
148
148
|
const { result } = await renderHook(() => usePlayer());
|
|
149
149
|
expect(typeof result.current.commands.play).toBe('function');
|
|
150
150
|
expect(typeof result.current.commands.pause).toBe('function');
|
|
@@ -376,8 +376,8 @@ describe('usePlayer (no provider)', () => {
|
|
|
376
376
|
});
|
|
377
377
|
|
|
378
378
|
it('returns stable command references across renders', async () => {
|
|
379
|
-
// Spec §Phase 34.5: stable command references let
|
|
380
|
-
// memo
|
|
379
|
+
// Spec §Phase 34.5: stable command references let a consumer's
|
|
380
|
+
// controls memo their handlers. The V13 commands object is a module-scope
|
|
381
381
|
// singleton, so the reference is identical for every render.
|
|
382
382
|
const { result, rerender } = await renderHook(() => usePlayer());
|
|
383
383
|
const firstCommands = result.current.commands;
|
package/src/types/player.ts
CHANGED
|
@@ -394,7 +394,13 @@ export interface PlayerCommands {
|
|
|
394
394
|
* audio-only playback — mpv keeps running with no render target.
|
|
395
395
|
*/
|
|
396
396
|
setSurfaceVisible(visible: boolean): Promise<boolean>;
|
|
397
|
-
/**
|
|
397
|
+
/**
|
|
398
|
+
* Whether a video picture view is mounted in the React tree right now.
|
|
399
|
+
*
|
|
400
|
+
* The picture is a Fabric view (`SimbaVideoView`) that React Native's
|
|
401
|
+
* ViewManager creates, so this answers "is there somewhere to put a
|
|
402
|
+
* video?" — and it is false until a consumer mounts `<SimbaVideo />`.
|
|
403
|
+
*/
|
|
398
404
|
isSurfaceMounted(): boolean;
|
|
399
405
|
|
|
400
406
|
/**
|
|
@@ -876,7 +882,7 @@ const BUILT_COMMANDS: PlayerCommands = buildCommands();
|
|
|
876
882
|
* driven by mpv events (via `subscribePlayerEvent`) plus a one-shot
|
|
877
883
|
* hydration read at mount. Outside a provider, `state` is
|
|
878
884
|
* `DEFAULT_STATE` (no throw — see Phase 24 design notes: this
|
|
879
|
-
* hook is non-throwing so
|
|
885
|
+
* hook is non-throwing so a consumer's own controls can render in any
|
|
880
886
|
* environment, including web previews and tests).
|
|
881
887
|
*
|
|
882
888
|
* The `commands` object is a module-singleton: the same reference
|
|
@@ -1485,7 +1491,7 @@ export function applyPlayerEvent(
|
|
|
1485
1491
|
* `<PlayerStateProvider>` component (in `PlayerProvider.tsx`)
|
|
1486
1492
|
* can import them. The component itself is a JSX component, so
|
|
1487
1493
|
* it has to live in a `.tsx` file — we keep the contexts in
|
|
1488
|
-
* this `.ts` file so non-JSX consumers (
|
|
1489
|
-
*
|
|
1494
|
+
* this `.ts` file so non-JSX consumers (`usePlayer`, etc.) can
|
|
1495
|
+
* import them without forcing the JSX
|
|
1490
1496
|
* transform on the whole module.
|
|
1491
1497
|
*/
|