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 compose box resurfacing issue #9060

Merged
merged 18 commits into from
Jun 7, 2022
Merged

Fix compose box resurfacing issue #9060

merged 18 commits into from
Jun 7, 2022

Conversation

marcaaron
Copy link
Contributor

@marcaaron marcaaron commented May 17, 2022

Details

Fixed Issues

$ #9016

Tests & QA (On a mobile device or mWeb only)

  1. Edit a message
  2. Verify the "compose" input at the bottom hides
  3. Blur the input by navigating away or tapping somewhere else
  4. Verify the compose input at the bottom reappears
  • Verify that no errors appear in the JS console

PR Review Checklist

PR Reviewer Checklist

  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • 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 verified proper code patterns were followed (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 was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by tagging the marketing team 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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • 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
  • 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 */
    • Any functional components have the displayName property
    • 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 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.

Screenshots

Web

❌ - Change doesn't affect web

Mobile Web

Mobile web is working - but looks kind of inconsistent on iOS simulator. We should probably create some follow up issues for these bugs if they are not being worked...

  1. There's some weird extra whitespace (maybe dev only)
  2. Scrolling up to the comment isn't working (probably because scrollToIndex / comment linking doesn't work on web)
2022-05-20_08-47-19.mp4

Desktop

❌ - Change doesn't affect desktop

iOS

2022-05-18_14-12-08.mp4

Android

2022-05-20_08-18-44.mp4

@marcaaron marcaaron self-assigned this May 17, 2022
@marcaaron marcaaron changed the title Fix compose box resurfacing issue [WIP] Fix compose box resurfacing issue May 18, 2022
@marcaaron
Copy link
Contributor Author

Found a solution for web and mobile web (the edit comment feature needs improvement there) and still need to test iOS/Android.

@marcaaron marcaaron changed the title [WIP] Fix compose box resurfacing issue Fix compose box resurfacing issue May 20, 2022
@marcaaron marcaaron marked this pull request as ready for review May 20, 2022 19:06
@marcaaron marcaaron requested a review from a team as a code owner May 20, 2022 19:06
@melvin-bot melvin-bot bot requested review from Gonals and removed request for a team May 20, 2022 19:06
@marcaaron marcaaron requested a review from Beamanator May 25, 2022 17:08
Gonals
Gonals previously approved these changes May 26, 2022
Copy link
Contributor

@Gonals Gonals left a comment

Choose a reason for hiding this comment

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

LGTM!

@parasharrajat
Copy link
Member

Testing...

Copy link
Member

@parasharrajat parasharrajat left a comment

Choose a reason for hiding this comment

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

BUG: Composer stays hidden on switching the chats.
Steps:

  1. Open any chat on Android.
  2. Edit any message.
  3. Click hardware back button.
  4. Open any other chat.
  5. No Composer.

I was doing this #8255 to solve it.

