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

[Fabric] TextInput UI is not updated when changing prop value or calling inputRef.current.clear() / inputRef.current.setNativeProps({text: ''}) #2066

Open
gaeldestrem opened this issue Feb 3, 2024 · 2 comments
Labels
bug Something isn't working Needs: Triage 🔍

Comments

@gaeldestrem
Copy link

gaeldestrem commented Feb 3, 2024

Environment

react-native -v: 12.3.2
npm ls react-native-macos: └── react-native-macos@0.73.13
node -v: v18.16.0
npm -v: 9.5.1
yarn --version: 1.22.19
xcodebuild -version: Xcode 15.0 Build version 15A240d

Steps to reproduce the bug

  • npx react-native init rnrepro
  • npx react-native-macos-init --overwrite
  • USE_HERMES=1 RCT_NEW_ARCH_ENABLED=1 bundle exec pod install
  • Create a component with a TextInput and try to clear / change the value

Issue:

When using Fabric and having a component TextInput with the following definition:

export const TestTextInput = () => {
  const ref = useRef<TextInput | null>(null);
  const [value, setValue] = useState('');

  const clearTextInput = useCallback(() => {
    setValue('');
    ref.current?.clear();
    ref.current?.setNativeProps({text: ''});
  }, []);

  return (
    <View style={styles.viewContainer}>
      <TextInput
        ref={ref}
        value={value}
        onChangeText={setValue}
        style={styles.input}
      />
      <Button
        title="clear"
        onPress={clearTextInput}
      />
    </View>
  );
};

Calling the method clearTextInput doesn't clear the UI value.

Screen.Recording.2024-02-03.at.15.32.49.mov

Expected Behavior

I would expect the same behavior than when using a TextInput with Chakra:

  • Changing the input prop value : Old Arch ✅ / Fabric ❌
  • Calling inputRef.current.clear() : Old Arch ✅ / Fabric ❌
  • Calling inputRef.current.setNativeProps({text: ''}) : Old Arch ✅ / Fabric ❌

Reproducible Demo

https://github.com/gaeldestrem/rnrepro

@gaeldestrem gaeldestrem added the bug Something isn't working label Feb 3, 2024
@gaeldestrem
Copy link
Author

By debugging the native code, the method RCTTextInputComponentView > _setAttributedString doesn't seem implemented for the macos platform.

Adding these two lines seems to fix the issue. It's probably not the right fix but it might help to investigate :)

Screenshot 2024-02-03 at 18 48 55

Here's is the patch and a record

react-native-macos+0.73.13.patch

Screen.Recording.2024-02-03.at.18.46.15.mov

@Saadnajmi
Copy link
Collaborator

Sorry for not updating sooner. Our Fabric implementation is still experimental, so I expect bugs like this one to be everywhere :). We should be pushing a bunch of Fabric changes soon, and I'll keep this issue in mind! @shwanton fyi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Needs: Triage 🔍
Projects
None yet
Development

No branches or pull requests

2 participants