ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

IOS 8 Scrolling to focused input / Scrolling whilst input is focused

Open joemcelroy opened this issue 12 years ago • 31 comments

Hi there,

platform: IOS8 safari - not using the cordova-keyboard plugin as this is a mobile website Ionic: beta 12

Im getting 2 issues:

  • when the user focuses on an input, ionic scroll-view will scroll where the input is being obscured by the keyboard.
  • When the user scrolls whilst input is focused, the scrolling experience isn't great, with the top navigation disappearing.

Heres a video showing these issues: https://vid.me/nMU

Works perfectly on iOS7.

Could be related to this issue: https://github.com/driftyco/ionic/issues/2256 where now the window shifts where before it did not. Is there any way to do disableScrolling but for mobile safari?

Thanks

joemcelroy avatar Sep 24 '14 14:09 joemcelroy

I am getting the same issue. This is a web site not native so I cannot use the disable scroll keyboard plugin.

dhaligas avatar Sep 29 '14 15:09 dhaligas

i've got a code pen to show this issue in action: http://codepen.io/phoey/pen/seAkK

joemcelroy avatar Sep 29 '14 19:09 joemcelroy

Any word on this from the ionic team?

dhaligas avatar Oct 01 '14 14:10 dhaligas

Hey there guys. So since is with mobile safari and not a compiled app, there's not going to be a whole lot that we can do.

Ionic is meant for compiled hybrid apps because we have a lot more control of things. Not the case in mobile safari.

mhartington avatar Oct 01 '14 14:10 mhartington

Hey guys, i think it's the Scroll Evennt change in iOS8 Safari. (http://developer.telerik.com/featured/scroll-event-change-ios-8-big-deal/?utm_source=mobilewebweekly&utm_medium=email) - and also in the new WKWebView for cordova/phonegap

I have the same issue on my web-app in Safari.

A Workaround that helps me:

i changed in "keyboard.js"

function keyboardBrowserFocusIn(e) { if( !e.target || !ionic.tap.isTextInput(e.target) || ionic.tap.isDateInput(e.target) || !keyboardIsWithinScroll(e.target) ) return; ....

to

function keyboardBrowserFocusIn(e) { if( !e.target || keyboardActiveElement !== e.target || !ionic.tap.isTextInput(e.target) || ionic.tap.isDateInput(e.target) || !keyboardIsWithinScroll(e.target) ) return; ...

... that solves my problem

PeBu avatar Oct 03 '14 08:10 PeBu

Had same issue (compiled app, not mobile safari) and the fix from @PeBu worked for me.

xdissent avatar Oct 27 '14 20:10 xdissent

Same issue here on an iOs 8 compiled app - works fine with iOs 7.x... Seems to be a regression. The fix from @PeBu works. Any chance to have it integrated in a next ionic release ?

phil74 avatar Nov 19 '14 14:11 phil74

@PeBu fix works but then the navigation bar hide behind the status bar on a compiled app.

jfbourne avatar Dec 23 '14 15:12 jfbourne

What is the @PeBu fix?

Edit: Looks to be compiled app only, not Mobile Safari :'-(

Anyone able to help?

Thanks

ChristianBetts avatar Jan 29 '15 15:01 ChristianBetts

@ChristianBetts like I said above @PeBu fix will work but you will have the issue that your navigation bar will scroll up and hide underneath status bar when the keyboards comes up. If you have no problem with that just go into ionic\js\ionic.bundle.js and search for this line

keyboardBrowserFocusIn

then replace:

if( !e.target || !ionic.tap.isTextInput(e.target) || ionic.tap.isDateInput(e.target) || !keyboardIsWithinScroll(e.target) ) return;

with

if( !e.target || keyboardActiveElement !== e.target || !ionic.tap.isTextInput(e.target) || ionic.tap.isDateInput(e.target) || !keyboardIsWithinScroll(e.target) ) return;

MY SOLUTION:

Because I did not like the fact that the keyboard was making my nav bar to be hidden I decided to disable keyboard scrolling when entering the view with this issue and disabling keyboard scrolling when exiting that view. See example below

.state('app.help', { onEnter: function($ionicPlatform){

    $ionicPlatform.ready(function() {
      if(window.cordova ){
         cordova.plugins.Keyboard.disableScroll(true);
      }

   }); 
  },
  onExit: function($ionicPlatform){
    $ionicPlatform.ready(function() {
       if(window.cordova){
         cordova.plugins.Keyboard.disableScroll(false);

        }
    });
  }
})

jfbourne avatar Jan 29 '15 16:01 jfbourne

Hi everyone! I have the same trouble on bootstrap-based site. It would really help if someone got a solution that can be used on non-ionic website. I googled like hell but found nothing. The only info real close to my issue is the one you are talking about, but I'm not good enough in JS to dig it from ionic code. Any help would be appreciated!

evgenium avatar Apr 16 '15 16:04 evgenium

Unfortunately on Safari there is not a lot we can do to prevent the browser from automatically scrolling inputs into view. Rather than try and battle the browser on this, I've added ionic.keyboard.disable(), which will allow you to easily disable Ionic's keyboard adjustments. You can re-enable them with ionic.keyboard.enable(). If for some reason you need to disable/re-enable the keyboard code in a web view I would suggest doing each of them with cordova.plugins.Keyboard.disableScroll(false) and cordova.plugins.Keyboard.disableScroll(true), respectively.

tlancina avatar Apr 20 '15 21:04 tlancina

This seems to be working fine for me:

$scope.openPopover = function($event, id) {
    ionic.keyboard.disable();
    $scope.popovers[id].show($event); 
};

 // Execute action on hide popover
$scope.$on('popover.hidden', function() {
    ionic.keyboard.enable();
});

Thanks tlancina!

torleifs avatar Apr 29 '15 08:04 torleifs

@tlancina thank you for that hotfix...

fkukuck avatar May 01 '15 00:05 fkukuck

@torleifs .I am working on Mobile Portal and I am facing focused input / Scrolling whilst issue. I tried your code in my Portal. Error is ionic.keyboard.disable(); is not a function ? please suggest me.It is not a mobileApp.It is web application using ionic framework

smamit27 avatar May 13 '15 09:05 smamit27

In our app, we experienced the same issue. Somewhere in our codebase we found this snippet of code, removed it, and the "jerkiness" went away.

document.addEventListener('focusin', function (event) {
    if (event.target.tagName === 'INPUT') {
        document.body.scrollTop = 0;
    }
});

I suggest grepping your scripts, you may find something similar.

I expect we added this to prevent input focus from scrolling the screen. Perhaps document.body.scrollTop = 0; happened quickly enough in iOS 7 to negate the scrolling, but in iOS 8 it seems to be delayed just long enough for the whole page to shift. Guess we'll have to settle for the default OS behavior until another fix is discovered.

jacksonrayhamilton avatar Jul 08 '15 01:07 jacksonrayhamilton

Using ionic.keyboard.disable(); prevents the view's 'jerky jump' when selecting an input field, which is good, however the entire header slides up above the status bar, and creates another problem. This form/input/view/keyboard issue on IOS is pretty bad. I've tried alot of tricks to get around it, however fixing one issue leads to another.

jason-engage avatar Aug 12 '15 23:08 jason-engage

@jason-engage, assuming you're not using Cordova, have you tried setting overflow-scroll=true?

tlancina avatar Aug 13 '15 03:08 tlancina

@tlancina what do you mean not using cordova?... I'm building a cordova app. I tried adding overflow-scroll=true to my ion-content, and removed the ionic.keyboard.disable(). It also stops the jerking, however, the entire view scrolls up thru the status bar, and I lose the header. It also has at least one or two other negative side-effects. Btw, this issue is within an ion-modal-view. I've even tried setting has-bounce to false, using window.cordova.plugins.Keyboard.disableScroll(true), and calling an scrollDelegate.resize() after the keyboard shows up. Most of them either do nothing, or shift the problem to another problem.

I'm planning on packaging my codebase and reselling it in your soon-to-be-launched theme store. Perhaps you guys can look at it in person, and install it on an iPhone - this scrolling bug seems to be the last major issue it has. I should have it ready by next week, at which time I'll shoot Perry an email. Cheers

jason-engage avatar Aug 13 '15 05:08 jason-engage

@jason-engage this issue was for mobile Safari, using cordova.plugins.Keyboard.disableScroll(true) should prevent the behavior you're seeing.

tlancina avatar Aug 13 '15 23:08 tlancina