-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
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
[Overlay] Split out AutoLockScrolling #3690
Conversation
This is very interesting 👍 👍 |
} | ||
} | ||
|
||
_preventScrolling() { |
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 we remove the _
from our methods and properties?
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.
done
There are issues with AutoLockScrolling in the current implementation with nested dialogs, when they unmount out of order. This component doesn't make it better or worse, but would be great to consider it as well when thinking about this. |
@chrismcv tried a fix :) |
58c4803
to
a9e8786
Compare
gentle ping :) |
@chrismcv Is right, the This really remembers me issues with concurrent access to resources like memory in a multi-thread environment. What do you think about using a semaphore? |
@cgestes What do you think about just extracting the |
That's really interesting 👍 I think it's the best approach. just keep an integer ( increment with mount decrement with unmount ) and then set with non-zero and set with zero 👍 |
@alitaheri & @oliviertassinari I did not know the locker was not supposed to be the unlocker. Will implement it with a counter, thanks for the idea :) |
sorry - been a busy day... I agree, in that I don't think the suggested fix would work. In my head, moving the lock variable outside the component |
a9e8786
to
03b9ce9
Compare
updated the PR with a semaphore :) |
This looks good to me :) |
Reviewing the commit again... I dont think it is... I'll add inline comments |
} | ||
|
||
allowScrolling() { | ||
lockingCounter = lockingCounter - 1; |
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.
we should decrement only if we incremented.
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 have a bad feeling that if we switch the lock property on/off while the component is mounted it might go wrong. not sure.
I have a plane to take, so I'll have to check it again carefully later.
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? I can't see a problem with always incrementing?
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 fear that we can double increment while decrementing only once. or the reverse.
I'll add an extra security. I believe if we have lock = false we decrease the counter without having incremented it. Please dont merge now. |
03b9ce9
to
0b79dca
Compare
I believe this time everything is ok. It will only unlock if it has been locked. What do you think? |
0b79dca
to
4972513
Compare
I'm having a new look at this PR. Can we add some unit test to this component? |
4972513
to
b59350b
Compare
from what I understand we do.
and better be safe when we play with a global semaphore. |
The code is not gonna evolve a lot. it's just a simple component doing one thing with no possible side effect. I'll try to add some when I'll come back from ski in 10 days. I'am not sure how to do unittest which have impact on the DOM. |
@cgestes Enjoy ❄️! |
b59350b
to
23eceb4
Compare
rebased :) |
@cgestes Looks like rebasing went a bit haywire, can you try again? |
23eceb4
to
9e0a915
Compare
fixed. sorry for the inconvenient. |
@cgestes That seems to work correctly 👍. I'm fine with merging this PR.
|
@@ -131,7 +94,9 @@ const Overlay = React.createClass({ | |||
const styles = getStyles(this.props, this.state); | |||
|
|||
return ( | |||
<div {...other} ref="overlay" style={prepareStyles(Object.assign(styles.root, style))} /> | |||
<div {...other} ref="overlay" style={prepareStyles(Object.assign(styles.root, style))}> | |||
{this.props.autoLockScrolling && <AutoLockScrolling lock={this.props.show} />} |
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.
The show
variable is already destructured. We can use it. It would be good to do the same with autoLockScrolling
.
{autoLockScrolling && <AutoLockScrolling lock={show} />}
this.locked is extra safety and code readability. For example when you mount with lock=false and you unmount this ensure that the counter is not decremented. |
9e0a915
to
b84ffa5
Compare
rebased on @mbrookes changes :) |
b84ffa5
to
da9009a
Compare
second rebase done :) |
One component, one feature.
AutoLockScrolling is useful on it's own.