import React, { memo, useCallback, useEffect, useMemo, useState } from 'react'
import { View, ImageBackground, TouchableOpacity, InteractionManager, type ImageSourcePropType } from 'react-native'
import { setTheme } from '@/core/theme'
import { useI18n } from '@/lang'
import { useSettingValue } from '@/store/setting/hook'
import { useTheme } from '@/store/theme/hook'
import SubTitle from '../components/SubTitle'
import { BG_IMAGES, getAllThemes, type LocalTheme } from '@/theme/themes'
import Text from '@/components/common/Text'
import { createStyle } from '@/utils/tools'
import { scaleSizeH } from '@/utils/pixelRatio'
const useActive = (id: string) => {
const activeThemeId = useSettingValue('theme.id')
const isActive = useMemo(() => activeThemeId == id, [activeThemeId, id])
return isActive
}
const ThemeItem = ({ id, name, color, image, setTheme }: {
id: string
name: string
color: string
image?: ImageSourcePropType
setTheme: (id: string) => void
}) => {
const theme = useTheme()
const isActive = useActive(id)
return (
{ setTheme(id) }}>
{
image
?
:
}
{name}
)
}
interface ThemeInfo {
themes: Readonly
userThemes: LX.Theme[]
dataPath: string
}
const initInfo: ThemeInfo = { themes: [], userThemes: [], dataPath: '' }
export default memo(() => {
const t = useI18n()
const [themeInfo, setThemeInfo] = useState(initInfo)
const setThemeId = useCallback((id: string) => {
void InteractionManager.runAfterInteractions(() => {
setTheme(id)
})
}, [])
useEffect(() => {
void getAllThemes().then(setThemeInfo)
}, [])
return (
{
themeInfo.themes.map(({ id, config }) => {
return
})
}
{
themeInfo.userThemes.map(({ id, name, config }) => {
return
})
}
)
})
const ITEM_HEIGHT = 56
const COLOR_ITEM_HEIGHT = 34
const IMAGE_HEIGHT = 27
const styles = createStyle({
list: {
flexDirection: 'row',
flexWrap: 'wrap',
},
item: {
marginRight: 15,
alignItems: 'center',
marginTop: 5,
// backgroundColor: 'rgba(0,0,0,0.2)',
},
colorContent: {
height: COLOR_ITEM_HEIGHT,
borderRadius: 4,
borderWidth: 1.6,
alignItems: 'center',
justifyContent: 'center',
},
imageContent: {
height: IMAGE_HEIGHT,
borderRadius: 4,
// elevation: 1,
},
name: {
marginTop: 2,
},
})