-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b568dbf
commit d5dd87e
Showing
17 changed files
with
273 additions
and
271 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
multiplatformContact/src/androidMain/kotlin/multiContacts/Launcher.kt
This file was deleted.
Oops, something went wrong.
85 changes: 0 additions & 85 deletions
85
multiplatformContact/src/androidMain/kotlin/multiContacts/Picker.kt
This file was deleted.
Oops, something went wrong.
105 changes: 105 additions & 0 deletions
105
multiplatformContact/src/androidMain/kotlin/multiplatformWebView/WebviewEngine.android.kt
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,105 @@ | ||
package multiplatformWebView | ||
|
||
import android.graphics.Bitmap | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.webkit.WebResourceRequest | ||
import android.webkit.WebSettings | ||
import android.webkit.WebView | ||
import android.webkit.WebViewClient | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.rememberScrollState | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.viewinterop.AndroidView | ||
import androidx.core.content.ContextCompat | ||
|
||
|
||
@Composable | ||
actual fun WebViewEngine( | ||
htmlContent: String, | ||
isLoading: (isLoading: Boolean) -> Unit, | ||
onUrlClicked: (url: String) -> Unit, | ||
onCreated: () -> Unit, | ||
onDispose: () -> Unit, | ||
) { | ||
val context = LocalContext.current | ||
val color = ContextCompat.getColor(context, androidx.core.R.color.notification_icon_bg_color) | ||
var isLoadingFinished by remember { mutableStateOf(false) } | ||
Box(modifier = Modifier.fillMaxWidth().verticalScroll(rememberScrollState())) { | ||
AndroidView( | ||
modifier = Modifier.fillMaxWidth(), | ||
factory = { context -> | ||
WebView(context).apply { | ||
// Enable WebView debugging for development | ||
onCreated() | ||
//Todo---- remove debugger when publishing | ||
WebView.setWebContentsDebuggingEnabled(true) | ||
|
||
scrollBarStyle = View.SCROLLBARS_OUTSIDE_OVERLAY | ||
setBackgroundColor(color) | ||
layoutParams = ViewGroup.LayoutParams( | ||
ViewGroup.LayoutParams.MATCH_PARENT, | ||
ViewGroup.LayoutParams.WRAP_CONTENT | ||
) | ||
// Enable horizontal scrolling and adjust settings | ||
settings.apply { | ||
loadWithOverviewMode = true | ||
useWideViewPort = true | ||
layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL | ||
javaScriptEnabled = true // Enable JavaScript if needed | ||
domStorageEnabled = true // Enable DOM storage for complex pages | ||
mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW // Allow mixed content | ||
userAgentString = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" | ||
setSupportZoom(true) // Enable zoom support | ||
builtInZoomControls = true // Enable built-in zoom controls (e.g., pinch-to-zoom) | ||
displayZoomControls = false | ||
} | ||
|
||
webViewClient = object : WebViewClient() { | ||
override fun onPageStarted( | ||
view: WebView?, | ||
url: String?, | ||
favicon: Bitmap? | ||
) { | ||
isLoading(true) | ||
} | ||
override fun onPageFinished(view: WebView?, url: String?) { | ||
view?.scrollTo(view.contentHeight, 0) | ||
isLoadingFinished = true | ||
isLoading(false) | ||
} | ||
|
||
override fun shouldOverrideUrlLoading( | ||
view: WebView?, | ||
request: WebResourceRequest? | ||
): Boolean { | ||
return if (request?.url.toString().contains("jpg") || | ||
request?.url.toString().contains("png") || | ||
request?.url.toString().contains("attachment_id") | ||
) { | ||
true | ||
} else { | ||
onUrlClicked(request?.url.toString()) | ||
true | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
update = { webView -> | ||
webView.loadUrl(htmlContent) | ||
}, | ||
onRelease = { | ||
onDispose() | ||
} | ||
) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
multiplatformContact/src/commonMain/kotlin/multiContacts/Launcher.kt
This file was deleted.
Oops, something went wrong.
38 changes: 0 additions & 38 deletions
38
multiplatformContact/src/commonMain/kotlin/multiContacts/MultiContacts.kt
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
multiplatformContact/src/commonMain/kotlin/multiContacts/Picker.kt
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
multiplatformContact/src/commonMain/kotlin/multiplatformWebView/WebviewEngine.kt
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,12 @@ | ||
package multiplatformWebView | ||
|
||
import androidx.compose.runtime.Composable | ||
|
||
@Composable | ||
expect fun WebViewEngine( | ||
htmlContent: String, | ||
isLoading: (isLoading: Boolean) -> Unit, | ||
onUrlClicked: (url: String) -> Unit, | ||
onCreated: () -> Unit, | ||
onDispose: () -> Unit, | ||
) |
31 changes: 31 additions & 0 deletions
31
multiplatformContact/src/commonMain/kotlin/multiplatformWebView/WebviewTestSample.kt
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,31 @@ | ||
package multiplatformWebView | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Scaffold | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
|
||
@Composable | ||
fun WebViewTestSample(){ | ||
Scaffold(modifier = Modifier.fillMaxSize()){ | ||
Column(modifier = Modifier | ||
.padding(it) | ||
.fillMaxSize()){ | ||
WebViewEngine( | ||
htmlContent = "https://github.com/Lilytreasure", | ||
isLoading = { | ||
}, | ||
onUrlClicked = { url -> | ||
}, | ||
onCreated ={ | ||
|
||
}, | ||
onDispose = { | ||
|
||
} | ||
) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
multiplatformContact/src/iosMain/kotlin/multiContacts/Launcher.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.