add a spinner
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
|||||||
ClipClop,
|
ClipClop,
|
||||||
placeholderClops,
|
placeholderClops,
|
||||||
} from '#/components/ClipClopTest/RandomClipClops'
|
} from '#/components/ClipClopTest/RandomClipClops'
|
||||||
|
import {Loader} from '#/components/Loader'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
|
|
||||||
function ClipClopItem({item}: {item: ClipClop}) {
|
function ClipClopItem({item}: {item: ClipClop}) {
|
||||||
@@ -28,6 +29,20 @@ function ClipClopItem({item}: {item: ClipClop}) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function MaybeLoader({isLoading}: {isLoading: boolean}) {
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
height: 50,
|
||||||
|
width: '100%',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
}}>
|
||||||
|
{isLoading && <Loader size="xl" />}
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
function renderItem({item}: {item: ClipClop}) {
|
function renderItem({item}: {item: ClipClop}) {
|
||||||
return <ClipClopItem item={item} />
|
return <ClipClopItem item={item} />
|
||||||
}
|
}
|
||||||
@@ -50,6 +65,8 @@ export const ClipClopList = () => {
|
|||||||
// total number of clops
|
// total number of clops
|
||||||
const totalClops = React.useRef(10)
|
const totalClops = React.useRef(10)
|
||||||
|
|
||||||
|
const [showSpinner, setShowSpinner] = React.useState(false)
|
||||||
|
|
||||||
const [clops, setClops] = React.useState(
|
const [clops, setClops] = React.useState(
|
||||||
Array.from(Array(10).keys()).map(n => ({
|
Array.from(Array(10).keys()).map(n => ({
|
||||||
id: generateUniqueKey(),
|
id: generateUniqueKey(),
|
||||||
@@ -91,12 +108,6 @@ export const ClipClopList = () => {
|
|||||||
const firstVisibleIndex = info.viewableItems[0]?.index
|
const firstVisibleIndex = info.viewableItems[0]?.index
|
||||||
|
|
||||||
isAtBottom.current = Number(firstVisibleIndex) < 2
|
isAtBottom.current = Number(firstVisibleIndex) < 2
|
||||||
|
|
||||||
console.log({
|
|
||||||
firstVisibleIndex,
|
|
||||||
totalClops: totalClops.current,
|
|
||||||
isAtBottom: isAtBottom.current,
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
itemVisiblePercentThreshold: 100,
|
itemVisiblePercentThreshold: 100,
|
||||||
@@ -112,6 +123,7 @@ export const ClipClopList = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isFetching.current = false
|
isFetching.current = false
|
||||||
|
setShowSpinner(false)
|
||||||
},
|
},
|
||||||
[clops],
|
[clops],
|
||||||
)
|
)
|
||||||
@@ -119,6 +131,7 @@ export const ClipClopList = () => {
|
|||||||
const onEndReached = () => {
|
const onEndReached = () => {
|
||||||
if (isFetching.current) return
|
if (isFetching.current) return
|
||||||
isFetching.current = true
|
isFetching.current = true
|
||||||
|
setShowSpinner(true)
|
||||||
|
|
||||||
// We wouldn't actually use a timeout, but there would be a delay while loading
|
// We wouldn't actually use a timeout, but there would be a delay while loading
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -147,6 +160,7 @@ export const ClipClopList = () => {
|
|||||||
maxToRenderPerBatch={20}
|
maxToRenderPerBatch={20}
|
||||||
inverted
|
inverted
|
||||||
onEndReached={onEndReached}
|
onEndReached={onEndReached}
|
||||||
|
ListFooterComponent={<MaybeLoader isLoading={showSpinner} />}
|
||||||
/>
|
/>
|
||||||
<Button title="Add New Clip" onPress={addNewClip} />
|
<Button title="Add New Clip" onPress={addNewClip} />
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
Reference in New Issue
Block a user