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] Add onKeyPress for TextInput and enable legacyTextInputTests #12771

Merged
merged 13 commits into from
Feb 29, 2024

Conversation

TatianaKapos
Copy link
Contributor

@TatianaKapos TatianaKapos commented Feb 27, 2024

Description

Adds onKeyPress event to Fabric's TextInput and enables some legacy textInput tests

Type of Change

  • New feature (non-breaking change which adds functionality)

Why

Component Parity

What

We used to be able to get the Text out of a Text component on Paper but that currently doesn't work with Fabric (and may not be what we want). Changed LegacyTextInput to use snapshots instead.

Screenshots

Paper

ApplicationFrameHost_fNUflIy6yT.mp4

Fabric

Playground-composition_HSKn16woYF.mp4

Testing

tested locally and events showing up in legacytests

Changelog

no

"IsKeyboardFocusable": false,
"LocalizedControlType": "text",
"Name": "onKeyPress key: a
onChange text: a
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text log is now being saved in the snapshot!

@TatianaKapos TatianaKapos changed the title [Draft] Add onKeyPress [Fabric] Add onKeyPress for TextInput and enable legacyTextInputTests Feb 27, 2024
@TatianaKapos TatianaKapos marked this pull request as ready for review February 27, 2024 22:02
@TatianaKapos TatianaKapos requested a review from a team as a code owner February 27, 2024 22:02
Copy link
Contributor

@jonthysell jonthysell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're good once you move the call to get the rich edit text inside the event calling code, and clarify if that string is needed to gate the key press event.

@TatianaKapos
Copy link
Contributor Author

TatianaKapos commented Feb 28, 2024

Video with Backspace edgecase!

Playground-composition_5YKeR0mLAn.mp4

onChange text: ab
onSelectionChange range: 2,2
onSelectionChange range: 1,1
onChange text: a
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue created for this: #12780, when the root issue of this gets solved we can remove the extra check for onKeyPress or add a check for onChange

// save the last key pressed for onKeyPress
wchar_t key[2] = L" ";
key[0] = static_cast<wchar_t>(args.KeyCode());
m_lastKeyPressed = ::Microsoft::Common::Unicode::Utf16ToUtf8(key, 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we dont just fire the onKeyPress event here?

Copy link
Contributor Author

@TatianaKapos TatianaKapos Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally had it there, but then onKeyPress would fire before onChange which is the opposite of what Paper does.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. I just checked in expo snack. On web and iOS onKeyPress fires before onChange. On android onChange fires first.

So it doesn't look like the order is properly defined right now.

I think I'd go with the simpler code. Assuming that it is simpler to just fire the event in OnCharacterReceived/OnKeyDown

Copy link
Contributor Author

@TatianaKapos TatianaKapos Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't care about matching Paper exactly for the order of events, I can switch it back! It does make the code a lot more simpler. And actually reading the specs for TextInput, it looks like it should fire before (https://reactnative.dev/docs/textinput#onkeypress) so Paper may have a bug.

@jonthysell Would it be helpful to have a running document of intentional API differences between Paper/Fabric? I feel like it may make switching to Fabric easier but just an idea!

@TatianaKapos TatianaKapos merged commit c040ff7 into microsoft:main Feb 29, 2024
48 checks passed
@TatianaKapos TatianaKapos deleted the tk-onKeyPress branch February 29, 2024 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants