@@ -25,6 +25,19 @@ function isScrollableY(element: HTMLElement) {
2525 return element . scrollHeight > element . clientHeight + BOUNDARY_EPSILON_PX ;
2626}
2727
28+ function isScrollableX ( element : HTMLElement ) {
29+ if ( isDocumentElement ( element ) ) {
30+ return false ;
31+ }
32+
33+ const style = window . getComputedStyle ( element ) ;
34+ if ( ! SCROLLABLE_OVERFLOW_VALUES . has ( style . overflowX ) ) {
35+ return false ;
36+ }
37+
38+ return element . scrollWidth > element . clientWidth + BOUNDARY_EPSILON_PX ;
39+ }
40+
2841function canScrollY ( element : HTMLElement , deltaY : number ) {
2942 if ( deltaY < 0 ) {
3043 return element . scrollTop > BOUNDARY_EPSILON_PX ;
@@ -34,6 +47,15 @@ function canScrollY(element: HTMLElement, deltaY: number) {
3447 return element . scrollTop < maxScrollTop - BOUNDARY_EPSILON_PX ;
3548}
3649
50+ function canScrollX ( element : HTMLElement , deltaX : number ) {
51+ if ( deltaX < 0 ) {
52+ return element . scrollLeft > BOUNDARY_EPSILON_PX ;
53+ }
54+
55+ const maxScrollLeft = element . scrollWidth - element . clientWidth ;
56+ return element . scrollLeft < maxScrollLeft - BOUNDARY_EPSILON_PX ;
57+ }
58+
3759function isConversationScroller ( element : HTMLElement ) {
3860 return Boolean ( element . closest ( CONVERSATION_SCROLL_SELECTOR ) ) ;
3961}
@@ -44,39 +66,63 @@ function isConversationScroller(element: HTMLElement) {
4466 * Buzz is laid out as fixed-height nested panes. On macOS, a wheel/trackpad
4567 * gesture that starts over a non-scrollable pane (or over a scrollable pane at
4668 * its boundary) can still be handed to the WKWebView viewport, which rubber-
47- * bands the entire app and reveals a blank strip above/below the UI. CSS
69+ * bands the entire app and reveals a blank strip beside the UI. CSS
4870 * `overscroll-behavior` is not enough for all of the empty/header/footer hit
4971 * targets in the webview, so this capture listener consumes only gestures that
50- * otherwise have nowhere app-local to scroll.
72+ * otherwise have nowhere app-local to scroll. Both axes are locked: vertical
73+ * and horizontal pans are each checked against containers that can actually
74+ * move in that direction.
5175 *
5276 * Real scrolling is left alone: if any scroll container under the pointer can
53- * move in the wheel direction, the browser handles it normally. At boundaries,
54- * only containers marked with `data-buzz-conversation-scroll` are allowed to
55- * receive the gesture so their own local elastic affordance can remain; every
56- * other boundary is locked and cannot chain to the viewport.
77+ * move in the wheel direction, the browser handles it normally. At vertical
78+ * boundaries, only containers marked with `data-buzz-conversation-scroll` are
79+ * allowed to receive the gesture so their own local elastic affordance can
80+ * remain; every other boundary — including all horizontal ones — is locked and
81+ * cannot chain to the viewport.
5782 */
5883export function useWebviewScrollBoundaryLock ( ) {
5984 React . useEffect ( ( ) => {
6085 function handleWheel ( event : WheelEvent ) {
61- if ( event . defaultPrevented || event . deltaY === 0 || event . ctrlKey ) {
86+ if ( event . defaultPrevented || event . ctrlKey ) {
87+ return ;
88+ }
89+
90+ const { deltaX, deltaY } = event ;
91+ if ( deltaX === 0 && deltaY === 0 ) {
6292 return ;
6393 }
6494
6595 const path = event . composedPath ( ) ;
6696 let firstScrollable : HTMLElement | null = null ;
6797
6898 for ( const target of path ) {
69- if ( ! isHTMLElement ( target ) || ! isScrollableY ( target ) ) {
99+ if ( ! isHTMLElement ( target ) ) {
100+ continue ;
101+ }
102+
103+ const scrollableY = deltaY !== 0 && isScrollableY ( target ) ;
104+ const scrollableX = deltaX !== 0 && isScrollableX ( target ) ;
105+ if ( ! scrollableY && ! scrollableX ) {
70106 continue ;
71107 }
72108
73109 firstScrollable ??= target ;
74- if ( canScrollY ( target , event . deltaY ) ) {
110+ if (
111+ ( scrollableY && canScrollY ( target , deltaY ) ) ||
112+ ( scrollableX && canScrollX ( target , deltaX ) )
113+ ) {
75114 return ;
76115 }
77116 }
78117
79- if ( firstScrollable && isConversationScroller ( firstScrollable ) ) {
118+ // Only the vertical elastic affordance of conversation scrollers is
119+ // preserved; a predominantly horizontal gesture must never pan the
120+ // webview, even over a conversation pane.
121+ if (
122+ firstScrollable &&
123+ isConversationScroller ( firstScrollable ) &&
124+ Math . abs ( deltaY ) >= Math . abs ( deltaX )
125+ ) {
80126 return ;
81127 }
82128
0 commit comments