-
Notifications
You must be signed in to change notification settings - Fork 3k
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: add a timeout on PressableWithFeedback for disable removal #18865
Conversation
@roryabraham @s77rt 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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the problem with this implementation is that it doesn't actually disable the Pressable
until after 1000ms, which is not what we want. We just want to prevent the disabled cursor style from showing until the Pressable
has been disabled for 1000ms.
Also, it currently is only delaying the Pressable
from being re-enabled, which we agreed we didn't want to do at all.
Something like this is more like what I had in mind (in BaseGenericPressable
):
const isDisabled = useMemo(() => {
let shouldBeDisabledByScreenReader = false;
if (enableInScreenReaderStates === CONST.SCREEN_READER_STATES.ACTIVE) {
shouldBeDisabledByScreenReader = !isScreenReaderActive;
}
if (enableInScreenReaderStates === CONST.SCREEN_READER_STATES.DISABLED) {
shouldBeDisabledByScreenReader = isScreenReaderActive;
}
return props.disabled || shouldBeDisabledByScreenReader;
}, [isScreenReaderActive, enableInScreenReaderStates, props.disabled]);
const [shouldUseDisabledCursor, setShouldUseDisabledCursor] = useState(isDisabled);
useEffect(() => {
if (!isDisabled) {
setShouldUseDisabledCursor(isDisabled);
} else {
setTimeout(() => setShouldUseDisabledCursor(isDisabled), 1000);
}
}, [isDisabled]);
...
...
getCursorStyle(shouldUseDisabledCursor, [props.accessibilityRole, props.role].includes('text')),
c457c82
to
1cf0c12
Compare
@roryabraham Handled your comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this solution is working. We basically disabled the "disabled cursor". This is because the useEffect
will run after the click event is already handled.
@s77rt I think this is what is intended. As far as I've understood, we need to show the disabled cursor AFTER 1s timeout. We don't need to add a timeout to the disabled state itself. |
@allroundexperts What I meant is that the cursor won't show even if the button remains disabled for more than 1s. The timer won't even start. |
That's weird. Checkout the second video I attached for Web. It seems to be getting triggered fine. I made the |
It will only work if the If the callback is sync. We will first do the sync work (keep cursor in normal state - even if the work is taking more than 1sec) and then call the |
Nice finding. I'll try to come up with a solution that works for sync code as well. As a side note, do we have any sync action that usually takes more than a second 🤔? |
I'm not totally sure. Seems like an edge case so maybe we can have the disabled cursor just for the async work. |
@roryabraham Can you confirm if that is a reasonable assumption? |
@s77rt I think this is a reasonable assumption. If a Screen.Recording.2023-05-13.at.6.50.50.PM.mov |
Yeah I think you are right. |
.then(() => { | ||
setDisabled(props.disabled); | ||
}) | ||
.catch(() => setDisabled(props.disabled)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this is required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
During my testing, I found that the button would be stuck in a disabled state if the promise failed. This resets the button so that the user can continue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you pinpoint to any real case that I can reproduce?
Also if that's the case we should just use finally
instead of then & catch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It really depends on the onPress
function being supplied. And yea, finally
looks good.
useEffect(() => { | ||
let timer = null; | ||
if (!isDisabled) { | ||
setShouldUseDisabledCursor(false); | ||
} else { | ||
timer = setTimeout(() => setShouldUseDisabledCursor(true), 1000); | ||
} | ||
onPressHandler(event); | ||
}, [onPressHandler]); | ||
|
||
return () => { | ||
if (!timer) return; | ||
clearTimeout(timer); | ||
}; | ||
}, [isDisabled]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make the cleanup function only if isDisabled is true.
useEffect(() => {
if (isDisabled) {
const timer = setTimeout(() => setShouldUseDisabledCursor(true), 1000);
return () => clearTimeout(timer);
}
setShouldUseDisabledCursor(false);
}, [isDisabled]);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
.then(() => { | ||
setDisabled(props.disabled); | ||
}) | ||
.catch(() => setDisabled(props.disabled)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you pinpoint to any real case that I can reproduce?
Also if that's the case we should just use finally
instead of then & catch.
BTW; the diff looks to be a lot. Is this caused by prettier? Can you fix that? |
Merged with latest and fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good. But the PR details / tests are not correct. Please update.
@s77rt I've updated the steps. However, I'm unsure how to test the actual cursor getting disabled after 1s since none of the actions in our app takes this long. Do you have any idea of how we should deal with this? |
@allroundexperts Just test against this case #17103 (comment) |
@s77rt I've mentioned a similar case in the tests section of my proposal. |
Reviewer Checklist
Screenshots/VideosWebweb.mp4Mobile Web - Chromemweb-chrome.mp4Mobile Web - Safarimweb-safari.mp4Desktopdesktop.mp4iOSios.mp4Androidandroid.mp4 |
@allroundexperts Almost ready 😁 Can you please remove the old videos as they may be confusing since the disabled cursor is visible on those. |
@s77rt If you are talking about the videos in |
@allroundexperts Yeah but the 2s promise is not on staging so it's hard for the QA team to test this and it may be confusing. |
Makes sense. Removing that one. |
@s77rt Removed on web and desktop. |
@allroundexperts Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🚀
cc @roryabraham
@roryabraham This is waiting for your review. |
🚀 Deployed to staging by https://github.com/roryabraham in version: 1.3.15-0 🚀
|
@roryabraham @s77rt This issue is failing step 3 on Web and Desktop - #19137 |
I went ahead and closed that other issue. I think that it was maybe just poorly described testing steps. |
Great! Then we can check this one off from the checklist. Thanks! |
🚀 Deployed to production by https://github.com/yuwenmemon in version: 1.3.15-12 🚀
|
Details
This PR adds a delay of 1000ms in
GenericPressable
before the disabled cursor style kicks in. This is needed in order to fix the quick cursor style change that often occurs when thePressableWithFeedback
button is clicked quickly.Fixed Issues
$ #18862
PROPOSAL: #18862 (comment)
Tests
PressableWithFeedback
button (eg The submit button at the first step of the manual connect bank account page)disabled
and make sure that it does not flicker.Offline tests
N/A
QA Steps
PressableWithFeedback
button (eg The submit button at the first step of the manual connect bank account page)disabled
and make sure that it does not flicker.PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Web
Screen.Recording.2023-05-13.at.3.03.19.AM.mov
Mobile Web - Chrome
Screen.Recording.2023-05-13.at.12.58.45.AM.mov
Mobile Web - Safari
Screen.Recording.2023-05-13.at.12.55.18.AM.mov
Desktop
Screen.Recording.2023-05-13.at.3.09.15.AM.mov
iOS
Screen.Recording.2023-05-13.at.1.13.42.AM.mov
Android
Screen.Recording.2023-05-13.at.1.00.22.AM.mov