change charprogress appearance

This commit is contained in:
Samuel Newman
2026-05-21 14:31:28 +03:00
parent 16699d98a5
commit 4529d13558
@@ -4,18 +4,15 @@ import {
View, View,
type ViewStyle, type ViewStyle,
} from 'react-native' } from 'react-native'
// @ts-ignore no type definition -prf
import ProgressCircle from 'react-native-progress/Circle'
// @ts-ignore no type definition -prf
import ProgressPie from 'react-native-progress/Pie'
import {MAX_GRAPHEME_LENGTH} from '#/lib/constants' import {MAX_GRAPHEME_LENGTH} from '#/lib/constants'
import {atoms as a, useTheme} from '#/alf' import {atoms as a, useTheme} from '#/alf'
import {ProgressCircle} from '#/components/Progress'
import {Text} from '#/components/Typography' import {Text} from '#/components/Typography'
export function CharProgress({ export function CharProgress({
count, count,
max, max = MAX_GRAPHEME_LENGTH,
style, style,
textStyle, textStyle,
size, size,
@@ -26,40 +23,42 @@ export function CharProgress({
textStyle?: StyleProp<TextStyle> textStyle?: StyleProp<TextStyle>
size?: number size?: number
}) { }) {
const maxLength = max || MAX_GRAPHEME_LENGTH
const t = useTheme() const t = useTheme()
const textColor = count > maxLength ? '#e60000' : t.atoms.text.color const textColor = count > max ? '#e60000' : t.atoms.text.color
const circleColor = count > maxLength ? '#e60000' : t.palette.primary_500 const circleColor = count > max ? '#e60000' : t.palette.primary_500
return ( return (
<View style={[style]}>
{max - count < 100 && (
<View <View
style={[a.flex_row, a.align_center, a.justify_between, a.gap_sm, style]}> style={[
a.absolute,
a.inset_0,
a.justify_center,
a.align_center,
a.px_xs,
]}>
<Text <Text
style={[ style={[
{color: textColor, fontVariant: ['tabular-nums']}, {color: textColor, fontVariant: ['tabular-nums']},
a.flex_grow, a.text_center,
a.text_right, a.text_xs,
{maxWidth: '100%'},
textStyle, textStyle,
]} ]}
maxFontSizeMultiplier={1}> maxFontSizeMultiplier={1}
{maxLength - count} adjustsFontSizeToFit
numberOfLines={1}>
{max - count}
</Text> </Text>
{count > maxLength ? ( </View>
<ProgressPie
size={size ?? 30}
borderWidth={4}
borderColor={circleColor}
color={circleColor}
progress={Math.min((count - maxLength) / maxLength, 1)}
/>
) : (
<ProgressCircle
size={size ?? 30}
borderWidth={1}
borderColor={t.atoms.border_contrast_low.borderColor}
color={circleColor}
progress={count / maxLength}
/>
)} )}
<ProgressCircle
size={size ?? 32}
borderWidth={3}
borderColor={t.palette.contrast_50}
color={circleColor}
progress={Math.min(count / max, 1)}
/>
</View> </View>
) )
} }