@@ -1629,6 +1629,327 @@ describe('useSheetGestures', () => {
16291629 }
16301630 } ) ;
16311631
1632+ describe ( 'content that fits' , ( ) => {
1633+ // Nothing scrolls, so a touch arms both edges at touch-down.
1634+ function fittingSheet ( ) {
1635+ const { hook} = setup ( {
1636+ snapHeights : ( ) => [ 200 ] ,
1637+ offscreenBlockEndInset : TOUCH_RESERVE ,
1638+ } ) ;
1639+ const el = makeScroller ( {
1640+ scrollTop : 0 ,
1641+ clientHeight : 200 ,
1642+ scrollHeight : 200 ,
1643+ } ) ;
1644+ act ( ( ) => hook . result . current . sheetRef ( el ) ) ;
1645+ act ( ( ) => hook . result . current . bodyProps . ref ( el ) ) ;
1646+ return { hook, el} ;
1647+ }
1648+
1649+ it . each ( [
1650+ { first : 1 , isFirstCancelled : false } ,
1651+ { first : 4 , isFirstCancelled : false } ,
1652+ { first : 5 , isFirstCancelled : true } ,
1653+ { first : 8 , isFirstCancelled : true } ,
1654+ ] ) (
1655+ 'promotes a pull-down whose first move is $first px, under the drag slop' ,
1656+ ( { first, isFirstCancelled} ) => {
1657+ const { hook, el} = fittingSheet ( ) ;
1658+ let start ! : Event ;
1659+ let pull ! : Event ;
1660+ act ( ( ) => {
1661+ touch ( el , 'touchstart' , 100 ) ;
1662+ start = touch ( el , 'touchmove' , 100 + first ) ;
1663+ } ) ;
1664+ // A tap's wobble keeps its click. Past the wobble, the sheet cancels
1665+ // the pan.
1666+ expect ( start . defaultPrevented ) . toBe ( isFirstCancelled ) ;
1667+ expect ( hook . result . current . isDragging ) . toBe ( false ) ;
1668+ act ( ( ) => {
1669+ pull = touch ( el , 'touchmove' , 140 ) ;
1670+ } ) ;
1671+ expect ( pull . defaultPrevented ) . toBe ( true ) ;
1672+ expect ( hook . result . current . isDragging ) . toBe ( true ) ;
1673+ // The drag starts from the touch-down point, so the sheet loses no
1674+ // travel.
1675+ expect ( liveOffset ( hook ) ) . toBe ( 40 ) ;
1676+ } ,
1677+ ) ;
1678+
1679+ it ( 'promotes a pull-down that creeps a pixel at a time through the slop' , ( ) => {
1680+ const { hook, el} = fittingSheet ( ) ;
1681+ const moves : Event [ ] = [ ] ;
1682+ act ( ( ) => {
1683+ touch ( el , 'touchstart' , 100 ) ;
1684+ for ( let y = 101 ; y <= 108 ; y += 1 ) {
1685+ moves . push ( touch ( el , 'touchmove' , y ) ) ;
1686+ }
1687+ } ) ;
1688+ expect ( hook . result . current . isDragging ) . toBe ( false ) ;
1689+ expect ( moves . map ( move => move . defaultPrevented ) ) . toEqual ( [
1690+ false ,
1691+ false ,
1692+ false ,
1693+ false ,
1694+ true ,
1695+ true ,
1696+ true ,
1697+ true ,
1698+ ] ) ;
1699+ act ( ( ) => {
1700+ touch ( el , 'touchmove' , 109 ) ;
1701+ } ) ;
1702+ expect ( hook . result . current . isDragging ) . toBe ( true ) ;
1703+ expect ( liveOffset ( hook ) ) . toBe ( 9 ) ;
1704+ } ) ;
1705+
1706+ it ( 'promotes a pull-down after the finger drifts up as it lands' , ( ) => {
1707+ const { hook, el} = fittingSheet ( ) ;
1708+ let drift ! : Event ;
1709+ let pull ! : Event ;
1710+ act ( ( ) => {
1711+ touch ( el , 'touchstart' , 100 ) ;
1712+ drift = touch ( el , 'touchmove' , 99 ) ;
1713+ } ) ;
1714+ expect ( drift . defaultPrevented ) . toBe ( false ) ;
1715+ expect ( hook . result . current . isDragging ) . toBe ( false ) ;
1716+ act ( ( ) => {
1717+ pull = touch ( el , 'touchmove' , 140 ) ;
1718+ } ) ;
1719+ expect ( pull . defaultPrevented ) . toBe ( true ) ;
1720+ expect ( hook . result . current . isDragging ) . toBe ( true ) ;
1721+ expect ( liveOffset ( hook ) ) . toBe ( 40 ) ;
1722+ } ) ;
1723+
1724+ it ( 'claims a pull-up after the finger drifts down as it lands' , ( ) => {
1725+ const { hook, el} = fittingSheet ( ) ;
1726+ let pull ! : Event ;
1727+ act ( ( ) => {
1728+ touch ( el , 'touchstart' , 300 ) ;
1729+ touch ( el , 'touchmove' , 303 ) ;
1730+ pull = touch ( el , 'touchmove' , 250 ) ;
1731+ } ) ;
1732+ // The sheet takes the pull from the touch-down, and cancels its pan.
1733+ expect ( pull . defaultPrevented ) . toBe ( true ) ;
1734+ expect ( hook . result . current . isDragging ) . toBe ( true ) ;
1735+ expect ( - liveOffset ( hook ) ) . toBeCloseTo (
1736+ rubberBand ( 50 , SHEET_HEIGHT - TOUCH_RESERVE ) ,
1737+ 6 ,
1738+ ) ;
1739+ } ) ;
1740+ } ) ;
1741+
1742+ it ( 'gives a list at its top to its scroll on an upward first move, and takes no later pull-down' , ( ) => {
1743+ const { hook} = setup ( { snapHeights : ( ) => [ 200 ] } ) ;
1744+ const el = makeScroller ( {
1745+ scrollTop : 0 ,
1746+ clientHeight : 200 ,
1747+ scrollHeight : 800 ,
1748+ } ) ;
1749+ act ( ( ) => hook . result . current . sheetRef ( el ) ) ;
1750+ act ( ( ) => hook . result . current . bodyProps . ref ( el ) ) ;
1751+ let back ! : Event ;
1752+ act ( ( ) => {
1753+ touch ( el , 'touchstart' , 100 ) ;
1754+ // A kept move of 5 px commits iOS Safari to the list's pan.
1755+ touch ( el , 'touchmove' , 95 ) ;
1756+ back = touch ( el , 'touchmove' , 150 ) ;
1757+ } ) ;
1758+ // The scroll owns this touch, so the drag does not change hands.
1759+ expect ( back . defaultPrevented ) . toBe ( false ) ;
1760+ expect ( hook . result . current . isDragging ) . toBe ( false ) ;
1761+ } ) ;
1762+
1763+ it ( 'gives a list at its end to its scroll on a downward first move, and claims no later pull-up' , ( ) => {
1764+ const { hook} = setup ( { snapHeights : ( ) => [ 200 ] } ) ;
1765+ const el = makeScroller ( {
1766+ scrollTop : 600 ,
1767+ clientHeight : 200 ,
1768+ scrollHeight : 800 ,
1769+ } ) ;
1770+ act ( ( ) => hook . result . current . sheetRef ( el ) ) ;
1771+ act ( ( ) => hook . result . current . bodyProps . ref ( el ) ) ;
1772+ // Settle at the lower detent, where the sheet claims a pull up at the
1773+ // end.
1774+ down ( hook , 0 , 0 , el ) ;
1775+ move ( hook , 180 , 700 , el ) ;
1776+ up ( hook , 180 , 1100 , el ) ;
1777+ expect ( hook . result . current . settledOffset ) . toBe ( 200 ) ;
1778+ let back ! : Event ;
1779+ act ( ( ) => {
1780+ touch ( el , 'touchstart' , 300 ) ;
1781+ touch ( el , 'touchmove' , 305 ) ;
1782+ back = touch ( el , 'touchmove' , 250 ) ;
1783+ } ) ;
1784+ expect ( back . defaultPrevented ) . toBe ( false ) ;
1785+ } ) ;
1786+
1787+ it ( 'promotes a pull-down at the top of a list after the finger wobbles up less than a tap does' , ( ) => {
1788+ const { hook} = setup ( { snapHeights : ( ) => [ 200 ] } ) ;
1789+ const el = makeScroller ( {
1790+ scrollTop : 0 ,
1791+ clientHeight : 200 ,
1792+ scrollHeight : 800 ,
1793+ } ) ;
1794+ act ( ( ) => hook . result . current . sheetRef ( el ) ) ;
1795+ act ( ( ) => hook . result . current . bodyProps . ref ( el ) ) ;
1796+ let wobble ! : Event ;
1797+ let pull ! : Event ;
1798+ act ( ( ) => {
1799+ touch ( el , 'touchstart' , 100 ) ;
1800+ // A kept move of 4 px commits no native pan, so it decides nothing.
1801+ wobble = touch ( el , 'touchmove' , 96 ) ;
1802+ pull = touch ( el , 'touchmove' , 106 ) ;
1803+ } ) ;
1804+ expect ( wobble . defaultPrevented ) . toBe ( false ) ;
1805+ expect ( pull . defaultPrevented ) . toBe ( true ) ;
1806+ expect ( hook . result . current . isDragging ) . toBe ( false ) ;
1807+ act ( ( ) => {
1808+ touch ( el , 'touchmove' , 140 ) ;
1809+ } ) ;
1810+ expect ( hook . result . current . isDragging ) . toBe ( true ) ;
1811+ expect ( liveOffset ( hook ) ) . toBe ( 40 ) ;
1812+ } ) ;
1813+
1814+ it ( 'claims a pull-up at the end of a list after the finger wobbles down less than a tap does' , ( ) => {
1815+ const { hook} = setup ( { snapHeights : ( ) => [ 200 ] } ) ;
1816+ const el = makeScroller ( {
1817+ scrollTop : 600 ,
1818+ clientHeight : 200 ,
1819+ scrollHeight : 800 ,
1820+ } ) ;
1821+ act ( ( ) => hook . result . current . sheetRef ( el ) ) ;
1822+ act ( ( ) => hook . result . current . bodyProps . ref ( el ) ) ;
1823+ // Settle at the lower detent, where the sheet claims a pull up at the
1824+ // end.
1825+ down ( hook , 0 , 0 , el ) ;
1826+ move ( hook , 180 , 700 , el ) ;
1827+ up ( hook , 180 , 1100 , el ) ;
1828+ expect ( hook . result . current . settledOffset ) . toBe ( 200 ) ;
1829+ let wobble ! : Event ;
1830+ let pull ! : Event ;
1831+ act ( ( ) => {
1832+ touch ( el , 'touchstart' , 300 ) ;
1833+ wobble = touch ( el , 'touchmove' , 304 ) ;
1834+ pull = touch ( el , 'touchmove' , 250 ) ;
1835+ } ) ;
1836+ expect ( wobble . defaultPrevented ) . toBe ( false ) ;
1837+ // The sheet takes the pull from the touch-down, and cancels its pan.
1838+ expect ( pull . defaultPrevented ) . toBe ( true ) ;
1839+ expect ( hook . result . current . isDragging ) . toBe ( true ) ;
1840+ expect ( liveOffset ( hook ) ) . toBe ( 150 ) ;
1841+ } ) ;
1842+
1843+ it . each ( [
1844+ { content : 'content that fits' , scrollHeight : 200 } ,
1845+ { content : 'a list at its top' , scrollHeight : 800 } ,
1846+ ] ) (
1847+ 'leaves a sideways swipe on $content to the row for the whole touch, also when it drifts down, turns into a pull, or comes back up' ,
1848+ ( { scrollHeight} ) => {
1849+ const { hook} = setup ( { snapHeights : ( ) => [ 200 ] } ) ;
1850+ const el = makeScroller ( {
1851+ scrollTop : 0 ,
1852+ clientHeight : 200 ,
1853+ scrollHeight,
1854+ } ) ;
1855+ act ( ( ) => hook . result . current . sheetRef ( el ) ) ;
1856+ act ( ( ) => hook . result . current . bodyProps . ref ( el ) ) ;
1857+ const moves : Event [ ] = [ ] ;
1858+ act ( ( ) => {
1859+ touch ( el , 'touchstart' , 100 , 1 , 'direct' , undefined , 0 ) ;
1860+ // A swipe along a row of chips whose finger drifts 40 px down.
1861+ moves . push ( touch ( el , 'touchmove' , 103 , 1 , 'direct' , undefined , 20 ) ) ;
1862+ moves . push ( touch ( el , 'touchmove' , 109 , 1 , 'direct' , undefined , 60 ) ) ;
1863+ moves . push ( touch ( el , 'touchmove' , 140 , 1 , 'direct' , undefined , 150 ) ) ;
1864+ // The finger then pulls down, farther than it went sideways.
1865+ moves . push ( touch ( el , 'touchmove' , 300 , 1 , 'direct' , undefined , 152 ) ) ;
1866+ // It then comes back up, past where it began.
1867+ moves . push ( touch ( el , 'touchmove' , 60 , 1 , 'direct' , undefined , 154 ) ) ;
1868+ } ) ;
1869+ expect ( moves . map ( move => move . defaultPrevented ) ) . toEqual ( [
1870+ false ,
1871+ false ,
1872+ false ,
1873+ false ,
1874+ false ,
1875+ ] ) ;
1876+ expect ( hook . result . current . isDragging ) . toBe ( false ) ;
1877+ } ,
1878+ ) ;
1879+
1880+ it ( 'takes no pull whose first move past the slop is more sideways than down, also when the pull then turns down' , ( ) => {
1881+ const { hook} = setup ( { snapHeights : ( ) => [ 200 ] } ) ;
1882+ const el = makeScroller ( {
1883+ scrollTop : 0 ,
1884+ clientHeight : 200 ,
1885+ scrollHeight : 800 ,
1886+ } ) ;
1887+ act ( ( ) => hook . result . current . sheetRef ( el ) ) ;
1888+ act ( ( ) => hook . result . current . bodyProps . ref ( el ) ) ;
1889+ let diagonal ! : Event ;
1890+ let down ! : Event ;
1891+ act ( ( ) => {
1892+ touch ( el , 'touchstart' , 100 , 1 , 'direct' , undefined , 0 ) ;
1893+ diagonal = touch ( el , 'touchmove' , 120 , 1 , 'direct' , undefined , 30 ) ;
1894+ down = touch ( el , 'touchmove' , 250 , 1 , 'direct' , undefined , 34 ) ;
1895+ } ) ;
1896+ expect ( diagonal . defaultPrevented ) . toBe ( false ) ;
1897+ expect ( down . defaultPrevented ) . toBe ( false ) ;
1898+ // A drag that began here would move the sheet 150 px at once.
1899+ expect ( hook . result . current . isDragging ) . toBe ( false ) ;
1900+ } ) ;
1901+
1902+ it ( 'decides at the drag slop, so a pull on content that fits whose first move is diagonal starts the drag' , ( ) => {
1903+ const { hook} = setup ( { snapHeights : ( ) => [ 200 ] } ) ;
1904+ const el = makeScroller ( {
1905+ scrollTop : 0 ,
1906+ clientHeight : 200 ,
1907+ scrollHeight : 200 ,
1908+ } ) ;
1909+ act ( ( ) => hook . result . current . sheetRef ( el ) ) ;
1910+ act ( ( ) => hook . result . current . bodyProps . ref ( el ) ) ;
1911+ let first ! : Event ;
1912+ act ( ( ) => {
1913+ touch ( el , 'touchstart' , 100 , 1 , 'direct' , undefined , 0 ) ;
1914+ // 6 px sideways and 5 px down: under the slop, so nothing is decided.
1915+ first = touch ( el , 'touchmove' , 105 , 1 , 'direct' , undefined , 6 ) ;
1916+ } ) ;
1917+ expect ( first . defaultPrevented ) . toBe ( false ) ;
1918+ expect ( hook . result . current . isDragging ) . toBe ( false ) ;
1919+ act ( ( ) => {
1920+ touch ( el , 'touchmove' , 112 , 1 , 'direct' , undefined , 7 ) ;
1921+ } ) ;
1922+ expect ( hook . result . current . isDragging ) . toBe ( true ) ;
1923+ // A sideways drift after the drag begins does not end it.
1924+ act ( ( ) => {
1925+ touch ( el , 'touchmove' , 140 , 1 , 'direct' , undefined , 90 ) ;
1926+ } ) ;
1927+ expect ( hook . result . current . isDragging ) . toBe ( true ) ;
1928+ expect ( liveOffset ( hook ) ) . toBe ( 40 ) ;
1929+ } ) ;
1930+
1931+ it ( 'gives the touch to the content when a list is off its top at the drag slop, and takes no later pull-down' , ( ) => {
1932+ const { hook} = setup ( { snapHeights : ( ) => [ 200 ] } ) ;
1933+ const el = makeScroller ( {
1934+ scrollTop : 0 ,
1935+ clientHeight : 200 ,
1936+ scrollHeight : 800 ,
1937+ } ) ;
1938+ act ( ( ) => hook . result . current . sheetRef ( el ) ) ;
1939+ act ( ( ) => hook . result . current . bodyProps . ref ( el ) ) ;
1940+ let back ! : Event ;
1941+ act ( ( ) => {
1942+ touch ( el , 'touchstart' , 100 ) ;
1943+ // The list scrolls under the finger before the pull passes the slop.
1944+ el . scrollTop = 12 ;
1945+ touch ( el , 'touchmove' , 110 ) ;
1946+ el . scrollTop = 0 ;
1947+ back = touch ( el , 'touchmove' , 150 ) ;
1948+ } ) ;
1949+ expect ( back . defaultPrevented ) . toBe ( false ) ;
1950+ expect ( hook . result . current . isDragging ) . toBe ( false ) ;
1951+ } ) ;
1952+
16321953 it ( "keeps a stylus pulling up on the body at the tallest detent on a pen's stretch, capped at 48 px" , ( ) => {
16331954 const { hook} = setup ( {
16341955 snapHeights : ( ) => [ 200 ] ,
0 commit comments