diff --git a/packages/react-native-sdk/src/components/Participant/FloatingParticipantView/index.tsx b/packages/react-native-sdk/src/components/Participant/FloatingParticipantView/index.tsx index a629dce938..6308b201be 100644 --- a/packages/react-native-sdk/src/components/Participant/FloatingParticipantView/index.tsx +++ b/packages/react-native-sdk/src/components/Participant/FloatingParticipantView/index.tsx @@ -6,7 +6,7 @@ import { View, type ViewStyle, } from 'react-native'; -import { FLOATING_VIDEO_VIEW_STYLE, Z_INDEX } from '../../../constants'; +import { Z_INDEX } from '../../../constants'; import { ComponentTestIds } from '../../../constants/TestIds'; import { VideoSlash } from '../../../icons'; import FloatingView from './FloatingView'; @@ -21,6 +21,7 @@ import { type ParticipantViewProps, } from '../ParticipantView'; import { useTheme } from '../../../contexts/ThemeContext'; +import { useFloatingVideoDimensions } from './useFloatingVideoDimensions'; import { type StreamVideoParticipant } from '@stream-io/video-client'; export type FloatingParticipantViewAlignment = @@ -104,7 +105,11 @@ export const FloatingParticipantView = ({ objectFit, }: FloatingParticipantViewProps) => { const { - theme: { colors, floatingParticipantsView }, + theme: { + colors, + floatingParticipantsView, + variants: { spacingSizes }, + }, } = useTheme(); const floatingAlignmentMap: Record< @@ -122,6 +127,12 @@ export const FloatingParticipantView = ({ height: number; }>(); + const floatingVideoDimensions = useFloatingVideoDimensions( + containerDimensions, + participant, + 'videoTrack', + ); + const participantViewProps: ParticipantViewComponentProps = { ParticipantLabel: null, ParticipantNetworkQualityIndicator, @@ -158,7 +169,7 @@ export const FloatingParticipantView = ({ }); }} > - {containerDimensions && ( + {containerDimensions && floatingVideoDimensions && ( { + const containerWidth = containerDimensions?.width ?? 0; + const { width, height } = useTrackDimensions(participant, trackType); + + if (width === 0 || height === 0 || containerWidth === 0) { + return undefined; + } + + const aspectRatio = width / height; + + // based on Android AOSP PiP mode default dimensions algorithm + // 23% of the container width + const floatingVideoWidth = containerWidth * 0.23; + // the height is calculated based on the aspect ratio + const floatingVideoHeight = floatingVideoWidth / aspectRatio; + + return { + width: floatingVideoWidth, + height: floatingVideoHeight, + }; +}; diff --git a/packages/react-native-sdk/src/constants/index.ts b/packages/react-native-sdk/src/constants/index.ts index 3de64a63d4..a8b63c099c 100644 --- a/packages/react-native-sdk/src/constants/index.ts +++ b/packages/react-native-sdk/src/constants/index.ts @@ -1,11 +1,5 @@ import { type StreamReactionType } from '../components'; -export const FLOATING_VIDEO_VIEW_STYLE = { - height: 140, - width: 80, - borderRadius: 10, -}; - export const defaultEmojiReactions: StreamReactionType[] = [ { type: 'reaction', diff --git a/packages/react-native-sdk/src/hooks/useTrackDimensions.ts b/packages/react-native-sdk/src/hooks/useTrackDimensions.ts index e3a203c9ab..f516c041d4 100644 --- a/packages/react-native-sdk/src/hooks/useTrackDimensions.ts +++ b/packages/react-native-sdk/src/hooks/useTrackDimensions.ts @@ -11,10 +11,10 @@ import { NativeEventEmitter, NativeModules } from 'react-native'; * `tracktype` should be 'videoTrack' for video track and 'screenShareTrack' for screen share track. */ export function useTrackDimensions( - participant: StreamVideoParticipant, + participant: StreamVideoParticipant | undefined, trackType: VideoTrackType, ) { - const { videoStream, screenShareStream } = participant; + const { videoStream, screenShareStream } = participant || {}; const stream = trackType === 'screenShareTrack' ? screenShareStream : videoStream; const [track] = stream?.getVideoTracks() ?? []; diff --git a/sample-apps/react-native/dogfood/src/theme.ts b/sample-apps/react-native/dogfood/src/theme.ts index 0ee73a89af..63fe2e6b2f 100644 --- a/sample-apps/react-native/dogfood/src/theme.ts +++ b/sample-apps/react-native/dogfood/src/theme.ts @@ -52,16 +52,6 @@ export const useCustomTheme = (mode: ThemeMode): DeepPartial => { container: { paddingTop: 0, paddingBottom: 0, flexDirection: 'column' }, }; - const { height, width } = Dimensions.get('window'); - const floatingParticipantsView: DeepPartial< - Theme['floatingParticipantsView'] - > = { - participantViewContainer: { - height: height * 0.2, - width: width * 0.25, - }, - }; - const lightThemeColors: DeepPartial = { buttonPrimary: '#3399ff', buttonSecondary: '#eff0f1', @@ -82,7 +72,6 @@ export const useCustomTheme = (mode: ThemeMode): DeepPartial => { const baseTheme: DeepPartial = { variants, callContent, - floatingParticipantsView, }; if (mode === 'light') {