11import * as React from 'react'
2+ import { Icon } from '@alifd/next'
23
34const styles = {
45 scrollIndicator : {
56 position : 'fixed' as 'fixed' ,
6- bottom : '2rem' ,
7+ display : 'flex' as 'flex' ,
8+ justifyContent : 'center' as 'center' ,
9+ alignItems : 'center' as 'center' ,
10+ left : 'calc(50% - 8px)' ,
11+ borderRadius : '100%' ,
12+ zIndex : 100 ,
13+ bottom : '2.2rem' ,
14+ boxShadow : '0 0 0 5px transparent' ,
715 } ,
816}
917
@@ -13,7 +21,7 @@ type Props = {
1321}
1422
1523const ScrollContent = ( { item, children } : Props ) => {
16- const [ showScrollIndicator , setShowScrollIndicator ] = React . useState ( false )
24+ const [ showScrollIndicator , setShowScrollIndicator ] = React . useState < 'UNDETERMINED' | 'SHOW' | 'HIDE' > ( 'UNDETERMINED' )
1725 const pageTopRef : React . RefObject < any > = React . useRef ( null )
1826 const pageBottomRef : React . RefObject < any > = React . useRef ( null )
1927
@@ -27,17 +35,16 @@ const ScrollContent = ({ item, children }: Props) => {
2735 ( [ entry ] ) => {
2836 // show a scroll indicator to let the user know
2937 // they can scroll down for more
30- const isVisible = ! entry . isIntersecting
31- setShowScrollIndicator ( isVisible )
32- if ( ! isVisible ) {
33- hideTimeout = setTimeout ( ( ) => {
34- setShowScrollIndicator ( false )
35- } , 3000 )
38+ const isVisible = entry . isIntersecting
39+ if ( ! isVisible && showScrollIndicator === 'UNDETERMINED' ) {
40+ setShowScrollIndicator ( 'SHOW' )
3641 }
42+ hideTimeout = setTimeout ( ( ) => {
43+ setShowScrollIndicator ( 'HIDE' )
44+ observer . unobserve ( pageBottomRef . current )
45+ } , 2000 )
3746 } ,
38- {
39- rootMargin : '0px' ,
40- } ,
47+ { rootMargin : '0px' } ,
4148 )
4249
4350 const showTimeout = setTimeout ( ( ) => {
@@ -46,7 +53,7 @@ const ScrollContent = ({ item, children }: Props) => {
4653 if ( pageBottomRef . current ) {
4754 observer . observe ( pageBottomRef . current )
4855 }
49- } , 300 )
56+ } , 600 )
5057 return ( ) => {
5158 // cleanup timeouts & subs
5259 observer . unobserve ( pageBottomRef . current )
@@ -57,15 +64,17 @@ const ScrollContent = ({ item, children }: Props) => {
5764
5865 React . useEffect ( scrollToTop , [ item ] )
5966
60- console . log ( `showScrollIndicator = ${ showScrollIndicator } ` )
61-
6267 return (
63- < >
68+ < div css = { { position : 'relative' } } >
6469 < div ref = { pageTopRef } />
6570 { children }
66- { showScrollIndicator ? < div style = { styles . scrollIndicator } > MORE</ div > : null }
67- < div ref = { pageBottomRef } > BOTTOM</ div >
68- </ >
71+ { showScrollIndicator === 'SHOW' ? (
72+ < div style = { styles . scrollIndicator } >
73+ < Icon type = "arrow-down" size = "small" />
74+ </ div >
75+ ) : null }
76+ < div ref = { pageBottomRef } />
77+ </ div >
6978 )
7079}
7180
0 commit comments