Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull refresh on iOS #218

Open
dappledore opened this issue Sep 5, 2024 · 3 comments
Open

Pull refresh on iOS #218

dappledore opened this issue Sep 5, 2024 · 3 comments

Comments

@dappledore
Copy link

Im using below to implement pull to refresh , this works on Android but on iOS its a blank Webview. If i remove

.verticalScroll(rememberScrollState()) line then the Webview is not blank however unable to pull to refresh.

Is there a way to get pull to refresh to work on iOS and Android.

import com.multiplatform.webview.web.WebView
import com.multiplatform.webview.web.rememberWebViewNavigator
import com.multiplatform.webview.web.rememberWebViewState
import dev.materii.pullrefresh.PullRefreshLayout
import dev.materii.pullrefresh.rememberPullRefreshState
import dev.materii.pullrefresh.PullRefreshIndicator

  val webViewState =
        rememberWebViewState("https://www.timeanddate.com/worldclock/japan/tokyo")
    val navigator = rememberWebViewNavigator()

    var isRefreshing by remember {
        mutableStateOf(false)
    }
    var pullRefreshState = rememberPullRefreshState(refreshing = isRefreshing, onRefresh = {
        isRefreshing = true
        navigator.reload()
        isRefreshing = false
    })

PullRefreshLayout(
            modifier = Modifier.fillMaxSize(),
            state = pullRefreshState,
        ) {
                Box(
                    modifier = Modifier
                        .fillMaxSize()
                        .verticalScroll(rememberScrollState())
                ) {
                    Column(Modifier.fillMaxSize())
                    {
                        val text = webViewState.let {
                            "${it.pageTitle ?: ""} ${it.loadingState} ${it.lastLoadedUrl ?: ""}"
                        }
                        Text(text)
                        WebView(
                            state = webViewState,
                            navigator = navigator,
                            modifier = Modifier.fillMaxSize()
                        )
                    }
                    PullRefreshIndicator(
                        state = pullRefreshState,
                        Modifier.align(Alignment.TopCenter)
                    )
                }
        }
@KevinnZou
Copy link
Owner

@dappledore Could you have a try with this sample?

@dappledore
Copy link
Author

Could you have a try with this sample?

@KevinnZou Is this Android only? The above is working Android but not on iOS. The box with vertical scroll seems to be the problem.

@nicoppola
Copy link

nicoppola commented Nov 27, 2024

Has there been any updates on this? I'm trying to implement scroll away top app bar, so I need my WebView to be in a scrollable container for the nested scrolling behavior to work correctly. Works on Android, but as soon as I add .verticalScroll(rememberScrollState()) to the box containing my WebView, it doesn't load anything on iOS.

Here is my code, let me know if there's anything else I can do to help debug!

val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(rememberTopAppBarState())
    Scaffold(
        topBar = {
            CenterAlignedTopAppBar(
                title = { Text(navComponent.title) },
                scrollBehavior = scrollBehavior,
               ... )
         },
         ...
        modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
        content = { innerPadding ->
            Box(
                modifier = Modifier
                    .fillMaxSize()
                    .padding(innerPadding)
                    .verticalScroll(rememberScrollState())  // if I comment this line out, the WebView is visible in iOS, else not
            ) {
                val state: WebViewState = rememberWebViewState(url = navComponent.url)

                WebView(
                    state = state,
                    modifier = Modifier
                        .fillMaxSize(),
                )
            }
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants