Skip to content

UserItem: Clean up onPress logic a bit#4429

Merged
chrisbobbe merged 3 commits intozulip:masterfrom
gnprice:pr-useritem
Jan 22, 2021
Merged

UserItem: Clean up onPress logic a bit#4429
chrisbobbe merged 3 commits intozulip:masterfrom
gnprice:pr-useritem

Conversation

@gnprice
Copy link
Copy Markdown
Member

@gnprice gnprice commented Jan 22, 2021

This is a quick followup to #4424, to make the cleanups discussed at #4424 (comment) .

This is pretty dubious logic that, to the extent it's possible for
it to have any effect at all, makes this component's interface more
complicated than it needs to be.

Happily, this condition should never be able to trigger:

 * Most callers of `UserItemRaw` get here through `UserItem`,
   which looks up a real user's data.  Real users don't have the
   empty string (let alone some other falsy value, which wouldn't
   be well-typed) as their "email".

 * The one other caller is `PeopleAutocomplete`.  That one passes
   a number of real users, and possibly a couple of pseudo-users
   generated by `getAutocompleteSuggestion`.  Those two pseudo-users
   have non-empty "emails" too: they both read "(Notify everyone)".

So nothing could have been relying on this quirk, and we can just
cut it out.
Sometimes there's nothing the surrounding UI actually wants to have
happen if the user presses the UserItem.  In that case we can simplify
by not making the caller pass in a do-nothing onPress callback.
When there's no `onPress` callback passed in to this component,
our own `handlePress` will do nothing.  Rather than pass that on
down as an `onPress` prop, pass nothing again.

This is useful because when our `Touchable` doesn't receive an
actual callback for interaction, it can avoid creating an
underlying `TouchableHighlight` or `TouchableNativeFeedback` at
all, and so avoid falsely advertising to a screen reader or other
a11y interface that there's some interaction being offered here.
@gnprice gnprice requested a review from chrisbobbe January 22, 2021 22:34
@chrisbobbe chrisbobbe merged commit e41ce88 into zulip:master Jan 22, 2021
@chrisbobbe
Copy link
Copy Markdown
Contributor

chrisbobbe commented Jan 22, 2021

LGTM, merged! Thanks.

@gnprice
Copy link
Copy Markdown
Member Author

gnprice commented Jan 22, 2021

Thanks for the fast review and merge 😄

@gnprice gnprice deleted the pr-useritem branch January 22, 2021 22:41
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.

2 participants