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

webview 自定义滚动边界功能 #394

Closed
lizhw123 opened this issue Mar 7, 2018 · 7 comments
Closed

webview 自定义滚动边界功能 #394

lizhw123 opened this issue Mar 7, 2018 · 7 comments

Comments

@lizhw123
Copy link

lizhw123 commented Mar 7, 2018

嵌套了一个webview实现下拉刷新,页面比较长的时候,滑动一段距离后,在页面任意地方下拉都会触发下拉刷新。想使用smartLayout 提供的 自定义滚动边界功能,ScrollBoundaryDecider有demo吗?

@scwang90
Copy link
Owner

scwang90 commented Mar 7, 2018

webview 的问题应该从内部 html 代码解决

@scwang90 scwang90 closed this as completed Mar 7, 2018
@lizhw123
Copy link
Author

lizhw123 commented Mar 7, 2018

解决了,让HTML告诉APP webview是否到顶,然后在下拉刷新。希望对大家有用。

    mRefreshLayout.setScrollBoundaryDecider(new ScrollBoundaryDecider() {
        @Override
        public boolean canRefresh(View content) {
            //webview滚动到顶部才可以下拉刷新
            return TextUtils.equals(canReload, "1");
        }

        @Override
        public boolean canLoadmore(View content) {
            return false;
        }
    });

@scwang90
Copy link
Owner

scwang90 commented Mar 7, 2018

@lizhw123 好样的!!

@Jiiiiiin
Copy link

参考: https://blog.csdn.net/ahuyangdong/article/details/77773323

    private void _initSmartRefreshLayout() {
        // TODO 抽出来
        // https://github.com/scwang90/SmartRefreshLayout/blob/master/art/md_faq.md
        //使上拉加载具有弹性效果
        mSmartRefreshLayout.setEnableAutoLoadMore(false);
        //禁止越界拖动(1.0.4以上版本)
        mSmartRefreshLayout.setEnableOverScrollDrag(false);
        //关闭越界回弹功能
        mSmartRefreshLayout.setEnableOverScrollBounce(false);
        // 这个功能是本刷新库的特色功能:在列表滚动到底部时自动加载更多。 如果不想要这个功能,是可以关闭的:
        mSmartRefreshLayout.setEnableAutoLoadMore(false);
        final MaterialHeader mMaterialHeader = (MaterialHeader) mSmartRefreshLayout.getRefreshHeader();
        mMaterialHeader.setColorSchemeColors(new int[]{ViewPlus.getConfiguration(ConfigKeys.APP_THEME_COLOR)});
        if (canPullRefresh()) {
            mSmartRefreshLayout.setOnRefreshListener(refreshLayout -> mWebViewDelegate.refresh());
            mSmartRefreshLayout.setScrollBoundaryDecider(new ScrollBoundaryDecider() {
                @Override
                public boolean canRefresh(View content) {
                    //webview滚动到顶部才可以下拉刷新
                    try {
                        return !(mWebViewDelegate.getWebViewOrNullllll().getScrollY() > 0);
                    } catch (Exception e) {
                        LoggerProxy.e(e, "canRefresh err");
                    }
                    return false;
                }

                @Override
                public boolean canLoadMore(View content) {
                    return false;
                }

            });
        }
    }

@scwang90

@Winstonokk
Copy link

请问一下你这个canReload是什么值

@zhaoxiuyu
Copy link

@lizhw123 请问一下你这个canReload是什么值?

@CrassusX
Copy link

// 配置滚动和防止刷新
private fun setupRefresh(view:View){
mRefreshlayout = view?.findViewById(R.id.refreshLayout) as RefreshLayout
mRefreshlayout.setEnableAutoLoadMore(false)
mRefreshlayout.setEnableOverScrollDrag(false)
mRefreshlayout.setEnableOverScrollBounce(false)
mRefreshlayout.setEnableHeaderTranslationContent(false)
mRefreshlayout.setScrollBoundaryDecider(object : ScrollBoundaryDecider {
override fun canRefresh(content: View?): Boolean {
try {
val value = mAgentWeb.webCreator.webView.scrollY <= 0
return value
} catch (e: java.lang.Exception) {
TLog.e( "canRefresh err")
}
return false
}

       override fun canLoadMore(content: View?): Boolean {
            return false
        }
    })

    mRefreshlayout.setOnRefreshListener(object : OnRefreshListener {
        override fun onRefresh(refreshlayout: RefreshLayout) {
            mAgentWeb.urlLoader.reload()
            mRefreshlayout.finishRefresh(2000)
        }
    })
}

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

6 participants