-
Notifications
You must be signed in to change notification settings - Fork 2
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
Orientation fix for mobile #38
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,29 @@ | ||
import React, { Component } from "react"; | ||
import PropTypes from "prop-types"; | ||
|
||
const isMobileDevice = () => | ||
typeof window.orientation !== "undefined" || | ||
navigator.userAgent.indexOf("IEMobile") !== -1; | ||
|
||
const isLandscape = () => Math.abs(window.orientation) === 90; | ||
|
||
const orientationType = () => { | ||
if (isMobileDevice()) { | ||
return isLandscape() ? "landscape-primary" : "portrait"; | ||
} else { | ||
return window.screen.orientation.type; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should replace There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, will look into this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about this? https://polyfill.io/v2/docs/features/#screen_orientation |
||
} | ||
}; | ||
|
||
class Orientation extends Component { | ||
state = { | ||
type: "" | ||
type: orientationType() | ||
}; | ||
|
||
componentDidMount() { | ||
window.addEventListener("orientationchange", () => { | ||
this.setState({ type: window.screen.orientation.type }); | ||
this.setState({ type: orientationType() }); | ||
}); | ||
this.setState({ type: window.screen.orientation.type }); | ||
} | ||
|
||
render() { | ||
|
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'm afraid that
window.orientation
is not going to be our best friend since it's deprecated.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.
Oh wow I wasn't aware of this, I'll look for an alternative approach 😅
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.
Would this work? 🤔
https://developer.mozilla.org/en-US/docs/Web/API/Detecting_device_orientation
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 think we should re-think the solution because the device orientation stuff is kind of experimental. Basically, the idea behind the feature is to prevent the game to be rendered in small screens. We can simply do that based on the screen width and use the resize event to swap components as we currently do with the
Orientation
component. What do you think?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.
👌 makes sense, I can make those changes. Do you have a minimum width in mind?
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.
Let's show the
Game
component at minimum 542px width. Below we can just show theRotateInfo
component. Please, remember to listen to the resize event and also perform the check on mounting phase. Test your code and include yourself into the contributor's list :) Thanks again for the collaboration!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.
Any advance on this?
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.
Yo, I had a lot going on at work 😅 I'm almost done, will definitely push this week.