Skip to content

Commit

Permalink
Merge pull request #9943 from keymanapp/fix/web/gestures-old-android-…
Browse files Browse the repository at this point in the history
…compat

fix(web): restores compat with older Android devices 🐵
  • Loading branch information
jahorton authored Nov 14, 2023
2 parents 1a7245e + 3ea4a60 commit eefea0d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 13 deletions.
1 change: 1 addition & 0 deletions android/KMEA/app/src/main/assets/keyboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
polyfill.
-->
<script src="es6-shim.min.js"></script>
<script src="other-polyfills.js"></script>
<script src="keymanweb-webview.js"></script>
<script src="sentry.min.js"></script>
<script src="keyman-sentry.js"></script>
Expand Down
17 changes: 17 additions & 0 deletions android/KMEA/app/src/main/assets/other-polyfills.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Needed by the KMW's gesture engine until Chrome 61.
var DOMRect = DOMRect || function (x, y, width, height) {
this.x = this.left = x;
this.y = this.top = y;
this.width = width;
this.height = height;
this.bottom = y + height;
this.right = x + width;
};

// https://stackoverflow.com/questions/53308396/how-to-polyfill-array-prototype-includes-for-ie8
if(!Array.prototype.includes){
//or use Object.defineProperty
Array.prototype.includes = function(search){
return !!~this.indexOf(search);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ public String toString() {
protected static final String KMFilename_KmwGlobeHintCss = "globe-hint.css";
protected static final String KMFilename_Osk_Ttf_Font = "keymanweb-osk.ttf";
protected static final String KMFilename_JSPolyfill = "es6-shim.min.js";
protected static final String KMFilename_JSPolyfill2 = "other-polyfills.js";

// Deprecated by KeyboardController.KMFilename_Installed_KeyboardsList
public static final String KMFilename_KeyboardsList = "keyboards_list.dat";
Expand Down Expand Up @@ -812,6 +813,7 @@ private static void copyAssets(Context context) {
// Copy default keyboard font
copyAsset(context, KMDefault_KeyboardFont, "", true);
copyAsset(context, KMFilename_JSPolyfill, "", true);
copyAsset(context, KMFilename_JSPolyfill2, "", true);

// Keyboard packages directory
File packagesDir = new File(getPackagesDir());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ export class PaddedZoneSource implements RecognitionZoneSource {
getBoundingClientRect(): DOMRect {
const rootZone = this.root.getBoundingClientRect();

return DOMRect.fromRect({
x: rootZone.x + this.edgePadding.x,
y: rootZone.y + this.edgePadding.y,
width: rootZone.width - this.edgePadding.w,
height: rootZone.height - this.edgePadding.h
});
return new DOMRect(
/*x:*/ rootZone.x + this.edgePadding.x,
/*y:*/ rootZone.y + this.edgePadding.y,
/*width:*/ rootZone.width - this.edgePadding.w,
/*height:*/ rootZone.height - this.edgePadding.h
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export class ViewportZoneSource implements RecognitionZoneSource {

getBoundingClientRect(): DOMRect {
// Viewport dimension detection is based on https://stackoverflow.com/a/8876069.
return DOMRect.fromRect({
y: 0,
x: 0,
width: Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0),
height: Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0)
});
return new DOMRect(
/*x:*/ 0,
/*y:*/ 0,
/*width:*/ Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0),
/*height:*/ Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0)
);
}
}
3 changes: 3 additions & 0 deletions common/web/lm-worker/build-bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ await esbuild.build(embeddedWorkerBuildOptions);
const minifiedProfilingOptions = {
...embeddedWorkerBuildOptions,
minify: true,
// Do NOT enable - will break under Android 5.0 / Chrome 35 environments, likely through Chrome 42.
// https://caniuse.com/mdn-javascript_builtins_function_name_configurable_true
keepNames: false,
metafile: true,
write: false // don't actually write the file.
}
Expand Down
4 changes: 3 additions & 1 deletion common/web/lm-worker/build-wrap-and-minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ if(MINIFY) {
sourcemap: 'external',
sourcesContent: DEBUG,
minify: true,
keepNames: true,
// Do NOT enable - will break under Android 5.0 / Chrome 35 environments, likely through Chrome 42.
// https://caniuse.com/mdn-javascript_builtins_function_name_configurable_true
keepNames: false,
target: 'es5',
outfile: `build/lib/worker-main.polyfilled.min.js`
});
Expand Down

0 comments on commit eefea0d

Please sign in to comment.