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: 16098 main composer is focused again when user enters key if the emoji picker is not open #17649

Closed

Conversation

tienifr
Copy link
Contributor

@tienifr tienifr commented Apr 19, 2023

Details

We should automatically focus on the Composer if we press on regular characters like a, b, c, d, ... (not non-character keys like Enter, Shift) when we're not typing on any input or textarea.

Fixed Issues

$ #16098
PROPOSAL: #16098 (comment)

Tests

  1. Go to any chats
  2. Click on any message
  3. Press any character keys like a,b,c,d (not non-character keys like Enter, Shift)
  4. Verify that the composer is focused again and the above character is entered in the composer
  5. Open emoji picker
  6. Press any character keys like a,b,c,d
  7. Verify that the emoji composer is focused again and the above character is entered in this composer. And the main composer is not affected
  • Verify that no errors appear in the JS console

Offline tests

QA Steps

  1. Go to any chats
  2. Click on any message
  3. Press any character keys like a,b,c,d (not non-character keys like Enter, Shift)
  4. Verify that the composer is focused again and the above character is entered in the composer
  5. Open emoji picker
  6. Press any character keys like a,b,c,d
  7. Verify that the emoji composer is focused again and the above character is entered in this composer. And the main composer is not affected
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is correct English and approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
Screen.Recording.2023-04-19.at.17.49.13.mp4
Mobile Web - Chrome
RPReplay_Final1680890370.mp4
Mobile Web - Safari
RPReplay_Final1680890255.mp4
Desktop
Screen.Recording.2023-04-08.at.01.07.15.mov
iOS
Screen-Recording-2023-04-08-at-01.06.13.mp4
Android
Screen.Recording.2023-04-08.at.01.27.23.mov

@MelvinBot
Copy link

@PauloGasparSv @rushatgabhane One of you needs to copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@cead22
Copy link
Contributor

cead22 commented Apr 19, 2023

Can we update this PR's title to something that summarizes what's being done in it?

@tienifr tienifr changed the title fix: 16098 fix: 16098 main composer is focused again when user enters key if the emoji picker is not open Apr 20, 2023
@tienifr
Copy link
Contributor Author

tienifr commented Apr 24, 2023

@rushatgabhane @PauloGasparSv any updates?

@rushatgabhane
Copy link
Member

rushatgabhane commented Apr 24, 2023

replying to - #16098 (comment)
@tienifr sorry, but this feature can cause more trouble than it's worth.

I don't think we should implement this feature. It's a UX polish but is it even required?
@PauloGasparSv what do you think?

@PauloGasparSv
Copy link
Contributor

PauloGasparSv commented Apr 27, 2023

Sorry for the delay here guys!

I don't think we should implement this feature. It's a UX polish but is it even required?
@PauloGasparSv what do you think?

I agree and I don't think we shouldn't implement this again at the moment : /

But I don't think we should dismiss this feature just yet! I'll bring this discussion over to slack in #expensify-open-source so more people can chime in and give their opinion on whether we should try to implement this again or not.

@rushatgabhane
Copy link
Member

we can close this PR, thank you!

@PauloGasparSv
Copy link
Contributor

we can close this PR, thank you!

Hey @rushatgabhane I'm confused! Aren't we going to test this?

@cead22 cead22 changed the title fix: 16098 main composer is focused again when user enters key if the emoji picker is not open Fix: 16098 main composer is focused again when user enters key if the emoji picker is not open May 3, 2023
@PauloGasparSv
Copy link
Contributor

@tienifr would you mind fixing the conflicts?

bump @rushatgabhane for a review here please

@PauloGasparSv
Copy link
Contributor

@tienifr can you fix the new conflict?

Also, what do you and @rushatgabhane think of using the following test steps? I tried to add all the regressions we had so far as tests here:

Typing should focus on the composer

  1. Open any chat
  2. Click on a message
  3. Start typing alpha-numeric characters (like a,b,c,d… but not Enter, Shift…)
  4. Verify that the composer is focused and the characters you type are inserted there

Typing in other inputs and modals

(Coming from here)

  1. Open any chat
  2. Open the Global Search and make sure the search is working
  3. Blur the global search input and start typing alpha-numeric characters (like a,b,c,d… but not Enter, Shift…)
  4. Make sure the characters you typed aren’t added to the search input or the Chat composer box
  5. Open your profile then display name and make sure the “First name” and “Last name” are not focused then start typing alpha-numeric characters (like a,b,c,d… but not Enter, Shift…)
  6. Go back to the chat and make sure those characters were not added to the composer box
  7. Go to Settings > Workspaces
  8. Open any workspace and go to the “Manage Members” page
  9. With no input focused, start typing alpha-numeric characters (like a,b,c,d… but not Enter, Shift…) and make sure they are not added to the Chat composer box
  10. Click on “Invite” and repeat the previous step

The composer Emoji Picker

(Coming from here)

  1. Open any chat
  2. Click on the Emoji Picker icon in the right side of the composer box
  3. Make sure you can search inside the Emoji Picker but what you type isn’t added to the composer box
  4. With the Emoji Picker opened, blur the search box and start typing alpha-numeric characters (like a,b,c,d… but not Enter, Shift…)
  5. Make sure the focus goes back to the Emoji Picker search box and all characters are added there instead of the Chat composer box
  6. Hover any message and click on the “Add reaction” icon
  7. Repeat steps 3 to 5

Copying&Pasting - Web & Desktop only

