Skip to content

Commit

Permalink
feat:Basic Pull to Refresh sample
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinnZou committed Apr 3, 2024
1 parent d458067 commit 7270728
Showing 1 changed file with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import android.util.Log
import android.webkit.WebView
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -42,6 +45,7 @@ class PullToRefreshWebViewSample : ComponentActivity() {
var refreshing by remember { mutableStateOf(false) }
LaunchedEffect(refreshing) {
if (refreshing) {
navigator.reload()
delay(1200)
refreshing = false
}
Expand All @@ -51,30 +55,34 @@ class PullToRefreshWebViewSample : ComponentActivity() {
state = rememberPullToRefreshState(isRefreshing = refreshing),
onRefresh = { refreshing = true }
) {
// A custom WebViewClient and WebChromeClient can be provided via subclassing
val webClient = remember {
object : AccompanistWebViewClient() {
override fun onPageStarted(
view: WebView,
url: String?,
favicon: Bitmap?
) {
super.onPageStarted(view, url, favicon)
Log.d("Accompanist WebView", "Page started loading for $url")
Column(
modifier = Modifier.verticalScroll(state = rememberScrollState())
) {
// A custom WebViewClient and WebChromeClient can be provided via subclassing
val webClient = remember {
object : AccompanistWebViewClient() {
override fun onPageStarted(
view: WebView,
url: String?,
favicon: Bitmap?
) {
super.onPageStarted(view, url, favicon)
Log.d("Accompanist WebView", "Page started loading for $url")
}
}
}
}

WebView(
state = state,
modifier = Modifier
.fillMaxSize(),
navigator = navigator,
onCreated = { webView ->
webView.settings.javaScriptEnabled = true
},
client = webClient
)
WebView(
state = state,
modifier = Modifier
.fillMaxSize(),
navigator = navigator,
onCreated = { webView ->
webView.settings.javaScriptEnabled = true
},
client = webClient
)
}
}
}
}
Expand Down

0 comments on commit 7270728

Please sign in to comment.