Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(mobile): HTML pages in a thread no longer trap scrolling on Android #17211

MergedSunkenInTime(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/17211/headmerged by juliusmarminge View on GitHub

Showing 4 changed files with 80 additions and 13 deletions.

x
0 of 4 viewed, 4 left
22 additions and 13 deletionsapps/mobile/src/features/threads/HtmlRenderWebView.tsxModified
View file
@@ -51,20 +51,26 @@
​
const OVERFLOW_MESSAGE_TYPE = "t3-html-render-overflow";
​
-// Reports whether the page overflows its frame, so a feed row only takes scroll
-// gestures from a page that can use them.
-const OVERFLOW_SCRIPT = `(function(){var last;function report(){var d=document.documentElement,b=document.body;var o=Math.max(d.scrollHeight,b?b.scrollHeight:0)>window.innerHeight+1||Math.max(d.scrollWidth,b?b.scrollWidth:0)>window.innerWidth+1;if(o===last)return;last=o;window.ReactNativeWebView.postMessage(JSON.stringify({type:${JSON.stringify(OVERFLOW_MESSAGE_TYPE)},overflow:o}));}report();if(window.ResizeObserver){var r=new ResizeObserver(report);r.observe(document.documentElement);if(document.body)r.observe(document.body);}window.addEventListener("resize",report);})();true;`;
+// Reports which ways the page overflows its frame, so a feed row only takes
+// scroll gestures from a page that can use them.
+const OVERFLOW_SCRIPT = `(function(){var last;function report(){var d=document.documentElement,b=document.body;var x=Math.max(d.scrollWidth,b?b.scrollWidth:0)>window.innerWidth+1,y=Math.max(d.scrollHeight,b?b.scrollHeight:0)>window.innerHeight+1,o=x+","+y;if(o===last)return;last=o;window.ReactNativeWebView.postMessage(JSON.stringify({type:${JSON.stringify(OVERFLOW_MESSAGE_TYPE)},x:x,y:y}));}report();if(window.ResizeObserver){var r=new ResizeObserver(report);r.observe(document.documentElement);if(document.body)r.observe(document.body);}window.addEventListener("resize",report);})();true;`;
​
-function readOverflowMessage(data: string) {
+type Overflow = { readonly x: boolean; readonly y: boolean };
+​
+const NO_OVERFLOW: Overflow = { x: false, y: false };
+​
+function readOverflowMessage(data: string): Overflow | null {
try {
const message: unknown = JSON.parse(data);
return typeof message === "object" &&
message !== null &&
"type" in message &&
message.type === OVERFLOW_MESSAGE_TYPE &&
- "overflow" in message &&
- typeof message.overflow === "boolean"
- ? message.overflow
+ "x" in message &&
+ typeof message.x === "boolean" &&
+ "y" in message &&
+ typeof message.y === "boolean"