From a852bea8c9519b865c93b44cf69451f387d7627d Mon Sep 17 00:00:00 2001 From: Damiano Plebani Date: Fri, 10 Jan 2025 16:32:15 +0100 Subject: [PATCH] Revert "Fix flickering issue when text is bolder on iOS" This reverts commit 9abbcea891a92416f6a93dae1e3ebb9080f54bea. --- src/components/searchInput/SearchInput.tsx | 64 +++++++--------------- 1 file changed, 21 insertions(+), 43 deletions(-) diff --git a/src/components/searchInput/SearchInput.tsx b/src/components/searchInput/SearchInput.tsx index 96b1314c..5e6b6d62 100644 --- a/src/components/searchInput/SearchInput.tsx +++ b/src/components/searchInput/SearchInput.tsx @@ -3,7 +3,8 @@ import React, { forwardRef, useCallback, useImperativeHandle, - useRef + useRef, + useState } from "react"; import { ColorValue, @@ -36,12 +37,8 @@ import { useIOTheme } from "../../core"; import { IOFontSize, makeFontStyleObject } from "../../utils/fonts"; -import { Icon, IOIconSizeScale } from "../icons"; -import { - buttonTextFontSize, - buttonTextLineHeight, - IOText -} from "../typography"; +import { ButtonLink } from "../buttons"; +import { IOIconSizeScale, Icon } from "../icons"; /* Component visual attributes */ const inputPaddingHorizontal: IOSpacingScale = 12; @@ -131,19 +128,14 @@ export const SearchInput = forwardRef( const inputWidth: number = Dimensions.get("window").width - IOVisualCostants.appMarginDefault * 2; - /* Reanimated styles */ - const inputAnimatedWidth = useSharedValue(inputWidth); - const cancelButtonWidth = useSharedValue(0); - const isFocused = useSharedValue(0); + const [cancelButtonWidth, setCancelButtonWidth] = + useState(0); - const getCancelButtonWidth = useCallback( - ({ nativeEvent }: LayoutChangeEvent) => { - if (cancelButtonWidth.value !== nativeEvent.layout.width) { - cancelButtonWidth.value = nativeEvent.layout.width; - } - }, - [cancelButtonWidth] - ); + const getCancelButtonWidth = ({ nativeEvent }: LayoutChangeEvent) => { + setCancelButtonWidth(nativeEvent.layout.width); + }; + + const inputWidthWithCancel: number = inputWidth - cancelButtonWidth; useImperativeHandle( ref, @@ -155,6 +147,10 @@ export const SearchInput = forwardRef( [] ); + /* Reanimated styles */ + const inputAnimatedWidth = useSharedValue(inputWidth); + const isFocused = useSharedValue(0); + /* Applied to the `SearchInput` */ const animatedStyle = useAnimatedStyle(() => ({ width: withTiming(inputAnimatedWidth.value, inputWithTimingConfig), @@ -176,7 +172,7 @@ export const SearchInput = forwardRef( translateX: interpolate( showCancelButton, [0, 1], - [cancelButtonWidth.value + IOVisualCostants.appMarginDefault, 0], + [cancelButtonWidth + IOVisualCostants.appMarginDefault, 0], Extrapolation.CLAMP ) } @@ -204,13 +200,13 @@ export const SearchInput = forwardRef( /* Related event handlers */ const handleFocus = () => { isFocused.value = withTiming(1, inputWithTimingConfig); - inputAnimatedWidth.value = inputWidth - cancelButtonWidth.value; + inputAnimatedWidth.value = inputWidthWithCancel; }; const handleBlur = () => { isFocused.value = withTiming(0, inputWithTimingConfig); inputAnimatedWidth.value = keepCancelVisible - ? inputAnimatedWidth.value + ? inputWidthWithCancel : inputWidth; }; @@ -284,25 +280,7 @@ export const SearchInput = forwardRef( onLayout={getCancelButtonWidth} style={[styles.cancelButton, cancelButtonAnimatedStyle]} > - - - {cancelButtonLabel} - - + ); @@ -367,8 +345,8 @@ const styles = StyleSheet.create({ ) }, cancelButton: { - // position: "absolute", - // right: 0, + position: "absolute", + right: 0, paddingLeft: cancelButtonMargin }, clearButton: {