Skip to content

Instantly share code, notes, and snippets.

@wplong11
Last active November 22, 2021 01:54
Show Gist options
  • Select an option

  • Save wplong11/e62554b23f2f989d48f677fb38a3b6b4 to your computer and use it in GitHub Desktop.

Select an option

Save wplong11/e62554b23f2f989d48f677fb38a3b6b4 to your computer and use it in GitHub Desktop.
Android 웹뷰 사용 경험 개선을 위한 확장 함수. 네이티브 앱을 쓰는 것 처럼 느껴지게 하는 함수들을 제공한다.
fun WebView.disableTouchCalloutAndUserSelect() {
this.evaluateJavascript("""
(function() {
const head = document.getElementsByTagName('head')[0];
const style = document.createRange().createContextualFragment(`
<style type="text/css">
*:not(input):not(textarea) {
-webkit-touch-callout: none;
-webkit-user-select: none;
}
</style>
`);
head.appendChild(style);
})()
""".trimIndent(), null)
}
fun WebView.disableTouchHighlight() {
this.evaluateJavascript("""
(function() {
const head = document.getElementsByTagName('head')[0];
const style = document.createRange().createContextualFragment(`
<style type="text/css">
input,
textarea,
button,
select,
a {
-webkit-tap-highlight-color: rgba(0,0,0,0);
}
</style>
`);
head.appendChild(style);
})()
""".trimIndent(), null)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment