NTP-75220 | add spacing top and footer in web view (#16717)

This commit is contained in:
Sandeep Kumar
2025-06-23 18:37:43 +05:30
committed by GitHub
parent 0ce9b36934
commit 72ab14632e
2 changed files with 86 additions and 87 deletions

View File

@@ -9,7 +9,6 @@ package com.navi.insurance.decentro
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.lifecycle.lifecycleScope
import com.google.gson.Gson
import com.navi.base.model.CtaData
@@ -39,7 +38,6 @@ class GiWebViewActivity : GiBaseActivity() {
val exitUrl = intent.getStringExtra(WEBVIEW_EXIT_URL)
timeoutThresholdMs = intent.getStringExtra(CLOSE_TIMEOUT)?.toLong() ?: 0
ctaData = Gson().fromJson(intent.getStringExtra(CTA_DATA).orEmpty(), CtaData::class.java)
enableEdgeToEdge()
startTimeout()
setContent {
GiMaterialTheme {

View File

@@ -11,9 +11,11 @@ import android.annotation.SuppressLint
import android.graphics.Bitmap
import android.view.ViewGroup
import android.webkit.*
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material3.*
@@ -21,7 +23,6 @@ import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import com.navi.insurance.analytics.InsuranceAnalyticsConstants
@@ -35,100 +36,100 @@ fun WebViewScreen(
) {
Surface(modifier = Modifier.fillMaxSize()) {
Box(modifier = Modifier.fillMaxSize().padding(top = 32.dp)) {
LaunchedEffect(Unit) {
sendEvent(InsuranceAnalyticsConstants.HI_DECENTRO_KYC_WEBVIEW_INIT)
Column(modifier = Modifier.fillMaxSize()) {
Box(modifier = Modifier.fillMaxWidth().background(color = Color.White)) {
IconButton(
onClick = { nextScreen() },
modifier = Modifier.align(Alignment.CenterStart),
) {
Icon(
imageVector = Icons.Default.Close,
contentDescription = "Close",
tint = Color.Black,
)
}
}
AndroidView(
factory = { ctx ->
WebView(ctx).apply {
layoutParams =
ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
)
webViewClient =
object : WebViewClient() {
override fun onPageStarted(
view: WebView?,
url: String?,
favicon: Bitmap?,
) {
sendEvent(
InsuranceAnalyticsConstants
.HI_DECENTRO_KYC_NAVIGATION_LISTENER
)
super.onPageStarted(view, url, favicon)
url?.let { currentUrl ->
if (shouldExitOnUrl(currentUrl, exitUrl)) {
nextScreen()
Box(modifier = Modifier.fillMaxSize()) {
LaunchedEffect(Unit) {
sendEvent(InsuranceAnalyticsConstants.HI_DECENTRO_KYC_WEBVIEW_INIT)
}
AndroidView(
factory = { ctx ->
WebView(ctx).apply {
layoutParams =
ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
)
webViewClient =
object : WebViewClient() {
override fun onPageStarted(
view: WebView?,
url: String?,
favicon: Bitmap?,
) {
sendEvent(
InsuranceAnalyticsConstants
.HI_DECENTRO_KYC_NAVIGATION_LISTENER
)
super.onPageStarted(view, url, favicon)
url?.let { currentUrl ->
if (shouldExitOnUrl(currentUrl, exitUrl)) {
nextScreen()
}
}
}
}
override fun shouldOverrideUrlLoading(
view: WebView?,
request: WebResourceRequest?,
): Boolean {
request?.url?.let { uri ->
val urlString = uri.toString()
if (shouldExitOnUrl(urlString, exitUrl)) {
nextScreen()
override fun shouldOverrideUrlLoading(
view: WebView?,
request: WebResourceRequest?,
): Boolean {
request?.url?.let { uri ->
val urlString = uri.toString()
if (shouldExitOnUrl(urlString, exitUrl)) {
nextScreen()
}
}
return super.shouldOverrideUrlLoading(view, request)
}
}
webChromeClient =
object : WebChromeClient() {
override fun onReceivedTitle(view: WebView?, title: String?) {
super.onReceivedTitle(view, title)
title?.let { pageTitle ->
sendEvent("HI_DECENTRO_" + pageTitle.take(30))
}
}
return super.shouldOverrideUrlLoading(view, request)
}
}
webChromeClient =
object : WebChromeClient() {
override fun onReceivedTitle(view: WebView?, title: String?) {
super.onReceivedTitle(view, title)
title?.let { pageTitle ->
sendEvent("HI_DECENTRO_" + pageTitle.take(30))
override fun onConsoleMessage(
consoleMessage: ConsoleMessage?
): Boolean {
return true
}
}
override fun onConsoleMessage(
consoleMessage: ConsoleMessage?
): Boolean {
return true
}
settings.apply {
javaScriptEnabled = true
domStorageEnabled = true
loadWithOverviewMode = true
useWideViewPort = true
builtInZoomControls = true
displayZoomControls = false
mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
setSupportMultipleWindows(true)
javaScriptCanOpenWindowsAutomatically = true
loadsImagesAutomatically = true
cacheMode = WebSettings.LOAD_DEFAULT
}
settings.apply {
javaScriptEnabled = true
domStorageEnabled = true
loadWithOverviewMode = true
useWideViewPort = true
builtInZoomControls = true
displayZoomControls = false
mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
setSupportMultipleWindows(true)
javaScriptCanOpenWindowsAutomatically = true
loadsImagesAutomatically = true
cacheMode = WebSettings.LOAD_DEFAULT
loadUrl(url)
}
loadUrl(url)
}
},
update = { webView ->
if (webView.url != url) {
webView.loadUrl(url)
}
},
modifier = Modifier.fillMaxSize(),
)
IconButton(
onClick = { nextScreen() },
modifier = Modifier.align(Alignment.TopStart).padding(top = 16.dp),
) {
Icon(
imageVector = Icons.Default.Close,
contentDescription = "Close",
tint = Color.Black,
},
update = { webView ->
if (webView.url != url) {
webView.loadUrl(url)
}
},
modifier = Modifier.fillMaxSize(),
)
}
}