Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React Native 0.73 supports transformOrigin which can potentially fix TextInput issues #4341

Open
alexzel opened this issue Mar 14, 2024 · 2 comments

Comments

@alexzel
Copy link
Contributor

alexzel commented Mar 14, 2024

See related source code:

// Offset label scale since RN doesn't support transform origin

See React Native 0.73 docs mentioning transformOrigin https://reactnative.dev/docs/0.73/transforms#transform-origin

It means we do not need to move TextInput label with translateX to adjust label position after scaling. Most likely translateX was needed b/c transform origin was always related to center before v0.73. Now we can set it left and remove translateX position adjustments.

Related issues:
#4245
#4299
#4340
and possibly more related issues reporting TextInput label flickering..

@alexzel
Copy link
Contributor Author

alexzel commented Mar 14, 2024

The actual reason of flickering b/c translateX has some default value based on label width === 0 before the first rendering of the label element. Then it gets the correct width from onLayout event, and renders the correct position with new translateX value. Unfortunately there is no way to detect label width before rendering it, so transformOrigin should help, so no need to apply translateX.

@andrejordi
Copy link

I found that this is the function that causes the re-rendering:

const handleLayoutAnimatedText = React.useCallback(
  (e: LayoutChangeEvent) => {
    const width = roundLayoutSize(e.nativeEvent.layout.width);
    const height = roundLayoutSize(e.nativeEvent.layout.height);
    console.log('handleLayoutAnimatedText', width, height);
    if (width !== labelLayout.width || height !== labelLayout.height) {
      setLabelLayout({
        width,
        height,
        measured: true,
      });
    }
  },
  [labelLayout.height, labelLayout.width]
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants