I am working on Text Scaling in which I want to scale the text but with keeping the x position. Now, I am scaling the Text but it's loses it's current position. Can someone help me out with it?
<Animated.View style={{ transform: [{ translateY: transText }] }}>
<Animated.View onLayout={({ nativeEvent: { layout: { width, height } } }) => {
label.current = { width, height };
}} style={{ width: width - (width / 3), transform: [{ scale: textScale }, { translateX: labelTransX }, { translateY: labelTransY }], justifyContent: 'flex-end' }}>
<TouchableWithoutFeedback onPress={handleMenu}>
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
<View>
<Animated.Text style={{ color: isDarkMode ? colors.TextBodyL : 'black', fontSize: 28, fontWeight: 'bold' }} numberOfLines={1}>
{mainLabel}
</Animated.Text>
</View>
<Animated.View style={{ transform: [{ rotate: rotate.interpolate({ inputRange: [0, 180], outputRange: ['0deg', '180deg'], extrapolate: 'extend' }) }] }}>
<Icon name={'caret-down-outline'} size={20} color={isDarkMode ? colors.TextBodyL : 'black'} />
</Animated.View>
</View>
</TouchableWithoutFeedback>
</Animated.View>
<Animated.View style={{ transform: [{ translateY: labelTransY }] }}>
<Text style={{ color: isDarkMode ? colors.TextBodyL : colors.TextBodyD }}>
{notesState.length} notes
</Text>
</Animated.View>
</Animated.View>
This code above somehow keeps text to maintain it's position but not too much accurate.
There are a couple of options.
Easy: Put your text in a container with justifyContent: 'center', alignItems: 'center'
More annoying: add negative marginTop and marginLeft to your animated text properties, but multiply that amount by the change in fontSize, multiplied by PixelRatio/fontScale.
Hopefully the first option works for you; if not, let me know if you need more info on the second.