@@ -3,13 +3,9 @@ import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
33import * as Dialog from "../../components/ui/Dialog" ;
44import { useIsFocused , useNavigation , type StaticScreenProps } from "@react-navigation/native" ;
55import { createNativeStackNavigator } from "@react-navigation/native-stack" ;
6- import {
7- EnvironmentId ,
8- FILL_PREVIEW_VIEWPORT ,
9- ThreadId ,
10- type PreviewSessionSnapshot ,
11- } from "@t3tools/contracts" ;
12- import { normalizePreviewUrl } from "@t3tools/shared/preview" ;
6+ import { EnvironmentId , ThreadId , type PreviewSessionSnapshot } from "@t3tools/contracts" ;
7+ import { normalizePreviewUrl , previewPdfAssetUrl } from "@t3tools/shared/preview" ;
8+ import * as Option from "effect/Option" ;
139import { useCallback , useEffect , useRef , useState } from "react" ;
1410import { AppState , Platform , TextInput , View } from "react-native" ;
1511import { useSafeAreaInsets } from "react-native-safe-area-context" ;
@@ -18,6 +14,7 @@ import { ControlPill } from "../../components/ui/ControlPill";
1814import { AppBar } from "../../components/ui/AppBar" ;
1915
2016import { useThreadServerBrowserTabs } from "../../state/preview" ;
17+ import { usePreparedConnection } from "../../state/session" ;
2118import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider" ;
2219import { BrowserTabMenu } from "./BrowserTabMenu" ;
2320import { browserTabTitle , browserTabUrl , latestBrowserTab } from "./browserTabs" ;
@@ -79,6 +76,8 @@ function BrowserPreviewScreen({
7976} ) {
8077 const insets = useSafeAreaInsets ( ) ;
8178 const { themeVariables } = useAppearancePreferences ( ) ;
79+ const prepared = usePreparedConnection ( environmentId ) ;
80+ const httpBaseUrl = Option . isSome ( prepared ) ? prepared . value . httpBaseUrl : null ;
8281 const focused = useIsFocused ( ) ;
8382 const [ foreground , setForeground ] = useState ( AppState . currentState !== "background" ) ;
8483 const [ selectedTabId , setSelectedTabId ] = useState ( initialTabId ) ;
@@ -88,6 +87,8 @@ function BrowserPreviewScreen({
8887 const streamRef = useRef < PreviewStreamRef > ( null ) ;
8988 const { tabs, loaded } = useThreadServerBrowserTabs ( { environmentId, threadId, enabled : true } ) ;
9089 const tab = tabs . find ( ( entry ) => entry . tabId === selectedTabId ) ?? latestBrowserTab ( tabs ) ;
90+ const pdfUri =
91+ tab ?. navStatus . _tag === "Success" ? previewPdfAssetUrl ( tab . navStatus . url , httpBaseUrl ) : null ;
9192 const tabId = tab ?. tabId ?? null ;
9293 if ( tabId !== null && tabId !== selectedTabId ) {
9394 setPictureInPicture ( NO_PICTURE_IN_PICTURE ) ;
@@ -121,7 +122,9 @@ function BrowserPreviewScreen({
121122 options = { { headerBackVisible : false } }
122123 actions = {
123124 // Android WebView cannot play video in picture in picture.
124- Platform . OS === "ios" && pictureInPicture . supported
125+ Platform . OS === "ios" &&
126+ pictureInPicture . supported &&
127+ ( pictureInPicture . active || pdfUri === null )
125128 ? [
126129 {
127130 accessibilityLabel : pictureInPicture . active
@@ -181,6 +184,7 @@ function BrowserPreviewScreen({
181184 environmentId = { environmentId }
182185 threadId = { threadId }
183186 tabId = { tab . tabId }
187+ pdfUri = { pdfUri }
184188 ref = { streamRef }
185189 interactive
186190 background = { themeVariables [ "--color-sheet-solid" ] }
0 commit comments