Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 7 Chrome - Fixed position drawer doesn't stay at bottom when virtual keypad pops up

I have a bottom drawer which is fix positioned at the bottom. When tapped, the drawer will slide up and show more content. On iOS 7, when user taps on input tag or textarea tag, the virtual keyboard pops up. However, the drawer jumps up on the page instead of sticking to the bottom when keypad pops up. Please see the diagram below for illustration. enter image description here

I firstly encountered the issue also on Safari, but I added the following code to change the fixed position to absolute when keypad is open:

// Apple.Device detects if it is an apple device
if (Modernizr.touch && Apple.Device) {
    /* cache dom references */ 
    var $body = jQuery('body'); 

    /* bind events */
    $(document)
    .on('focus', 'input, textarea', function(e) {
        $body.addClass('fixfixed');
    })
    .on('blur', 'input, textarea', function(e) {
        $body.removeClass('fixfixed');
    });
} 

CSS code:

.fixfixed #drawer {
    bottom: 0;
    margin-left: auto;
    margin-right: auto;
    position: absolute;
    left: 0;
    right: 0;
}

This fix works on Safari on iOS 7 but it doesn't work on Chrome. Also, there is a weired behavior:

If there is an input tag on the page and I tap on it on iPad, then the virtual keyboard opens and the drawer jumps up. If the drawer happens to then cover the I clicked on, the click event actually fires on the drawer. Why is that?

How can I resolve this issue? (I've been searching for a while but how do I debug Chrome on iOS?)

Many thanks for your help!

Update

I've used the following code to detect if it is Chrome on iOS 7, if so, I hide the Drawer when the virtual keyboard is up, and re-display the drawer when virtual keyboard is down.

function iOSversion() {
    if (/iP(hone|od|ad)/.test(navigator.platform)) {
        // supports iOS 2.0 and later: <http://bit.ly/TJjs1V>
        var v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
        return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)];
    }
}

var iosVersion = iOSversion();

if (navigator.userAgent.match('CriOS') && iosVersion[0] == '7') {
   $(document).hammer().on('tap', 'input, textarea', function(e) {
            $('body').addClass('chromefixfixed');
        })
            .on('blur', 'input, textarea', function(){
                body.removeClass('chromefixfixed');
            })
}

CSS code:

.chromefixfixed #drawer {
    display: none;
}

Still the question remains: how do I get Chrome on iOS 7 to work like Chrome on Android (without hiding the drawer when keyboard is up)?

Thanks for the help!

like image 438
Yunzhou Avatar asked Oct 28 '13 09:10

Yunzhou


People also ask

What's wrong with iOS 6 virtual keyboard?

And this caveats are still there in iOS 6. Another thing that annoys me comes to play when the virtual keyboard displays, e.g. focus of an input element. Somehow fixed positioned elements lose their position, hang somewhere on the page and hide other elements.

Why does iOS Safari jump to the top of the page?

I wrote a new post about iOS Safari jumps to the top of the page when form elements inside fixed positioned divs receive input. Fixed positioned layout and content scrolling support arrived to MobileSafari with the release of iOS 5.

Are there any iOS apps with fixed position toolbars?

However, there's an increasing number of iOS apps I've noticed that are actually just a collection of WebViews (mini-MobileSafaris) with fixed position toolbars as seen in Apple's own AppStore app, the native Facebook app and Instagram below:

Did Apple just half arsed-Ed-ly fix the position-fixed issue?

It's a huge headache that Apple have half arsed-ed-ly fixed the position:fixed issue and done in a typically Microsoft proprietory way. Published 24-May 2012 under #apple & #css & #ios & #iphone & #web.


1 Answers

Position fixed bottom and position absolute bottom are an absolute nightmare on iOS and android devices, in my experience it's just not possible to get it to render consistently even across the most modern devices, let alone the older ones that dominate the market currently. So much so, that as a dev I would ask a designer to rethink the layout because of it. I believe it's called "sidestepping the turd".

like image 50
Edd Smith Avatar answered Oct 22 '22 02:10

Edd Smith