(Coming from here and here

  1. Open any chat
  2. Select/Highlight the text from a message
  3. Copy the text using CMD + C or CTRL + C
  4. Click on the composer and paste the text using CMD + V or CTRL + V

* @param {String} text
*/
replaceSelectionWithInput(text) {
const newComment = this.comment.slice(0, this.state.selection.start) + text + this.comment.slice(this.state.selection.end, this.comment.length);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could call ComposerUtils.insertText here right?

@PauloGasparSv
Copy link
Contributor

@tienifr can you check why the following is happening after the workspaces page is accessed? The modal is still opened but the input is going to the composer.

Screen.Recording.2023-05-22.at.14.29.02.mov

@rushatgabhane
Copy link
Member

Tests look good! They capture all the regressions we've faced

@tienifr
Copy link
Contributor Author

tienifr commented May 23, 2023

can you check why the following is happening after the workspaces page is accessed? The modal is still opened but the input is going to the composer.

After checking our code, I found out that In

hideModal(callHideCallback = true) {
if (this.props.shouldSetModalVisibility) {
Modal.setModalVisibility(false);
}
if (callHideCallback) {
this.props.onModalHide();
}
Modal.onModalDidClose();
}

We always call Modal.setModalVisibility(false); even when we press back button (WS -> Setting) (this should not be called). That makes our checks false

 keydownListener(e) {
        if (
            this.state.isFocused ||
            this.state.isEmojiPickerVisible ||
            this.props.modal.isVisible || // false
            this.props.isSmallScreenWidth ||
            EmojiPickerAction.emojiPickerRef.current.state.isEmojiPickerVisible
        ) {
            return;
        }

It can be out of this scope, so I suggest to create another PR to fix this bug first.

My solution:

We should not call Modal.setModalVisibility(false) when we click back button

Change this line

onBackButtonPress={this.props.onClose}

to

onBackButtonPress={()=>{
                    this.shouldGoBack=true;
                    this.props.onClose()
                }}

and update these lines

if (this.props.shouldSetModalVisibility) {
Modal.setModalVisibility(false);
}

to

hideModal(callHideCallback = true) {
        if (this.props.shouldSetModalVisibility && this.shouldGoBack) {
            Modal.setModalVisibility(false);
        }

Please tell me what you think @PauloGasparSv @rushatgabhane

@rushatgabhane
Copy link
Member

We should not call Modal.setModalVisibility(false) when we click back button

@tienifr let's try that but I think it'd cause regressions if other components are assuming the visibility to be false when back is pressed.

@tienifr
Copy link
Contributor Author

tienifr commented May 24, 2023

let's try that but I think it'd cause regressions if other components are assuming the visibility to be false when back is pressed.

@rushatgabhane should we fix the visibility bug in other PR because it's not related to this PR?

@PauloGasparSv
Copy link
Contributor

@rushatgabhane should we fix the visibility bug in other PR because it's not related to this PR?

I think we should try here as @rushatgabhane said!

@tienifr I also think we should treat this as related to the bug since we'll introduce the problem in this P.R. : /

Can we attempt that fix you proposed?
I'm confused on when shouldGoBack would be set to false in that logic and if it would cause regressions so I think we should try and test : )

@tienifr
Copy link
Contributor Author

tienifr commented May 24, 2023

@rushatgabhane @PauloGasparSv I've updated my PR.
Sorry for this solution: #17649 (comment)
It doesn't work because onBackButtonPress is different from the one in HeaderView

I found out that we can lean on navigationRef.current.getState().index if it's 0, the modal is shown otherwise the modal is hidden.

 if (this.props.shouldSetModalVisibility && !navigationRef.current.getState().index) {
            Modal.setModalVisibility(false);
        }

Additional solution

We can use the following code in Navigation.js

navigationRef.current.addListener('state',(e)=>{
            if(e.data.state.index){
// set isVisible = true
}else{
// set isVisible = false
}
})

I tested many cases and there's no regression, but we should double check. Thanks

@rushatgabhane
Copy link
Member

navigationRef.current.getState().index if it's 0, the modal

I don't think that's reliable enough. Because it's the index of focused route in the routes array.

https://reactnavigation.org/docs/navigation-state/#:~:text=index%20%2D%20Index%20of%20the%20focused%20route%20object%20in%20the%20routes%20array

@tienifr
Copy link
Contributor Author

tienifr commented May 26, 2023

@rushatgabhane After checking our App, I can't find any cases that the index === 0 but the modal is still open. Can you help find this case? Or do you have any suggestions? Thanks so much

@rushatgabhane
Copy link
Member

I can't find any cases that the index === 0 but the modal is still open

thing is, in future it could.
Because the docs suggest that routes array is - "List of route objects (screens) which are rendered in the navigator. It also represents the history in a stack navigator. There should be at least one item present in this array"

I think it's a workaround for finding if a modal is open.

@tienifr
Copy link
Contributor Author

tienifr commented May 29, 2023

I spend much time, but I can't find the best solution, it can cause regression some where. Can you give me any advices? Thanks @rushatgabhane @PauloGasparSv

@rushatgabhane
Copy link
Member

rushatgabhane commented May 30, 2023

Okayy, I'll try to work on this today.
Appreciate the effort and time you've spent on this issue @tienifr

@PauloGasparSv
Copy link
Contributor

Will investigate tomorrow : )

@PauloGasparSv
Copy link
Contributor

PauloGasparSv commented Jun 2, 2023

Will investigate tomorrow : )

I'll actually have time for this today, couldn't focus on this at all this week. @rushatgabhane do you have any updates on your side?

@PauloGasparSv
Copy link
Contributor

Bump @rushatgabhane

@rushatgabhane
Copy link
Member

Hi, sorry I had looked into this but didn't find anything. I was out sick and I can't prioritize it right now.
What should we do?

@PauloGasparSv
Copy link
Contributor

Hi, sorry I had looked into this but didn't find anything. I was out sick and I can't prioritize it right now.
What should we do?

Sorry for the delay and sorry to hear that @rushatgabhane, hope you are feeling better!

Should I re-assign a new C+ member to this issue/P.R.?

@rushatgabhane
Copy link
Member

@PauloGasparSv yes please could you reassign it to another c+

@Santhosh-Sellavel
Copy link
Collaborator

@tienifr Please resolve conflicts.

@Santhosh-Sellavel
Copy link
Collaborator

Let's close this PR @tienifr thanks!

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.

6 participants