Page MenuHomePhabricator

[5/n] Native Typeahead - Add selection state to chat input bar
ClosedPublic

Authored by przemek on Jan 24 2023, 1:06 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Dec 17, 5:45 AM
Unknown Object (File)
Tue, Dec 17, 5:45 AM
Unknown Object (File)
Tue, Dec 17, 5:45 AM
Unknown Object (File)
Tue, Dec 17, 5:45 AM
Unknown Object (File)
Tue, Dec 17, 5:45 AM
Unknown Object (File)
Tue, Dec 17, 5:45 AM
Unknown Object (File)
Tue, Dec 17, 5:45 AM
Unknown Object (File)
Tue, Dec 17, 5:45 AM

Details

Summary

Preparing for native typeahead.
Adding selection to state so we can control it in input bars. There was a problem on iOS desribed here: https://linear.app/comm/issue/ENG-2367#comment-8e0f3042.
It was solved by adding controlSelection flag. We set it to false initially so we don't control
selection. It will be set true when we want to manipulate selection when inserting usernames after tapping into typeahead buttons (incoming diffs)

Test Plan

Checked if app builds.
Checked if text input works corretly (both Android and iOS)

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Harbormaster returned this revision to the author for changes because remote builds failed.Jan 24 2023, 1:10 PM
Harbormaster failed remote builds in B15605: Diff 21271!

Update, forgot to add controlSelection in one place

tomek requested changes to this revision.Jan 30 2023, 3:01 AM
tomek added inline comments.
native/chat/chat-input-bar.react.js
149–152 ↗(On Diff #21317)

We usually prefer a syntax with + signs. There are some usages with $ReadOnly but they are less common.

629–633 ↗(On Diff #21317)

Why do we set controlSelection to false when setting the selection? Shouldn't we set it to true?

This revision now requires changes to proceed.Jan 30 2023, 3:01 AM
native/chat/chat-input-bar.react.js
629–633 ↗(On Diff #21317)

This was a hack I came up with that improves behavior on iOS. iOS doesn't have controlled selection very well, so basically we only control the selection when we need to (when we are changing the selection). We don't need to control the selection in this case, so we don't

przemek marked 2 inline comments as done.

Huge changes here. Explantions in code comments as the solutions are terribly hacky.

przemek added inline comments.
native/chat/chat-input-bar.react.js
629–633 ↗(On Diff #21317)

Quite the opposite. We only want to set state here, but we don't want to control selection after native update of selection as it causes flickering. We only set controlSelection to true if we want to manipulate selection.

ashoat requested changes to this revision.Jan 31 2023, 12:04 PM

Can we avoid putting these hacks in ChatInputBar? When we have hacks like this, it's best to factor them out into their own component, eg. ClearableTextInput, ChatList, etc. Leaving them in ChatInputBar violates separation of concerns, and makes the file really messy.

Could we create something like SelectableTextInput that wraps ClearableTextInput and fixes the issues with selection? We could also fork it into a .ios.js and .android.js file, which would allow us to keep the hacks separate

native/chat/chat-input-bar.react.js
178–205 ↗(On Diff #21690)

I don't think this text explains what's going on very well what's going on, and I also think it's lengthier than it needs to be. I don't have time to rewrite it for you unfortunately.

Did you make sure you rewrote this eg. 3x times? You should never go with the first iteration of something like this... it's necessary to rewrite it multiple times to get a good result.

native/components/clearable-text-input.js
9–13 ↗(On Diff #21690)

Can these be made $ReadOnly?

12–13 ↗(On Diff #21690)

I don't understand why you specified these two types here.

  1. onSelectionChange appears to be unchanged from TextInputProps, which is already being spread here
  2. selection is particularly confusing... you first pass it to $NonMaybeType (apparently to "undo" the optionality), but then you make it optional again! What's the point of this?

The other three props here all have good reasons for being here. textInputRef doesn't appear in TextInputProps, and the other two (onChangeText and value) are optional in TextInputProps, but required for us

I don't see any such "good reasons" for you including these here. Did you make sure it was necessary?

This revision now requires changes to proceed.Jan 31 2023, 12:04 PM
przemek marked 2 inline comments as done.

I've tried out a lot of solutions. Process and thoughts documented here: https://linear.app/comm/issue/ENG-2890/issue-with-typeahead-flickering-while-the-user-types

I decided to go with a solution I initially came up for Android. It's described in a comment in this commit.

przemek added inline comments.
native/components/clearable-text-input.js
12–13 ↗(On Diff #21690)

Thanks for explanation. Now I understand reasoning about the other ones. I'm not sure now, but initially I had problems with flow without specifying them. Maybe I changed something without revising lines above later on. I tested everything without them and it works.

Small fix. Did something wrong while rebasing and comment was not updated.

With the state of this work I think it's critical for me to actually patch it and play around with it in my local environment, but I didn't get time to do that today. @tomek, would be great if you could take a first pass

native/components/clearable-text-input.react.ios.js
157 ↗(On Diff #21852)

What is the point of this change?

171 ↗(On Diff #21852)

What is the point of this change?

native/components/clearable-text-input.react.js
63 ↗(On Diff #21852)

What is the point of this change?

przemek marked 3 inline comments as done.

Deleted unnecessary props.

On another note. I think @tomek has a day off today.

This revision is now accepted and ready to land.Feb 7 2023, 3:48 AM