-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat-cache' of github.com:eleliauk/muxiK-StackFrontend2.0
- Loading branch information
Showing
43 changed files
with
840 additions
and
495 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,5 @@ | |
.publish-header { | ||
display: flex; | ||
align-items: center; | ||
flex: 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,47 @@ | ||
import { ScrollView } from '@tarojs/components'; | ||
import type { VirtualListProps as TaroVirtualListProps } from '@tarojs/components-advanced/dist/components/virtual-list'; | ||
import TaroVirtualList from '@tarojs/components-advanced/dist/components/virtual-list'; | ||
import { memo } from 'react'; | ||
import { memo, useCallback, useRef } from 'react'; | ||
|
||
interface VirtualListProps extends TaroVirtualListProps {} | ||
interface VirtualListProps extends TaroVirtualListProps { | ||
item: React.FC<{ data: any; index: number }>; | ||
itemSize: number; | ||
} | ||
|
||
const VirtualList: React.FC<VirtualListProps> = memo( | ||
({ height, width, item, itemData, itemCount, itemSize, onScroll }) => ( | ||
<TaroVirtualList | ||
height={height} | ||
width={width} | ||
item={item} | ||
itemData={itemData} | ||
itemCount={itemCount} | ||
itemSize={itemSize} | ||
onScroll={onScroll} | ||
/> | ||
) | ||
({ height, width, item: Item, itemData, itemSize, onScroll }) => { | ||
const scrollTop = useRef<number>(0); | ||
const throttle = useCallback((fn, delay) => { | ||
let timer: NodeJS.Timeout | null = null; | ||
return (...args) => { | ||
if (timer) return; | ||
timer = setTimeout(() => { | ||
fn(...args); | ||
timer = null; | ||
}, delay); | ||
}; | ||
}, []); | ||
const handleScroll = throttle((event) => { | ||
console.log('fetching'); | ||
onScroll && onScroll(event); | ||
}, 1000); | ||
return ( | ||
<ScrollView | ||
scrollY | ||
lowerThreshold={100} | ||
style={{ height: height, width: width }} | ||
onScrollToLower={handleScroll} | ||
onScroll={(event) => { | ||
scrollTop.current = event.detail.scrollTop; | ||
}} | ||
scrollTop={scrollTop.current} | ||
> | ||
{itemData.length > 0 && | ||
itemData.map((_, index) => ( | ||
<Item key={index} data={itemData} index={index}></Item> | ||
))} | ||
</ScrollView> | ||
); | ||
} | ||
); | ||
|
||
export default VirtualList; |
Oops, something went wrong.