-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support multi-language support, theme color, theme mode (#41)
* chore: update router * refactor: component * feat: carousel * feat: handle safe area and status bar * feat: optimize carousel * feat: use safe area surface * fix: always splash when reload app * fix: loss height in web * fix: screen unmount flash with a hack way * feat: optimize theme * feat: use custom surface * chore: add setting type * chore: optimize colors * docs: update badge * feat: use theme color lang from local setting * feat: useAppSettings * chore: rename * feat: support app setting * chore: configure yarn timeout * chore: configure docker host
- Loading branch information
1 parent
63a48e8
commit 7d3dca6
Showing
44 changed files
with
1,792 additions
and
445 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
network-timeout 60000 |
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 |
---|---|---|
@@ -1,10 +1,199 @@ | ||
import ParallaxScrollView from '@/components/ParallaxScrollView'; | ||
import { Text } from 'react-native-paper'; | ||
import { Surface } from '@/components'; | ||
import { useColorScheme } from 'react-native'; | ||
import { List, Menu, IconButton, Snackbar, Icon } from 'react-native-paper'; | ||
import { Language, Languages } from '@/types'; | ||
import { useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useAppSetting } from '@/hooks/useAppSetting'; | ||
import { ColorName, Colors } from '@/constants/Colors'; | ||
|
||
export default function ProfileScreen() { | ||
const colorScheme = useColorScheme(); | ||
const { t } = useTranslation(); | ||
const [message, setMessage] = useState({ visible: false, content: '' }); | ||
|
||
const { setting, updateSetting } = useAppSetting(); | ||
|
||
const [display, setDisplay] = useState({ | ||
color: false, | ||
language: false, | ||
theme: false | ||
}); | ||
|
||
const themeColors = Colors[setting?.theme === 'auto' ? colorScheme ?? 'light' : setting?.theme ?? 'light']; | ||
|
||
return ( | ||
<ParallaxScrollView> | ||
<Text>个人详情</Text> | ||
</ParallaxScrollView> | ||
<Surface style={{ flex: 1 }}> | ||
<Surface elevation={0}> | ||
<List.AccordionGroup> | ||
<List.Accordion id="1" title={t('appearance')} left={(props) => <List.Icon {...props} icon="palette" />}> | ||
<List.Item | ||
title={t('language')} | ||
description={t('changeLanguage')} | ||
left={(props) => <List.Icon {...props} icon="translate" />} | ||
right={(props) => ( | ||
<Menu | ||
visible={display.language} | ||
onDismiss={() => setDisplay({ ...display, language: false })} | ||
anchor={ | ||
<IconButton {...props} icon="pencil" onPress={() => setDisplay({ ...display, language: true })} /> | ||
} | ||
> | ||
<Menu.Item | ||
title="System" | ||
trailingIcon={setting?.language === 'auto' ? 'check' : undefined} | ||
onPress={() => { | ||
updateSetting({ language: 'auto' }); | ||
setDisplay({ ...display, language: false }); | ||
}} | ||
/> | ||
{Object.entries(Languages).map((lang) => ( | ||
<Menu.Item | ||
key={lang[0]} | ||
title={`${lang[0]} / ${lang[1]}`} | ||
trailingIcon={setting?.language === lang[0] ? 'check' : undefined} | ||
onPress={() => { | ||
updateSetting({ | ||
language: lang[0] as Language | ||
}); | ||
setDisplay({ ...display, language: false }); | ||
}} | ||
/> | ||
))} | ||
</Menu> | ||
)} | ||
/> | ||
<List.Item | ||
title={t('mode')} | ||
description={t('changeMode')} | ||
left={(props) => ( | ||
<List.Icon | ||
{...props} | ||
icon={ | ||
setting?.theme === 'auto' | ||
? 'theme-light-dark' | ||
: setting?.theme === 'light' | ||
? 'weather-sunny' | ||
: 'weather-night' | ||
} | ||
/> | ||
)} | ||
right={(props) => ( | ||
<Menu | ||
visible={display.theme} | ||
onDismiss={() => setDisplay({ ...display, theme: false })} | ||
anchor={ | ||
<IconButton {...props} icon="pencil" onPress={() => setDisplay({ ...display, theme: true })} /> | ||
} | ||
> | ||
<Menu.Item | ||
title={t('system')} | ||
leadingIcon="theme-light-dark" | ||
trailingIcon={setting?.theme === 'auto' ? 'check' : undefined} | ||
onPress={() => { | ||
updateSetting({ theme: 'auto' }); | ||
setDisplay({ ...display, theme: false }); | ||
}} | ||
/> | ||
<Menu.Item | ||
title={t('lightMode')} | ||
leadingIcon="weather-sunny" | ||
trailingIcon={setting?.theme === 'light' ? 'check' : undefined} | ||
onPress={() => { | ||
updateSetting({ theme: 'light' }); | ||
setDisplay({ ...display, theme: false }); | ||
}} | ||
/> | ||
<Menu.Item | ||
title={t('darkMode')} | ||
leadingIcon="weather-night" | ||
trailingIcon={setting?.theme === 'dark' ? 'check' : undefined} | ||
onPress={() => { | ||
updateSetting({ theme: 'dark' }); | ||
setDisplay({ ...display, theme: false }); | ||
}} | ||
/> | ||
</Menu> | ||
)} | ||
/> | ||
<List.Item | ||
title={t('color')} | ||
description={t('changeColor')} | ||
left={(props) => ( | ||
<List.Icon | ||
{...props} | ||
icon="palette-swatch-variant" | ||
color={ | ||
Colors[setting?.theme === 'auto' ? colorScheme ?? 'light' : setting?.theme ?? 'light'][ | ||
setting?.color ?? 'default' | ||
]?.primary | ||
} | ||
/> | ||
)} | ||
right={(props) => ( | ||
<Menu | ||
visible={display.color} | ||
onDismiss={() => setDisplay({ ...display, color: false })} | ||
anchor={ | ||
<IconButton {...props} icon="pencil" onPress={() => setDisplay({ ...display, color: true })} /> | ||
} | ||
> | ||
{Object.keys(Colors.light).map((color) => ( | ||
<Surface | ||
key={color} | ||
elevation={0} | ||
style={{ | ||
width: '100%', | ||
flexDirection: 'row', | ||
alignItems: 'center' | ||
}} | ||
> | ||
<Surface | ||
elevation={0} | ||
style={{ | ||
padding: 4, | ||
marginLeft: 8, | ||
borderRadius: 16, | ||
backgroundColor: color !== setting?.color ? undefined : themeColors[color]?.primary | ||
}} | ||
> | ||
<Icon | ||
size={24} | ||
source="palette" | ||
color={ | ||
color !== setting?.color | ||
? themeColors[color as ColorName]?.primary | ||
: themeColors[color as ColorName].onPrimary | ||
} | ||
/> | ||
</Surface> | ||
|
||
<Menu.Item | ||
key={color} | ||
title={t(color)} | ||
onPress={() => { | ||
updateSetting({ | ||
color: color as ColorName | ||
}); | ||
setDisplay({ ...display, color: false }); | ||
}} | ||
/> | ||
</Surface> | ||
))} | ||
</Menu> | ||
)} | ||
/> | ||
</List.Accordion> | ||
</List.AccordionGroup> | ||
</Surface> | ||
|
||
<Snackbar | ||
visible={message.visible} | ||
onDismiss={() => setMessage({ ...message, visible: false })} | ||
onIconPress={() => setMessage({ ...message, visible: false })} | ||
> | ||
{message.content} | ||
</Snackbar> | ||
</Surface> | ||
); | ||
} |
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
Oops, something went wrong.