Last active
November 22, 2021 01:54
-
-
Save wplong11/e62554b23f2f989d48f677fb38a3b6b4 to your computer and use it in GitHub Desktop.
Android 웹뷰 사용 경험 개선을 위한 확장 함수. 네이티브 앱을 쓰는 것 처럼 느껴지게 하는 함수들을 제공한다.
This file contains hidden or 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
| 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