onPress={this.publishDraft}
onPress={() => {
this.publishDraft();
toggleReportActionComposeView(true, VirtualKeyboard.shouldAssumeIsOpen());
Copy link
Member

Choose a reason for hiding this comment

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

This is indirectly happening on publishDraft => deleteDraft

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not following. What is happening exactly?

Copy link
Member

Choose a reason for hiding this comment

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

I meant that this is already being called in publishDraft. So this call is a duplicate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it tried to remove it. Let me know if you see any issues? Tested Android and it worked well.

@@ -210,6 +210,14 @@ class ReportActionItemMessageEdit extends React.Component {
ReportScrollManager.scrollToIndex({animated: true, index: this.props.index}, true);
toggleReportActionComposeView(false, VirtualKeyboard.shouldAssumeIsOpen());
}}
onBlur={(event) => {
// Return to prevent re-render when save button is pressed which cancels the onPress event by re-rendering
if (lodashGet(event, 'nativeEvent.relatedTarget.id') === 'saveButton') {
Copy link
Member

Choose a reason for hiding this comment

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

Should we move saveButton to CONST? may be not. As this would be local to the component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, maybe it can be private to this file, but agree makes sense as a variable.

@marcaaron
Copy link
Contributor Author

@parasharrajat Thanks! And that's interesting so... the hardware back button is not causing the input to lose focus? I'll do some testing now and see.

@marcaaron
Copy link
Contributor Author

Ah ok so revealing the sidebar does not blur the input. The solution you shared only works if the ReportScreen unmounts and that doesn't happen when we navigate to the same chat. Maybe we can move the reset into the componentDidUpdate() of ReportActionsView 🤔

@parasharrajat
Copy link
Member

Maybe we can move the reset into the componentDidUpdate() of ReportActionsView

Sounds like a potential solution. I will test more on other platforms to see if there are other such cases.

@parasharrajat
Copy link
Member

parasharrajat commented May 27, 2022

Please merge main. There are conflicts.

@marcaaron
Copy link
Contributor Author

Updated. Best solution I could come up with is to reset the composer whenever we set the currently viewed reportID. Which happens whenever we mount a new report screen or update the reportID.

@parasharrajat
Copy link
Member

Thanks,I have fixed my Mac. I will review this shortly and we can close this.

@parasharrajat
Copy link
Member

There are definitely some weird things happening when we are navigating back with the browser in mWeb. Mostly I am confused why we end up navigating to a previous chat instead of showing the drawer. The behavior seems kind of unexpected.

This happening as there is no back handler for mWeb like native. Pressing the back button navigates the page back to previous history item.

As the url is always r/reportID for both open/closed state. previous history item will always be r/reporid for another report. Thus it switch to another report on pressing back. The default status of Drawer is closed thus we see LHN with respect to change of report.

[BackHandler](https://github.com/necolas/react-native-web/blob/master/packages/react-native-web/src/exports/BackHandler/index.js.) is not implemented on RN-web There is a good reason for that but I am not able to find the issue where maintainer explained it.

"integrity": "sha512-goW1b+d9q/HIwbVYZzZ6SsTr4IgE+WA44A0GmPIQstuOrgsFcT7VEJ48nmr9GaRtNu0XTKacFLGnBPAM6Afouw==",
"integrity": "sha1-1TswzfkxPf+33JoNR3CWqm0UXFA=",
Copy link
Member

Choose a reason for hiding this comment

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

This is strange change. I think you need to update your npm v6 to latest minor version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why?

Copy link
Member

@parasharrajat parasharrajat Jun 1, 2022

Choose a reason for hiding this comment

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

This is unnecessary change for this PR. I also got the same in one of the PR and then upgrading to latest v6 of npm fixed it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah hmm looks like someone already updated expensify-common then we don't need it.

@marcaaron
Copy link
Contributor Author

This happening as there is no back handler for mWeb like native. Pressing the back button navigates the page back to previous history item.

Yes am aware of an open issue in react-native-web to implement the BackHandler and also some issues that react-navigation has related to browser back nav on web (it's using popstate events not the BackHandler and also has a specific implementation for web).

I think it could also have to do with the CustomActions stuff. Probably eventually would be good to:

  • Determine how browser navigation should work
  • See if react-navigation can reasonable support what we want
  • If not, then re-write the CustomActions or create a custom navigator for web
  • If yes, then kill the CustomActions

That all has to be designed and researched though and probably not a near-term priority.

parasharrajat
parasharrajat previously approved these changes Jun 1, 2022
Copy link
Member

@parasharrajat parasharrajat left a comment

Choose a reason for hiding this comment

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

Rest changes looking good to me. Thanks for fixing the issue.

I agree, the back handler issue needs a proper discussion and analysis.

Reiterating issues that we ignored on this PR:

  1. ScrollToBottom does not work on mWeb.

cc: @Beamanator

@marcaaron
Copy link
Contributor Author

Yes, I think scrolling to the comment will not work until we solve the same issues we are struggling with here.

@marcaaron
Copy link
Contributor Author

@Gonals Can you give this another quick look whenever you get a chance? 🙇

package-lock.json Outdated Show resolved Hide resolved
Copy link
Contributor

@Gonals Gonals left a comment

Choose a reason for hiding this comment

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

Tested well!

@Gonals
Copy link
Contributor

Gonals commented Jun 7, 2022

@Beamanator all yours!

Copy link
Contributor

@Beamanator Beamanator left a comment

Choose a reason for hiding this comment

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

Interesting situation happening here in Android app. Steps:

  1. Edit comment
  2. Start adding emojis
  3. In background, see that chats move up
  4. Dismiss emoji picker
  5. See that Report Action Compose is visible, but hides automatically

Note: I also reproduced on iOS, but the iOS simulator is much quicker and the ReportActionCompose component hides much quicker

Screen.Recording.2022-06-07.at.9.59.14.AM.mov

@@ -77,7 +78,7 @@ function isSingleEmoji(message) {
* @returns {Boolean}
*/
function containsOnlyEmojis(message) {
const trimmedMessage = message.replace(/ /g, '').replaceAll('\n', '');
const trimmedMessage = Str.replaceAll(message.replace(/ /g, ''), '\n', '');
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB; If .replaceAll is a native JS function (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll) why do we prefer using a lib for it here?

Also, .replace(/ /g, '') is basically another .replaceAll(message, ' ', '') so why not replace that one too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's poly-filled and not available on some mobile browsers

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool ya makes sense

Any thoughts on my second comment?

Also, .replace(/ /g, '') is basically another .replaceAll(message, ' ', '') so why not replace that one too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mostly added this to fix a bad crash with iOS 14 so that wasn't my priority. We could change the usages, but that doesn't stop people from making this mistake in the future. I also added an eslint rule to prevent people from using string.prototype.replaceAll.

src/pages/home/ReportScreen.js Show resolved Hide resolved
src/pages/home/report/ReportActionCompose.js Show resolved Hide resolved
@@ -1,3 +1,4 @@
import lodashGet from 'lodash/get';
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: Interested in using lodashGet in some other places in this component?

Ex:

this.debouncedSaveDraft(this.props.action.message[0].html);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not in this PR unless that code is being modified already. My usual preference is to only make the changes that are necessary.

@@ -1,6 +1,6 @@
import * as Session from '../actions/Session';

export default (shouldShowComposeInput, isSmallScreenWidth) => {
export default (shouldShowComposeInput, isSmallScreenWidth = true) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking out loud: index.js is for web & mobile (since we have a index.native.js file) so... should this default to false, not small screen width?

Thought about this lib name: This isn't really "toggling" anything, is it? It's just setting Session.setShouldShowComposeInput based on whatever is passed... Maybe it's due for a rename

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I don't really understand this concern. Are you seeing a bug somewhere or something that needs to be addressed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope, no bug - this is related to my other 2 comments about web & desktop probably usually not being small screens, so it's weird to me that we default isSmallScreenWidth to true here.

Again, not a blocker & doesn't need to be changed until we see a bug somewhere so can resolve this

@Beamanator
Copy link
Contributor

Also seeing this in iOS following this flow:

  1. Send message, start editing (without sending)
  2. Verify ReportActionCompose hides
  3. Navigate away, then navigate back
  4. See that the comment edit input & report action compose input both show
Screen.Recording.2022-06-07.at.10.55.24.AM.mov

@marcaaron
Copy link
Contributor Author

See that the comment edit input & report action compose input both show

Yes, that is the expected behavior.

@marcaaron
Copy link
Contributor Author

Hey @Beamanator - good thoughts here and thanks for the review. Nothing is a blocker for me and it's important to get this one merged. If you are passionate about any of the concerns you had in the review I think we can create a follow up to address them.

@marcaaron marcaaron merged commit 1af9250 into main Jun 7, 2022
@marcaaron marcaaron deleted the marcaaron-fixComposeBox branch June 7, 2022 17:04
@OSBotify
Copy link
Contributor

OSBotify commented Jun 7, 2022

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

OSBotify commented Jun 8, 2022

🚀 Deployed to staging by @marcaaron in version: 1.1.74-0 🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 failure ❌
🍎 iOS 🍎 cancelled 🔪
🕸 web 🕸 failure ❌

@OSBotify
Copy link
Contributor

OSBotify commented Jun 9, 2022

🚀 Deployed to production by @yuwenmemon in version: 1.1.74-2 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Comment on lines +215 to +222
onBlur={(event) => {
// Return to prevent re-render when save/cancel button is pressed which cancels the onPress event by re-rendering
if (_.contains([this.saveButtonID, this.cancelButtonID], lodashGet(event, 'nativeEvent.relatedTarget.id'))) {
return;
}

toggleReportActionComposeView(true, VirtualKeyboard.shouldAssumeIsOpen());
}}
Copy link
Member

@parasharrajat parasharrajat Jul 18, 2022

Choose a reason for hiding this comment

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

@marcaaron Could you please help me understand this change? It has caused an issue #9252 and I am trying to figure out what is it doing? Especially What do I need to test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What are you curious about exactly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Want to maybe walk me through what you think it's doing?

Copy link
Member

Choose a reason for hiding this comment

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

So it is checking that if the Cancel or save button is clicked on the Editor, return, otherwise show the composer.

So do we want to show the composer on blur?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IIRC, in this case we are ignoring the blur event because when we are blurring because the cancel or save button is clicked the method to toggle the composer (toggleReportActionComposeView) would prevent the user from taking the actions. I assumed here (perhaps incorrectly) that it is related to re-rendering of the component - but the onPress method for the buttons never seemed to run. Let me know if that helps!

Copy link
Member

Choose a reason for hiding this comment

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

Got, It. Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

Do we want to show the composer on blur?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes on blur and it should happen when we save changes or cancel the edit right? Can we have this conversation on whatever issue you are working on so I can get more insight into what you're trying to figure out?

This comment was marked as off-topic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please bring whatever conversation you'd like to have to a relevant issue.

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