Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Commit

Permalink
Editing textarea no longer scrolls view up. Fixes #103
Browse files Browse the repository at this point in the history
  • Loading branch information
deadlyfingers committed Jan 6, 2016
1 parent e8f68d3 commit 55f4628
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
44 changes: 34 additions & 10 deletions app/jxcore/public/elements/behaviors/multi-platform.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,60 @@

PageBehaviors.MultiPlatform = {

_isWKWebViewEnabled : true, // Set to true if Cordova WKWebView is enabled

// triggers input.focus() with a timeout
autoFocus : function(input) {
this._focus(input, 0);
},

// triggers input.focus() on everything except on iOS devices. For example if an input has already received autofocus it can result in disabling soft-keyboard text entry.
// triggers input.focus() on everything except on iOS UIWebView. Sometimes if an input has already received autofocus it can result in disabling soft-keyboard text entry.
shouldFocus : function(input) {
if( !this._isiOS() ) {
if ( !this._isiOSUIWebView() ) {
this._focus(input, 0);
} else {
console.log("iOS UIWebView shouldFocus disabled");
}
},

_focus : function(input, delay) {
setTimeout(function() {
console.log("focus");
input.focus();
input.focus();
}, delay);
},

// hack for iOS to prevent scrolling view up when soft keyboard pops up
// hack for iOS to prevent scrolling view up when soft keyboard pops up in UIWebView
shouldFocusWithoutScrollUp : function(e) {
if( this._isiOS() ) {
e.target.style.webkitTransform = 'translate3d(0px,-10000px,0)';
webkitRequestAnimationFrame(function() { this.style.webkitTransform = ''; }.bind(e.target));
}
if ( this._isiOSUIWebView() ) {
console.log("iOS UIWebView shouldFocusWithoutScrollUp");
e.target.style.webkitTransform = 'translate3d(0px,-10000px,0)';
webkitRequestAnimationFrame(function() { this.style.webkitTransform = ''; }.bind(e.target));
}
},

_isiOS : function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},

// Only iOS 9+ supports WKWebView, older versions of iOS will fallback to UIWebView
_isiOSUIWebView : function() {
return (this._isiOS() && !(this._isWKWebViewEnabled && this._iOSVersion()>=9) );
},

_iOSVersion : function() {
var minVersion = 7; // default to minimum iOS version supported by Cordova
var results = navigator.userAgent.match(/(iphone|ipod|ipad).*os ([0-9_]+)/i);
if (results && results.length === 3) {
var versionStr = results[2];
var version = parseInt( versionStr.substr(0, versionStr.indexOf('_')) );
if ( version > minVersion ){
console.log("iOS version:" + version);
return version;
}
}
return minVersion;
}

};
</script>
</script>
10 changes: 9 additions & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
<preference name="BackupWebStorage" value="local" />
<preference name="BackupWebStorage" value="none" />
<preference name="EnableViewportScale" value="false" />
<preference name="KeyboardDisplayRequiresUserAction" value="false" />
<preference name="HideKeyboardFormAccessoryBar" value="false" />
<preference name="KeyboardShrinksView" value="true" />
<preference name="SuppressesIncrementalRendering" value="true" />
<preference name="DisallowOverscroll" value="true" />
<preference name="SuppressesLongPressGesture" value="false" />
<preference name="Suppresses3DTouchGesture" value="false" />
<preference name="AllowInlineMediaPlayback" value="true" />
<feature name="CDVWKWebViewEngine">
<param name="ios-package" value="CDVWKWebViewEngine" />
</feature>
Expand All @@ -48,6 +53,8 @@
</feature>
<preference name="StatusBarOverlaysWebview" value="true" />
<preference name="StatusBarStyle" value="lightcontent" />
<preference name="TopActivityIndicator" value="white" />
<preference name="target-device" value="universal" />
<icon height="180" src="assets/ios/Resources/icons/[email protected]" width="180" />
<icon height="60" src="assets/ios/Resources/icons/icon-60.png" width="60" />
<icon height="120" src="assets/ios/Resources/icons/[email protected]" width="120" />
Expand Down Expand Up @@ -78,4 +85,5 @@
<plugin name="cordova-plugin-statusbar" spec="~2.0.0" />
<plugin name="cordova-plugin-camera" spec="~2.0.0" />
<plugin name="cordova-plugin-wkwebview-engine" spec="~1.0.1" />
<plugin name="cordova-plugin-keyboard" spec="~1.1.3" />
</widget>

0 comments on commit 55f4628

Please sign in to comment.