mirror of
https://github.com/tooot-app/app
synced 2025-02-07 05:45:23 +01:00
Add menu row loading state
This commit is contained in:
parent
e1eade2b43
commit
2fff322de7
@ -1,18 +1,22 @@
|
|||||||
import React from 'react'
|
|
||||||
import { Pressable, StyleSheet, Text, View } from 'react-native'
|
|
||||||
import { Feather } from '@expo/vector-icons'
|
import { Feather } from '@expo/vector-icons'
|
||||||
import { useTheme } from '@utils/styles/ThemeManager'
|
|
||||||
|
|
||||||
import { ColorDefinitions } from '@utils/styles/themes'
|
|
||||||
import { StyleConstants } from '@utils/styles/constants'
|
import { StyleConstants } from '@utils/styles/constants'
|
||||||
|
import { useTheme } from '@utils/styles/ThemeManager'
|
||||||
|
import { ColorDefinitions } from '@utils/styles/themes'
|
||||||
|
import React, { useMemo } from 'react'
|
||||||
|
import { Pressable, StyleSheet, Text, View } from 'react-native'
|
||||||
|
import { Chase } from 'react-native-animated-spinkit'
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
iconFront?: any
|
iconFront?: any
|
||||||
iconFrontColor?: ColorDefinitions
|
iconFrontColor?: ColorDefinitions
|
||||||
|
|
||||||
title: string
|
title: string
|
||||||
content?: string
|
content?: string
|
||||||
|
|
||||||
iconBack?: 'chevron-right' | 'check'
|
iconBack?: 'chevron-right' | 'check'
|
||||||
iconBackColor?: ColorDefinitions
|
iconBackColor?: ColorDefinitions
|
||||||
|
|
||||||
|
loading?: boolean
|
||||||
onPress?: () => void
|
onPress?: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,12 +26,25 @@ const Core: React.FC<Props> = ({
|
|||||||
title,
|
title,
|
||||||
content,
|
content,
|
||||||
iconBack,
|
iconBack,
|
||||||
iconBackColor
|
iconBackColor,
|
||||||
|
loading = false
|
||||||
}) => {
|
}) => {
|
||||||
const { theme } = useTheme()
|
const { theme } = useTheme()
|
||||||
iconFrontColor = iconFrontColor || 'primary'
|
iconFrontColor = iconFrontColor || 'primary'
|
||||||
iconBackColor = iconBackColor || 'secondary'
|
iconBackColor = iconBackColor || 'secondary'
|
||||||
|
|
||||||
|
const loadingSpinkit = useMemo(
|
||||||
|
() => (
|
||||||
|
<View style={{ position: 'absolute' }}>
|
||||||
|
<Chase
|
||||||
|
size={StyleConstants.Font.Size.M * 1.25}
|
||||||
|
color={theme.secondary}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
),
|
||||||
|
[theme]
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.core}>
|
<View style={styles.core}>
|
||||||
<View style={styles.front}>
|
<View style={styles.front}>
|
||||||
@ -46,20 +63,32 @@ const Core: React.FC<Props> = ({
|
|||||||
{(content || iconBack) && (
|
{(content || iconBack) && (
|
||||||
<View style={styles.back}>
|
<View style={styles.back}>
|
||||||
{content && content.length ? (
|
{content && content.length ? (
|
||||||
<Text
|
<>
|
||||||
style={[styles.content, { color: theme.secondary }]}
|
<Text
|
||||||
numberOfLines={1}
|
style={[
|
||||||
>
|
styles.content,
|
||||||
{content}
|
{
|
||||||
</Text>
|
color: theme.secondary,
|
||||||
|
opacity: !iconBack && loading ? 0 : 1
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
numberOfLines={1}
|
||||||
|
>
|
||||||
|
{content}
|
||||||
|
</Text>
|
||||||
|
{loading && !iconBack && loadingSpinkit}
|
||||||
|
</>
|
||||||
) : null}
|
) : null}
|
||||||
{iconBack && (
|
{iconBack && (
|
||||||
<Feather
|
<>
|
||||||
name={iconBack}
|
<Feather
|
||||||
size={StyleConstants.Font.Size.M + 2}
|
name={iconBack}
|
||||||
color={theme[iconBackColor]}
|
size={StyleConstants.Font.Size.M + 2}
|
||||||
style={styles.iconBack}
|
color={theme[iconBackColor]}
|
||||||
/>
|
style={[styles.iconBack, { opacity: loading ? 0 : 1 }]}
|
||||||
|
/>
|
||||||
|
{loading && loadingSpinkit}
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
@ -68,16 +97,13 @@ const Core: React.FC<Props> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const MenuRow: React.FC<Props> = ({ ...props }) => {
|
const MenuRow: React.FC<Props> = ({ ...props }) => {
|
||||||
const { theme } = useTheme()
|
return (
|
||||||
|
<Pressable
|
||||||
return props.onPress ? (
|
style={styles.base}
|
||||||
<Pressable style={styles.base} onPress={props.onPress}>
|
{...(!props.loading && props.onPress && { onPress: props.onPress })}
|
||||||
|
>
|
||||||
<Core {...props} />
|
<Core {...props} />
|
||||||
</Pressable>
|
</Pressable>
|
||||||
) : (
|
|
||||||
<View style={styles.base}>
|
|
||||||
<Core {...props} />
|
|
||||||
</View>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,8 +145,4 @@ const styles = StyleSheet.create({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
export default React.memo(MenuRow, (prev, next) => {
|
export default MenuRow
|
||||||
let skipUpdate = true
|
|
||||||
skipUpdate = prev.content === next.content
|
|
||||||
return skipUpdate
|
|
||||||
})
|
|
||||||
|
@ -11,7 +11,7 @@ const Collections: React.FC = () => {
|
|||||||
const navigation = useNavigation()
|
const navigation = useNavigation()
|
||||||
|
|
||||||
const queryKey = ['Announcements', { showAll: true }]
|
const queryKey = ['Announcements', { showAll: true }]
|
||||||
const { data } = useQuery(queryKey, announcementFetch)
|
const { data, isFetching } = useQuery(queryKey, announcementFetch)
|
||||||
|
|
||||||
const announcementContent = useMemo(() => {
|
const announcementContent = useMemo(() => {
|
||||||
if (data) {
|
if (data) {
|
||||||
@ -55,6 +55,7 @@ const Collections: React.FC = () => {
|
|||||||
iconBack='chevron-right'
|
iconBack='chevron-right'
|
||||||
title={t('content.collections.announcements')}
|
title={t('content.collections.announcements')}
|
||||||
content={announcementContent}
|
content={announcementContent}
|
||||||
|
loading={isFetching}
|
||||||
onPress={() =>
|
onPress={() =>
|
||||||
data &&
|
data &&
|
||||||
data.length &&
|
data.length &&
|
||||||
|
@ -26,9 +26,7 @@ const ScreenMeSettings: React.FC = () => {
|
|||||||
|
|
||||||
const [cacheSize, setCacheSize] = useState<number>()
|
const [cacheSize, setCacheSize] = useState<number>()
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const getCacheSize = async () =>
|
CacheManager.getCacheSize().then(size => setCacheSize(size))
|
||||||
setCacheSize(await CacheManager.getCacheSize())
|
|
||||||
getCacheSize()
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -127,7 +125,7 @@ const ScreenMeSettings: React.FC = () => {
|
|||||||
<MenuContainer>
|
<MenuContainer>
|
||||||
<MenuRow
|
<MenuRow
|
||||||
title={t('content.cache.heading')}
|
title={t('content.cache.heading')}
|
||||||
content={cacheSize ? prettyBytes(cacheSize) : undefined}
|
content={cacheSize ? prettyBytes(cacheSize) : '暂无缓存'}
|
||||||
iconBack='chevron-right'
|
iconBack='chevron-right'
|
||||||
onPress={async () => {
|
onPress={async () => {
|
||||||
await CacheManager.clearCache()
|
await CacheManager.clearCache()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user