Skip to content

Commit fd64128

Browse files
fix(mobile): iOS web previews keep their flick momentum (#27671)
1 parent 9c96180 commit fd64128

6 files changed

Lines changed: 14 additions & 0 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { View } from "react-native";
33
import { WebView } from "react-native-webview";
44

55
import { FilePreviewLoading, FilePreviewNotice } from "../features/files/FilePreviewFeedback";
6+
import { webViewDecelerationRate } from "../lib/webViewDecelerationRate";
67

78
export function PdfPreview(props: { readonly uri: string }) {
89
const [error, setError] = useState<string | null>(null);
@@ -13,6 +14,7 @@ export function PdfPreview(props: { readonly uri: string }) {
1314
source={{ uri: props.uri }}
1415
originWhitelist={["*"]}
1516
automaticallyAdjustContentInsets={false}
17+
decelerationRate={webViewDecelerationRate}
1618
contentInsetAdjustmentBehavior="never"
1719
startInLoadingState
1820
onError={(event) =>

‎apps/mobile/src/features/files/WorkspaceFileWebPreview.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { PdfPreview } from "../../components/PdfPreview";
1111
import { ControlPill } from "../../components/ui/ControlPill";
1212
import { useHardwareBack } from "../../lib/backHandler";
1313
import { isPdfPreviewUri } from "../../lib/pdfPreview";
14+
import { webViewDecelerationRate } from "../../lib/webViewDecelerationRate";
1415
import { useContentTopInset } from "../../components/ui/useBarInset";
1516

1617
export function WorkspaceFileWebPreview(props: { readonly uri: string | null }) {
@@ -58,6 +59,7 @@ function DocumentWebPreview(props: { readonly uri: string }) {
5859
source={{ uri: props.uri }}
5960
// react-native-webview defaults to "never", which starts the page under the header.
6061
contentInsetAdjustmentBehavior="automatic"
62+
decelerationRate={webViewDecelerationRate}
6163
originWhitelist={["*"]}
6264
allowsBackForwardNavigationGestures
6365
allowsFullscreenVideo

‎apps/mobile/src/features/settings/components/SettingsLegalDocumentRouteScreen.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { AppText as Text } from "../../../components/ui/AppText";
1010
import { LoadingStrip } from "../../../components/ui/LoadingStrip";
1111
import { SymbolView } from "../../../components/ui/AppSymbol";
1212
import { isLegalDocumentUrl, LEGAL_URL } from "../lib/legal-document-url";
13+
import { webViewDecelerationRate } from "../../../lib/webViewDecelerationRate";
1314

1415
interface SettingsLegalDocumentRouteScreenProps {
1516
readonly documentName: string;
@@ -100,6 +101,7 @@ export function SettingsLegalDocumentRouteScreen({
100101
cacheEnabled={false}
101102
cacheMode="LOAD_NO_CACHE"
102103
allowsBackForwardNavigationGestures
104+
decelerationRate={webViewDecelerationRate}
103105
domStorageEnabled={false}
104106
incognito
105107
javaScriptEnabled={false}

‎apps/mobile/src/features/threads/HtmlRenderWebView.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { mobileHtmlRenderTheme } from "../../lib/htmlRenderTheme";
1919
import { tryOpenExternalUrl } from "../../lib/openExternalUrl";
2020
import { useAssetUrlState, useRefreshAssetUrl } from "../../state/assets";
2121
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
22+
import { webViewDecelerationRate } from "../../lib/webViewDecelerationRate";
2223

2324
const ROW_BOTTOM_MARGIN = 8;
2425
const FULL_SCREEN_GUTTER = 16;
@@ -130,6 +131,7 @@ export function HtmlRenderWebView(props: {
130131
showsVerticalScrollIndicator={!props.nested}
131132
showsHorizontalScrollIndicator={!props.nested}
132133
scrollEnabled={scrollable}
134+
decelerationRate={webViewDecelerationRate}
133135
// Android's patched WebView always keeps horizontal drags. Only pages
134136
// with vertical overflow hold vertical drags until they reach an edge.
135137
nestedScrollEnabled={props.nested && overflow.y}

‎apps/mobile/src/features/threads/McpAppWebView.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { shareGeneratedAttachment } from "../../lib/attachmentDownload";
3434
import { mobileHtmlRenderTheme } from "../../lib/htmlRenderTheme";
3535
import { tryOpenExternalUrl } from "../../lib/openExternalUrl";
3636
import { uuidv4 } from "../../lib/uuid";
37+
import { webViewDecelerationRate } from "../../lib/webViewDecelerationRate";
3738
import { useAssetUrlState } from "../../state/assets";
3839
import { appAtomRegistry } from "../../state/atom-registry";
3940
import { useThreadShell } from "../../state/entities";
@@ -536,6 +537,7 @@ export function ThreadMcpApp(props: {
536537
accessibilityLabel={`${app.server} app`}
537538
style={{ flex: 1, backgroundColor: "transparent" }}
538539
nestedScrollEnabled
540+
decelerationRate={webViewDecelerationRate}
539541
originWhitelist={["*"]}
540542
// Android misreports nested frames as top-level; rely on iframe sandboxing there and gate navigation elsewhere.
541543
onShouldStartLoadWithRequest={(request) =>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { Platform } from "react-native";
2+
3+
// react-native-webview on Fabric leaves an unset rate at 0, which UIKit clamps to "fast"; Android crashes on the string.
4+
export const webViewDecelerationRate = Platform.OS === "ios" ? "normal" : undefined;

0 commit comments

Comments
 (0)