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

Orientation fix for mobile #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/containers/Orientation.js
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" ||
Copy link
Owner

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.

Copy link
Author

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 😅

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Owner

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?

Copy link
Author

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?

Copy link
Owner

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 the RotateInfo 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!

Copy link
Owner

Choose a reason for hiding this comment

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

Any advance on this?

Copy link
Author

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.

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;
Copy link
Owner

Choose a reason for hiding this comment

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

We should replace window.screen.orientation with something else since it's not fully supported yet by all browsers

Copy link
Author

Choose a reason for hiding this comment

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

I agree, will look into this

Copy link
Author

Choose a reason for hiding this comment

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

}
};

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() {
Expand Down