GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(mobile): videos keep their own aspect ratio · pingdotgg/t3code@43a48de

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/mobile/src
    • components
      • MediaVideoPlayer.tsx
    • lib
      • useMediaVideoPlayback.test.tsx
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/mobile/src/components/MediaVideoPlayer.tsx‎

Copy file name to clipboardExpand all lines: apps/mobile/src/components/MediaVideoPlayer.tsx
+27-12Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useVideoPlayer, VideoView } from "expo-video";
33
import { useIsFocused } from "@react-navigation/native";
44
import { T, useGT } from "gt-react-native";
55
import { useEffect, useEffectEvent, useLayoutEffect, useRef, useState } from "react";
6-
import { Pressable, View } from "react-native";
6+
import { Pressable, View, type LayoutChangeEvent } from "react-native";
77

88
import { AppActivityIndicator } from "./ui/AppActivityIndicator";
99
import { AppText } from "./ui/AppText";
@@ -155,6 +155,8 @@ interface MediaVideoPlayerProps {
155155
readonly borderRadius?: number;
156156
}
157157

158+
const INLINE_MAX_SIZE = 480;
159+
158160
function MediaVideoPlayerContent(props: MediaVideoPlayerProps) {
159161
const gt = useGT();
160162
const mediaActions = useMediaActions(props.actionsSource);
@@ -167,7 +169,9 @@ function MediaVideoPlayerContent(props: MediaVideoPlayerProps) {
167169
: gt("Video unavailable");
168170
const [videoSize, setVideoSize] = useState<{ width: number; height: number } | null>(null);
169171
const [bounds, setBounds] = useState<{ width: number; height: number } | null>(null);
170-
const sizeSource = props.fitToVideo && isFocused && videoSize === null ? props.uri : null;
172+
const inline = !props.expanded && !props.fitToVideo;
173+
const measuresVideo = props.fitToVideo || (inline && props.thumbnailVisible !== false);
174+
const sizeSource = measuresVideo && isFocused && videoSize === null ? props.uri : null;
171175
// Queue before the poster so early Play cannot cancel the extraction that supplies frame dimensions.
172176
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- loads native thumbnail dimensions independently of the poster's lifetime
173177
useLayoutEffect(() => {
@@ -186,7 +190,17 @@ function MediaVideoPlayerContent(props: MediaVideoPlayerProps) {
186190
return () => controller.abort();
187191
}, [props.thumbnailKey, sizeSource]);
188192
const fittedFrame =
189-
props.fitToVideo && videoSize && bounds ? fitVideoFrame(videoSize, bounds, 480) : null;
193+
videoSize && bounds
194+
? fitVideoFrame(
195+
videoSize,
196+
inline ? { width: bounds.width, height: INLINE_MAX_SIZE } : bounds,
197+
INLINE_MAX_SIZE,
198+
)
199+
: null;
200+
const measureBounds = (event: LayoutChangeEvent) => {
201+
const { width, height } = event.nativeEvent.layout;
202+
setBounds({ width, height });
203+
};
190204

191205
const frame = (
192206
<View
@@ -195,7 +209,7 @@ function MediaVideoPlayerContent(props: MediaVideoPlayerProps) {
195209
style={[
196210
props.expanded
197211
? { flex: 1 }
198-
: (fittedFrame ?? { width: "100%", maxWidth: 480, aspectRatio: 16 / 9 }),
212+
: (fittedFrame ?? { width: "100%", maxWidth: INLINE_MAX_SIZE, aspectRatio: 16 / 9 }),
199213
props.borderRadius === undefined ? null : { borderRadius: props.borderRadius },
200214
]}
201215
>
@@ -259,15 +273,16 @@ function MediaVideoPlayerContent(props: MediaVideoPlayerProps) {
259273
)}
260274
</View>
261275
);
262-
if (!props.fitToVideo) return frame;
276+
if (props.fitToVideo) {
277+
return (
278+
<View className="flex-1 items-center justify-center self-stretch" onLayout={measureBounds}>
279+
{frame}
280+
</View>
281+
);
282+
}
283+
if (props.expanded) return frame;
263284
return (
264-
<View
265-
className="flex-1 items-center justify-center self-stretch"
266-
onLayout={(event) => {
267-
const { width, height } = event.nativeEvent.layout;
268-
setBounds({ width, height });
269-
}}
270-
>
285+
<View style={{ width: "100%", maxWidth: INLINE_MAX_SIZE }} onLayout={measureBounds}>
271286
{frame}
272287
</View>
273288
);
Collapse file

‎apps/mobile/src/lib/useMediaVideoPlayback.test.tsx‎

Copy file name to clipboardExpand all lines: apps/mobile/src/lib/useMediaVideoPlayback.test.tsx
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ it.each([
290290
screen.render(false);
291291
expect(mocks.thumbnail).not.toHaveBeenCalled();
292292
await act(async () => screen.render(true));
293-
const requests = kind === "files" ? 2 : 1;
293+
const requests = compact ? 1 : 2;
294294
expect(mocks.thumbnail).toHaveBeenCalledTimes(requests);
295295
const aborted = Promise.all(
296296
mocks.thumbnail.mock.calls.map(([, , signal]) => {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.