-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(android): when keyboard comes up, ensure input is in view
This requires us to set fullscreen="false" in our cordova apps. Uses the resize event to determine when the keyboard has been shown, then broadcasts an event from the activeElement: 'scrollChildIntoView', which is caught by the nearest parent scrollView. The scrollView will then see if that element is within the new device's height (since the keyboard resizes the screen), and if not scroll it into view. Additionally, when the keyboard resizes the screen we add a `.hide-footer` class to the body, which will hide tabbars and footer bars while the keyboard is opened. For now, this is android only. Closes #314.
- Loading branch information
Showing
9 changed files
with
229 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
(function(ionic) { | ||
|
||
ionic.Platform.ready(function() { | ||
if (ionic.Platform.is('android')) { | ||
androidKeyboardFix(); | ||
} | ||
}); | ||
|
||
function androidKeyboardFix() { | ||
var rememberedDeviceWidth = window.innerWidth; | ||
var rememberedDeviceHeight = window.innerHeight; | ||
var keyboardHeight; | ||
|
||
window.addEventListener('resize', resize); | ||
|
||
function resize() { | ||
|
||
//If the width of the window changes, we have an orientation change | ||
if (rememberedDeviceWidth !== window.innerWidth) { | ||
rememberedDeviceWidth = window.innerWidth; | ||
rememberedDeviceHeight = window.innerHeight; | ||
console.info('orientation change. deviceWidth =', rememberedDeviceWidth, | ||
', deviceHeight =', rememberedDeviceHeight); | ||
|
||
//If the height changes, and it's less than before, we have a keyboard open | ||
} else if (rememberedDeviceHeight !== window.innerHeight && | ||
window.innerHeight < rememberedDeviceHeight) { | ||
document.body.classList.add('hide-footer'); | ||
//Wait for next frame so document.activeElement is set | ||
window.rAF(handleKeyboardChange); | ||
} else { | ||
//Otherwise we have a keyboard close or a *really* weird resize | ||
document.body.classList.remove('hide-footer'); | ||
} | ||
|
||
function handleKeyboardChange() { | ||
//keyboard opens | ||
keyboardHeight = rememberedDeviceHeight - window.innerHeight; | ||
var activeEl = document.activeElement; | ||
if (activeEl) { | ||
//This event is caught by the nearest parent scrollView | ||
//of the activeElement | ||
ionic.trigger('scrollChildIntoView', { | ||
target: activeEl | ||
}, true); | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
})(window.ionic); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<html ng-app="navTest"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>List</title> | ||
|
||
<!-- Sets initial viewport load and disables zooming --> | ||
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no"> | ||
<link rel="stylesheet" href="lib/css/ionic.css"> | ||
<script src="lib/js/ionic.bundle.js"></script> | ||
</head> | ||
<body> | ||
|
||
<pane> | ||
|
||
<header class="bar bar-header bar-positive"> | ||
<div class="buttons"> | ||
<button ng-click="toggleDelete()" class="button button-clear">{{ editBtnText }}</button> | ||
</div> | ||
<h1 class="title">List Tests</h1> | ||
<div class="buttons"> | ||
<button ng-click="toggleReorder()" class="button button-clear">{{ reorderBtnText }}</button> | ||
</div> | ||
</header> | ||
|
||
<footer class="bar bar-footer bar-positive"> | ||
<h1 class="title">Footer time!</h1> | ||
</footer> | ||
|
||
<content has-header="true" has-footer="true"> | ||
<input type="text" placeholder="text me!"> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<input type="text" placeholder="text me!"> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<input type="text" placeholder="text me!"> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<input type="text" placeholder="text me!"> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<input type="text" placeholder="text me!"> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<input type="text" placeholder="text me!"> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<input type="text" placeholder="text me!"> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<input type="text" placeholder="text me!"> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<p style="margin: 10px;">...</p> | ||
<input type="text" placeholder="text me!"> | ||
</content> | ||
|
||
</pane> | ||
</body> | ||
</html> | ||
|