Skip to content

Commit b44557c

Browse files
fix(mobile): iOS web previews keep their flick momentum
react-native-webview 14 under Fabric never initializes the iOS deceleration rate, so an unset prop reaches UIKit as 0 and is clamped to the fast rate. Scrollable WebViews pass "normal" explicitly on iOS. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 6575ce3 commit b44557c

5 files changed

Lines changed: 12 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
@@ -12,6 +12,7 @@ import { ControlPill } from "../../components/ui/ControlPill";
1212
import { useHardwareBack } from "../../lib/backHandler";
1313
import { isPdfPreviewUri } from "../../lib/pdfPreview";
1414
import { useNativeColumnLayoutMetrics } from "../../native/native-layout-metrics";
15+
import { webViewDecelerationRate } from "../../lib/webViewDecelerationRate";
1516

1617
export function WorkspaceFileWebPreview(props: { readonly uri: string | null }) {
1718
if (props.uri === null) {
@@ -61,6 +62,7 @@ function DocumentWebPreview(props: { readonly uri: string }) {
6162
source={{ uri: props.uri }}
6263
// react-native-webview defaults to "never", which starts the page under the header.
6364
contentInsetAdjustmentBehavior="automatic"
65+
decelerationRate={webViewDecelerationRate}
6466
originWhitelist={["*"]}
6567
allowsBackForwardNavigationGestures
6668
allowsFullscreenVideo

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { LoadingStrip } from "../../../components/ui/LoadingStrip";
1212
import { SymbolView } from "../../../components/ui/AppSymbol";
1313
import { NativeStackScreenOptions } from "../../../native/StackHeader";
1414
import { isLegalDocumentUrl, LEGAL_URL } from "../lib/legal-document-url";
15+
import { webViewDecelerationRate } from "../../../lib/webViewDecelerationRate";
1516

1617
export function SettingsLegalDocumentCloseHeaderButton() {
1718
const navigation = useNavigation();
@@ -121,6 +122,7 @@ export function SettingsLegalDocumentRouteScreen({
121122
cacheEnabled={false}
122123
cacheMode="LOAD_NO_CACHE"
123124
allowsBackForwardNavigationGestures
125+
decelerationRate={webViewDecelerationRate}
124126
domStorageEnabled={false}
125127
incognito
126128
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
// Patched Android WebView hands vertical drags to the feed at its edges; horizontal-only overflow leaves them to the feed.
134136
nestedScrollEnabled={props.nested && overflow.y}
135137
overScrollMode={props.nested ? "never" : "always"}
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)