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

#316 Fix cursor visibility on monitor fullscreen view #319

Closed
wants to merge 3 commits into from
Closed

#316 Fix cursor visibility on monitor fullscreen view #319

wants to merge 3 commits into from

Conversation

cksharma11
Copy link

Fixes issue #316

@build-canaries/owners

@GentlemanHal
Copy link
Member

Hi @cksharma11, thanks for submitting this PR!

Unfortunately it isn't quite as simple this. Your change will always show the mouse cursor while in full screen. However the desired behaviour is for the mouse cursor to be hidden until the mouse is moved when in fullscreen.

Which I'm now realising isn't quite as simple as I first thought. Adding a class when the mouse moves is simple, but removing it is a little more complicated (without duplicating the logic used by the fullscreen hook) 🤔

@cksharma11
Copy link
Author

cksharma11 commented Oct 9, 2020

@GentlemanHal Ahh. Just realised that, will work on fixing the same.

@cksharma11
Copy link
Author

@GentlemanHal Updated the PR.

Thought, I'm not sure if that's the correct way to do this?

const monitorClassNames = cn(styles.monitor, {
[styles.fullscreen]: fullScreen
})
document.onmousemove = () => {
Copy link
Member

Choose a reason for hiding this comment

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

Using document.onmousemove is bad, it breaks React encapsulation meaning the handler isn't going to be cleaned up when the component unmounts. Which means a ton of warnings would be generated on every other page as you'd be trying to update state on an unmounted component!

@@ -33,6 +33,11 @@ export function Monitor({fullScreen, requestFullScreen}: MonitorProps): ReactEle

const [loaded, setLoaded] = useState(false)
const [projects, setProjects] = useState<Projects>([])
const [monitorClassNames, setMonitorClassNames] = useState({
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to store all of this as state. You only really need to keep track of the inactive boolean. Also doing this means the fullscreen style will never get toggled, as the state is only initialised on the first render using the fullscreen boolean.

})
document.onmousemove = () => {
setMonitorClassNames({
...monitorClassNames, [styles.inactive]: false
Copy link
Member

Choose a reason for hiding this comment

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

Nothing is ever setting the inactive style back to true, so once the mouse is moved the mouse cursor will never be hidden again.

@GentlemanHal
Copy link
Member

Thought, I'm not sure if that's the correct way to do this?

Thanks for updating the PR, but unfortunately not. I've added some comments directly to the code, as hopefully that's easier to explain some of the issues.

@GentlemanHal
Copy link
Member

I'm going to close this pull request, the code isn't mergeable and the underlying issue is more complicated than I realised. Sorry for wasting your time by incorrectly labelling the original 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.

2 participants