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

Fix SearchBar key event condition #811

Merged
merged 1 commit into from
Sep 13, 2023
Merged

Conversation

MatkovIvan
Copy link
Member

Proposed Changes

Addition to #801

Testing

Test: Don't change the state in onActiveChange, press Esc - it was called twice

@@ -457,7 +459,7 @@ private fun SearchBarInputField(
.focusRequester(focusRequester)
.onFocusChanged { if (it.isFocused) onActiveChange(true) }
.onKeyEvent {
if (it.key == Key.Escape) {
if (it.key == Key.Escape && it.type == KeyEventType.KeyDown) {
Copy link
Member

Choose a reason for hiding this comment

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

Not sure it's really needed, but just in case I've been doing it like this:

if (it.key == Key.Escape) {
    if (it.type == KeyEventType.KeyDown) {
        action()
    }
    true
}
else {
    false
}

So that they key-up is also consumed.

@igordmn What do you recommend?

Copy link
Member Author

Choose a reason for hiding this comment

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

We do not consume up event, so we shouldn't fake-consume it

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't have a strong opinion here, but as I can't imagine cases where we need to handle KeyUp, even if KeyDown is consumed, I lean toward consuming everything.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We do not consume up event, so we shouldn't fake-consume it

This was my first response as well, but I didn't send it :). Let's Ivan decide.

Copy link
Collaborator

Choose a reason for hiding this comment

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

An argument for not consuming:

  • we should consume only what we handle

An argument for consuming:

  • someone else can handle KeyUp, not knowing that another element consumes KeyDown

If we choose to consume, we can say that we consume "KeyDown gesture": KeyDown -> perform action -> KeyUp

Copy link
Member Author

Choose a reason for hiding this comment

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

There are a list of places where we follow

we should consume only what we handle

So, let's be consistent

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I agree, that we should do the same in this PR. the question - should we change the pattern everywhere.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's a bit safer to consume either both or neither. But since nobody has complained so far, maybe it doesn't affect (m)any people.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's keep it as-as for now, and reconsider it in case of issues

@MatkovIvan MatkovIvan merged commit 0b2c8d7 into jb-main Sep 13, 2023
1 check passed
@MatkovIvan MatkovIvan deleted the ivan.matkov/common-searchbar3 branch September 13, 2023 14:06
igordmn pushed a commit that referenced this pull request Nov 15, 2023
## Proposed Changes

Addition to #801

## Testing

Test: Don't change the state in `onActiveChange`, press `Esc` - it was
called twice
igordmn pushed a commit that referenced this pull request Jan 30, 2024
## Proposed Changes

Addition to #801

## Testing

Test: Don't change the state in `onActiveChange`, press `Esc` - it was
called twice
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

Successfully merging this pull request may close these issues.

3 participants