IOS 8 Scrolling to focused input / Scrolling whilst input is focused
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
I am getting the same issue. This is a web site not native so I cannot use the disable scroll keyboard plugin.
i've got a code pen to show this issue in action: http://codepen.io/phoey/pen/seAkK
Any word on this from the ionic team?
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.
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
Had same issue (compiled app, not mobile safari) and the fix from @PeBu worked for me.
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 ?
@PeBu fix works but then the navigation bar hide behind the status bar on a compiled app.
What is the @PeBu fix?
Edit: Looks to be compiled app only, not Mobile Safari :'-(
Anyone able to help?
Thanks
@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);
}
});
}
})
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!
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.
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!
@tlancina thank you for that hotfix...
@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
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.
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, assuming you're not using Cordova, have you tried setting overflow-scroll=true?
@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 this issue was for mobile Safari, using cordova.plugins.Keyboard.disableScroll(true) should prevent the behavior you're seeing.