fix(mobile): video-loop, breed/birthday edit, avatar zoom, milestone dark mode

- Videos kept looping forever after scrolling off-screen (expo-video has
  no visibility awareness). New useVisiblePostIds hook tracks FlatList
  viewability and pauses VideoPlayer once a post scrolls away, wired
  into both the feed and the pet-profile post list.
- Pet edit screen couldn't change breed or set birthday/adoption date,
  even though the backend (pets.update) already supported all three —
  web already used them. Extracted BreedPicker out of PetCreateForm
  into a shared component, added it plus TT-MM-JJJJ date fields (same
  validation pattern as the health forms) to edit.tsx. Its BreedPicker
  nests a ScrollView, so edit.tsx's outer ScrollView was swapped for a
  FlatList to avoid the same nested-scroll gesture conflict fixed
  earlier for onboarding/pet.tsx.
- Pet profile's own avatar was a plain, non-tappable Image. Tapping it
  now opens the existing /image-viewer (same pinch-to-zoom viewer post
  images already use) when the pet has an avatar set.
- milestones.tsx and milestone-new.tsx still imported the static
  light-only colors/typography tokens instead of useTheme() — switched
  to the established makeStyles(colors) pattern.
This commit is contained in:
admin committed 2026-09-07 21:33:23 +02:00
1 parent f700000e87
commit df4d5ccec2
13 files changed
+248 -94

No files matched your search

+4 -1
View File
@@ -68,6 +68,8 @@ type Props = {
actingPetId: string;
/** Set when this post was mixed into the feed from explore.getTrending rather than being a real followed-pet post — see FeedScreen's interleaving logic. */
isTrending?: boolean;
/** False once scrolled off-screen — pauses video playback instead of looping forever unseen (found.md). Defaults true for single-post screens without viewability tracking. */
isVisible?: boolean;
};
/**
@@ -77,7 +79,7 @@ type Props = {
* playback UI is an explicit fast-follow). Repost ("Paw-Back") posts
* delegate entirely to RepostCard before any of this renders.
*/
export function PostCard({ post, actingPetId, isTrending }: Props) {
export function PostCard({ post, actingPetId, isTrending, isVisible = true }: Props) {
const { t } = useTranslation();
const { width } = useWindowDimensions();
const router = useRouter();
@@ -159,6 +161,7 @@ export function PostCard({ post, actingPetId, isTrending }: Props) {
initialStatus={post.videoPost.status}
initialPlaybackId={post.videoPost.muxPlaybackId}
width={cardWidth}
isVisible={isVisible}
/>
) : (
<PostImages images={post.images} width={cardWidth} onPressImage={openViewer} />
+9 -3
View File
@@ -15,6 +15,8 @@ type Props = {
initialStatus: Status;
initialPlaybackId?: string | null;
width: number;
/** False once the post has scrolled off-screen — pauses playback instead of looping forever unseen (found.md). Defaults true for call sites without viewability tracking (single-post screens). */
isVisible?: boolean;
};
/**
@@ -22,7 +24,7 @@ type Props = {
* expo-video plays natively (AVPlayer/ExoPlayer under the hood) — no
* separate player SDK needed the way web needs @mux/mux-player-react.
*/
export function VideoPlayer({ postId, initialStatus, initialPlaybackId, width }: Props) {
export function VideoPlayer({ postId, initialStatus, initialPlaybackId, width, isVisible = true }: Props) {
const { t } = useTranslation();
const trpc = useTRPC();
const queryClient = useQueryClient();
@@ -63,14 +65,18 @@ export function VideoPlayer({ postId, initialStatus, initialPlaybackId, width }:
);
}
return <ReadyVideo playbackId={playbackId} width={width} />;
return <ReadyVideo playbackId={playbackId} width={width} isVisible={isVisible} />;
}
function ReadyVideo({ playbackId, width }: { playbackId: string; width: number }) {
function ReadyVideo({ playbackId, width, isVisible }: { playbackId: string; width: number; isVisible: boolean }) {
const player = useVideoPlayer(`https://stream.mux.com/${playbackId}.m3u8`, (p) => {
p.loop = true;
});
useEffect(() => {
if (!isVisible) player.pause();
}, [isVisible, player]);
return (
<VideoView
player={player}
@@ -6,6 +6,7 @@ import { useTRPC } from "../../api/trpc";
import { TextField } from "../TextField";
import { Button } from "../Button";
import { OptionPicker, type PickerOption } from "../OptionPicker";
import { BreedPicker } from "../pet/BreedPicker";
import { useTheme } from "../../context/ThemeContext";
import { getTypography, type ColorTokens } from "../../theme/tokens";
@@ -137,41 +138,6 @@ function SpeciesPicker({ selectedName, onSelect }: { selectedName: string | null
);
}
function BreedPicker({
speciesId,
selectedName,
onSelect,
}: {
speciesId: string | null;
selectedName: string | null;
onSelect: (o: PickerOption) => void;
}) {
const { t, i18n } = useTranslation();
const trpc = useTRPC();
const [open, setOpen] = useState(false);
const { data: breeds = [], isLoading } = useQuery({
...trpc.pets.listBreeds.queryOptions({ speciesId: speciesId ?? "", locale: i18n.language }),
enabled: !!speciesId,
});
return (
<OptionPicker
open={open}
onToggle={() => speciesId && setOpen((v) => !v)}
disabled={!speciesId}
selectedName={selectedName}
placeholder={speciesId ? t("petForm.selectBreed") : t("petForm.selectSpeciesFirst")}
isLoading={isLoading}
options={breeds}
emptyLabel={t("petForm.noBreedsFound")}
onSelect={(o) => {
onSelect(o);
setOpen(false);
}}
/>
);
}
function makeStyles(colors: ColorTokens) {
const typography = getTypography(colors);
return StyleSheet.create({
+44
View File
@@ -0,0 +1,44 @@
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { useQuery } from "@tanstack/react-query";
import { useTRPC } from "../../api/trpc";
import { OptionPicker, type PickerOption } from "../OptionPicker";
type Props = {
speciesId: string | null;
selectedName: string | null;
onSelect: (option: PickerOption) => void;
};
/**
* Extracted from onboarding/PetCreateForm.tsx once edit.tsx needed the same
* species-scoped breed dropdown (found.md: breed wasn't editable after pet
* creation) — kept as its own component instead of duplicating the query +
* OptionPicker wiring a second time.
*/
export function BreedPicker({ speciesId, selectedName, onSelect }: Props) {
const { t, i18n } = useTranslation();
const trpc = useTRPC();
const [open, setOpen] = useState(false);
const { data: breeds = [], isLoading } = useQuery({
...trpc.pets.listBreeds.queryOptions({ speciesId: speciesId ?? "", locale: i18n.language }),
enabled: !!speciesId,
});
return (
<OptionPicker
open={open}
onToggle={() => speciesId && setOpen((v) => !v)}
disabled={!speciesId}
selectedName={selectedName}
placeholder={speciesId ? t("petForm.selectBreed") : t("petForm.selectSpeciesFirst")}
isLoading={isLoading}
options={breeds}
emptyLabel={t("petForm.noBreedsFound")}
onSelect={(o) => {
onSelect(o);
setOpen(false);
}}
/>
);
}