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

[Popover] Fix bad positioning on IOS devices #4638

Merged
merged 7 commits into from
Dec 15, 2016

Conversation

w01fgang
Copy link

@w01fgang w01fgang commented Jul 6, 2016

Adds a device detection helper, maybe useful for cross-browser compatibility and fixes #3638

  • PR is linted.
  • Commit and PR titles begin with [ComponentName], and are in imperative form: "[Component] Fix leaky abstraction".
  • Description explains the issue / use-case resolved, and auto-closes the related issue(s) (http://tr.im/vFqem).

@igorbt
Copy link
Contributor

igorbt commented Aug 12, 2016

@w01fgang we had the same problem, but we fixed it differently, we replaced position fixed with position absolute. Keeping it to position fixed results in uncontrollable animations. I will come back later with more info.

@igorbt
Copy link
Contributor

igorbt commented Aug 12, 2016

In short, iOS renders fixed positioned elements as absolute when keyboard opens, but this "transition" from fixed to absolute is weirdly and uncontrollable animated and this results in flickering. For our project, the only good solution was to not use position fixed at all. So, both Popover and RenderToLayer should use position absolute instead of fixed. I will come back next week with a PR with the change I described.

@w01fgang
Copy link
Author

w01fgang commented Aug 14, 2016

@igorbt when you will make your PR, please let me know.

@Taakn
Copy link

Taakn commented Oct 11, 2016

@igorbt Did you end up merging anything? Your original fix worked for me @w01fgang

@muibot muibot added PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI PR: Needs Review and removed PR: Needs Review labels Nov 13, 2016
@w01fgang
Copy link
Author

Actually I don't know why test fails on src/utils/withWidth.js, I didn't make any changes there.

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

Wow, that bug is quite embarrassing on iOS devices!


describe('Device detection helper', () => {
before(() => {
global.window = {
Copy link
Member

Choose a reason for hiding this comment

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

Actually I don't know why test fails on src/utils/withWidth.js, I didn't make any changes there.

Yes, you have.

Copy link
Author

Choose a reason for hiding this comment

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

Ho, I forgot it, will fix it now.

@@ -0,0 +1,69 @@
/**
* Returns an object with detected device and browser.
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure we need this all browser device detection code for iOS.
It could be as simple as:

    // iOS detection from: http://stackoverflow.com/a/9039885/177710
    if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
        return "iOS";
    }

Copy link
Author

Choose a reason for hiding this comment

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

Yes, if we don't have any crossbrowser bugs in other components, it must be simple.

* layer, which will prevent clicks to the underlying
* elements, and trigger an `onRequestClose('clickAway')` call.
*/
* If true, the popover will render on top of an invisible
Copy link
Member

Choose a reason for hiding this comment

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

We have some indent issue here.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, I'll fix it.

@oliviertassinari oliviertassinari added the PR: out-of-date The pull request has merge conflicts and can't be merged label Nov 27, 2016
@muibot muibot added PR: Needs Review and removed PR: out-of-date The pull request has merge conflicts and can't be merged labels Nov 27, 2016
@w01fgang
Copy link
Author

@oliviertassinari please take a look.

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

We are almost there. Sorry for taking so long to review this PR.
It would also be great to rebase it on master and to squash down the commits (28).

@@ -240,7 +242,11 @@ class Popover extends Component {
};

a.right = rect.right || a.left + a.width;
a.bottom = rect.bottom || a.top + a.height;
if (/iPad|iPhone|iPod/.test(window.navigator.userAgent) && !window.MSStream) {
Copy link
Member

Choose a reason for hiding this comment

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

Still, I would move this logic into it's own module so we can test it 👼 .

Copy link
Author

Choose a reason for hiding this comment

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

Moved out to utils.

@muibot muibot added PR: out-of-date The pull request has merge conflicts and can't be merged PR: Needs Review and removed PR: Needs Review PR: out-of-date The pull request has merge conflicts and can't be merged labels Nov 27, 2016
@muibot muibot added PR: out-of-date The pull request has merge conflicts and can't be merged PR: Needs Review and removed PR: Needs Review PR: out-of-date The pull request has merge conflicts and can't be merged labels Nov 27, 2016
@oliviertassinari
Copy link
Member

It seems that the proposed fix (#4638) is only working fine in that context but breaking the others.

Following my comment, here is an example of broken context.

dec -10-2016 20-24-37
The Popover should be under the button, where more space is available.
I'm not sure we should push that PR path forward.

@w01fgang
Copy link
Author

w01fgang commented Dec 10, 2016

Yes, it might be, because the PR have been made for 0.14.x version or maybe 0.13.x.
In the 0.16.x it breaks some things, so I need some time to check it out.

@oliviertassinari
Copy link
Member

Yes, it might be, because the PR have been made for 0.14.x version or maybe 0.13.x.

Sorry for taking so long to review that PR. Thanks for digging into that issue.

@w01fgang
Copy link
Author

I checked it out. Now fix works only if input field in the focus.

@@ -240,7 +241,11 @@ class Popover extends Component {
};

a.right = rect.right || a.left + a.width;
a.bottom = rect.bottom || a.top + a.height;
if (isIOS() && document.activeElement.tagName === 'INPUT') {
Copy link
Member

Choose a reason for hiding this comment

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

Side node, with the next branch we would be using activeElement

@oliviertassinari oliviertassinari added PR: Review Accepted and removed PR: Needs Review PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Dec 15, 2016
@oliviertassinari
Copy link
Member

I confirm, it's working great now. I'm gonna add some comments in the source code. Thanks 👍 !

@oliviertassinari oliviertassinari merged commit ef384ac into mui:master Dec 15, 2016
@w01fgang w01fgang deleted the fixPopoverIOS branch December 18, 2016 13:25
@stas-lesiuk
Copy link

@w01fgang, on on 10 Dec 2016 you wrote:

Yes, it might be, because the PR have been made for 0.14.x version or maybe 0.13.x.
In the 0.16.x it breaks some things, so I need some time to check it out.

How does the situation looks like now? Is the fix merged to v0.16+ as well, or is it only on versions up to 0.14? Asking because I have a similar problem, not with the Autocomplete, but with an IconMenu popover on iOS devices. I'm using v0.16.7, but I've tested it on 0.20 and the issue is present there as well.

@w01fgang
Copy link
Author

w01fgang commented Jan 4, 2018

@stas-lesiuk on IOS before the version 11 CSS rule position: fixed counts from the top of the page, but from IOS 11 it works like it should work: from the top of the screen.
In this fix, we determine if the client's devise is IOS, but now we also should know the version to make this fix work.

@stas-lesiuk
Copy link

stas-lesiuk commented Jan 8, 2018

@w01fgang thanks for your help.
I have tried to copy Popover.js and IconMenu.js, and modify line:
if ((0, _iOSHelpers.isIOS)() && document.activeElement.tagName === 'INPUT') {
to
if ((0, () => true)() && document.activeElement.tagName === 'INPUT') {
and
if ((0, () => true)() && document.activeElement.tagName === 'INPUT') {

and unfortunately it seems that independently from the if statement result, there's still a problem with IconMenu Popover position on iOS devices. It looks like that's not the same issue like the initially addressed by you, however I wonder whether you may know the possible solution.
The difference seems to be that the issue appears only after zoom (screenshots attached), initially context menu position is right - it's next to menu, but the bigger zoom is the bigger distance becomes.

initial image, no zoom

wrong ios position after zoom

@quorak
Copy link

quorak commented Jan 20, 2018

hey there. Do you have any plans on releasing this? The fix is not in the current v0.20 is it? thanks a lot

@mbrookes
Copy link
Member

@quorak This PR was merged in Dec 2016!

@quorak
Copy link

quorak commented Jan 20, 2018

yeah, it was merged on Dec 16th .
But last stable release v0.20 seems to be from Dec 4th , if I'm not mistaken.
https://github.com/mui-org/material-ui/tree/v0.20.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: Popover The React component.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants