Skip to content

Commit 7803f2c

Browse files
authored
fix: missing adaptive floating dimensions for landscape video (#1983)
### 💡 Overview Follow up to #1969 The current algorithm only handles portrait local video on floating view. Which is default on mobile. But we can change it to landscape video from web for example. Landscape video needs more width. And this PR fixes it. Again, based on Android AOSP algorithm here. Additionally, we use screen dimensions to compute the base dimensions now. Because, say if integrator wants to constrain the CallContent to small view, the floating dimensions can become extremely small. Using screen dimensions make it independent of that. This is consistent with Android PiP mode also. | Portrait video | Landscape video | | ------------- | ------------- | | <img width="1080" height="2400" alt="Screenshot_20251106-114806" src="https://github.com/user-attachments/assets/fbe5845d-d962-4f95-9609-a9da3856413e" /> | <img width="1080" height="2400" alt="Screenshot_20251106-114758" src="https://github.com/user-attachments/assets/5ee4143f-f29d-4031-9ae5-b5ae4559fbf2" /> | Ticket: https://linear.app/stream/issue/RN-302
1 parent f8e5c6e commit 7803f2c

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

packages/react-native-sdk/src/components/Participant/FloatingParticipantView/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ export const FloatingParticipantView = ({
128128
}>();
129129

130130
const floatingVideoDimensions = useFloatingVideoDimensions(
131-
containerDimensions,
132131
participant,
133132
'videoTrack',
134133
);

packages/react-native-sdk/src/components/Participant/FloatingParticipantView/useFloatingVideoDimensions.tsx

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,43 @@ import {
33
VideoTrackType,
44
} from '@stream-io/video-client';
55
import { useTrackDimensions } from '../../../hooks/useTrackDimensions';
6+
import { useWindowDimensions } from 'react-native';
67

78
export const useFloatingVideoDimensions = (
8-
containerDimensions:
9-
| {
10-
width: number;
11-
height: number;
12-
}
13-
| undefined,
149
participant: StreamVideoParticipant | undefined,
1510
trackType: VideoTrackType,
1611
) => {
17-
const containerWidth = containerDimensions?.width ?? 0;
12+
const { width: containerWidth, height: containerHeight } =
13+
useWindowDimensions();
1814
const { width, height } = useTrackDimensions(participant, trackType);
1915

20-
if (width === 0 || height === 0 || containerWidth === 0) {
16+
if (
17+
width === 0 ||
18+
height === 0 ||
19+
containerWidth === 0 ||
20+
containerHeight === 0
21+
) {
2122
return undefined;
2223
}
2324

24-
const aspectRatio = width / height;
25-
2625
// based on Android AOSP PiP mode default dimensions algorithm
27-
// 23% of the container width
28-
const floatingVideoWidth = containerWidth * 0.23;
29-
// the height is calculated based on the aspect ratio
30-
const floatingVideoHeight = floatingVideoWidth / aspectRatio;
26+
// 23% of the shorter container dimension is the base dimension
27+
const shorterContainerDimension = Math.min(containerWidth, containerHeight);
28+
const baseDimension = shorterContainerDimension * 0.23;
3129

32-
return {
33-
width: floatingVideoWidth,
34-
height: floatingVideoHeight,
35-
};
30+
const aspectRatio = width / height;
31+
const isPortraitVideo = aspectRatio < 1;
32+
33+
// baseDimension is assigned to either height or width based on whether the video is landscape or portrait
34+
if (isPortraitVideo) {
35+
return {
36+
width: baseDimension,
37+
height: baseDimension / aspectRatio,
38+
};
39+
} else {
40+
return {
41+
width: baseDimension * aspectRatio,
42+
height: baseDimension,
43+
};
44+
}
3645
};

0 commit comments

Comments
 (0)