1d5113603SCedric van Puttenimport { css } from '@emotion/react'; 2d5113603SCedric van Puttenimport { theme } from '@expo/styleguide'; 34d749394SCedric van Puttenimport React, { forwardRef, HTMLAttributes, PropsWithChildren } from 'react'; 4d5113603SCedric van Putten 54d749394SCedric van Puttentype LayoutScrollProps = PropsWithChildren< 64d749394SCedric van Putten HTMLAttributes<HTMLDivElement> & { 734b42efdSBartosz Kaszubowski /** 8640b8015Sapeltop * If the scroll container should smoothly scroll when scrolled programmatically. 934b42efdSBartosz Kaszubowski */ 104d749394SCedric van Putten smoothScroll?: boolean; 1134b42efdSBartosz Kaszubowski /** 1234b42efdSBartosz Kaszubowski * If the overscoll effect should be disabled. 1334b42efdSBartosz Kaszubowski */ 1434b42efdSBartosz Kaszubowski disableOverscroll?: boolean; 154d749394SCedric van Putten } 164d749394SCedric van Putten>; 17d5113603SCedric van Putten 184d749394SCedric van Puttenexport const LayoutScroll = forwardRef<HTMLDivElement, LayoutScrollProps>( 1934b42efdSBartosz Kaszubowski ({ smoothScroll = true, disableOverscroll = true, children, ...rest }, ref) => ( 2034b42efdSBartosz Kaszubowski <div 2134b42efdSBartosz Kaszubowski css={[ 2234b42efdSBartosz Kaszubowski scrollStyle, 2334b42efdSBartosz Kaszubowski smoothScroll && smoothScrollBehavior, 2434b42efdSBartosz Kaszubowski disableOverscroll && disableOverscrollBehavior, 2534b42efdSBartosz Kaszubowski ]} 2634b42efdSBartosz Kaszubowski {...rest} 2734b42efdSBartosz Kaszubowski ref={ref}> 28d5113603SCedric van Putten {children} 29d5113603SCedric van Putten </div> 304d749394SCedric van Putten ) 31d5113603SCedric van Putten); 32d5113603SCedric van Putten 33d5113603SCedric van Puttenconst scrollStyle = css({ 3434b42efdSBartosz Kaszubowski flex: 1, 35d5113603SCedric van Putten overflowY: 'auto', 3634b42efdSBartosz Kaszubowski overflowX: 'hidden', 3734b42efdSBartosz Kaszubowski /** 3834b42efdSBartosz Kaszubowski * Scrollbar 3934b42efdSBartosz Kaszubowski */ 40d5113603SCedric van Putten '::-webkit-scrollbar': { 41d5113603SCedric van Putten width: '6px', 42d5113603SCedric van Putten }, 4334b42efdSBartosz Kaszubowski // Track 44d5113603SCedric van Putten '::-webkit-scrollbar-track': { 45d5113603SCedric van Putten backgroundColor: 'transparent', 46d5113603SCedric van Putten cursor: 'pointer', 47d5113603SCedric van Putten }, 4834b42efdSBartosz Kaszubowski // Handle 49d5113603SCedric van Putten '::-webkit-scrollbar-thumb': { 50*be43ea08SBartosz Kaszubowski backgroundColor: theme.palette.gray5, 51d5113603SCedric van Putten borderRadius: '10px', 52d5113603SCedric van Putten }, 5334b42efdSBartosz Kaszubowski // Handle on hover 54d5113603SCedric van Putten '::-webkit-scrollbar-thumb:hover': { 55*be43ea08SBartosz Kaszubowski backgroundColor: theme.palette.gray6, 56d5113603SCedric van Putten }, 57d5113603SCedric van Putten}); 584d749394SCedric van Putten 594d749394SCedric van Puttenconst smoothScrollBehavior = css({ 604d749394SCedric van Putten scrollBehavior: 'smooth', 614d749394SCedric van Putten}); 6234b42efdSBartosz Kaszubowski 6334b42efdSBartosz Kaszubowskiconst disableOverscrollBehavior = css({ 6434b42efdSBartosz Kaszubowski overscrollBehavior: 'contain', 6534b42efdSBartosz Kaszubowski}); 66