From dc4bacfc424982c5d75755ad59ed8d985812f201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=81opaci=C5=84ski?= Date: Sat, 4 Nov 2023 12:55:05 +0100 Subject: [PATCH] fix: Fix background color and text positioning issues (#30) --- .gitignore | 1 + src/components/ResponsiveText.tsx | 26 ++++++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 40edc01..f011b63 100644 --- a/.gitignore +++ b/.gitignore @@ -64,3 +64,4 @@ yarn-error.log dist/ react-native-skia-responsive-text*.tgz +.expo diff --git a/src/components/ResponsiveText.tsx b/src/components/ResponsiveText.tsx index 8d752c5..f09f72e 100644 --- a/src/components/ResponsiveText.tsx +++ b/src/components/ResponsiveText.tsx @@ -14,7 +14,6 @@ import { AnimationSettings, EllipsizeMode, HorizontalAlignment, - PartialBy, TextLineData, TextOverflow, VerticalAlignment @@ -29,7 +28,7 @@ import TextLine from './TextLine'; const LINE_HEIGHT_MULTIPLIER = 1.5; -type ResponsiveTextProps = PartialBy & { +type ResponsiveTextProps = Omit & { ellipsizeMode?: EllipsizeMode; font: SkFont; height?: number; @@ -42,6 +41,8 @@ type ResponsiveTextProps = PartialBy & { horizontalAlignment?: HorizontalAlignment; lineHeight?: number; verticalAlignment?: VerticalAlignment; + x?: number; + y?: number; }> & ( | { animationProgress?: SharedValue } @@ -55,7 +56,7 @@ type ResponsiveTextPrivateProps = ResponsiveTextProps & { function ResponsiveText({ animationSettings: animationSettingsProp, - backgroundColor: backgroundColorProp = 'transparent', + backgroundColor: backgroundColorProp, children, ellipsizeMode, font, @@ -68,8 +69,8 @@ function ResponsiveText({ text = '', verticalAlignment: verticalAlignmentProp = 'top', width: widthProp, - x = 0, - y = 0, + x: xProp = 0, + y: yProp = 0, ...rest }: ResponsiveTextPrivateProps) { const fontSize = font.getSize(); @@ -86,7 +87,11 @@ function ResponsiveText({ }, [animationSettingsProp]); // Create shared values from animatable props - const backgroundColor = useAnimatableValue(backgroundColorProp); + const x = useAnimatableValue(xProp); + const y = useAnimatableValue(yProp); + const backgroundColor = useAnimatableValue( + backgroundColorProp ?? 'transparent' + ); const lineHeight = useAnimatableValue( lineHeightProp ?? LINE_HEIGHT_MULTIPLIER * fontSize ); @@ -140,7 +145,7 @@ function ResponsiveText({ ) ); - const backgroundComponent = backgroundColor && ( + const backgroundComponent = backgroundColorProp && ( [ + { translateX: x.value }, + { translateY: y.value } + ]); + return ( - + {overflow === 'hidden' ? ( <> {backgroundComponent && (