diff --git a/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailWrapperFragment.kt b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailWrapperFragment.kt index 981f85e8fb..55a2246382 100644 --- a/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailWrapperFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/gamedetail/GameDetailWrapperFragment.kt @@ -727,6 +727,8 @@ class GameDetailWrapperFragment : BaseLazyFragment(), IScrollable { fragment = fragment ?: WebFragment() bundle.putString(EntranceConsts.KEY_ENTRANCE, "游戏专区") bundle.putString(EntranceConsts.KEY_URL, zone.link) + bundle.putBoolean(WebFragment.KEY_ENABLE_HORIZONTAL_SCROLL_DISPATCH, true) + bundle.putBoolean(WebFragment.KEY_FORCE_ENABLE_NESTED_SCROLL, true) } else { fragment = fragment ?: FuLiFragment() } @@ -735,6 +737,12 @@ class GameDetailWrapperFragment : BaseLazyFragment(), IScrollable { GameDetailTabEntity.TYPE_WEB -> { fragment = fragment ?: WebFragment() bundle.putString(EntranceConsts.KEY_URL, tabEntity.link?.link) + bundle.putBoolean(WebFragment.KEY_ENABLE_HORIZONTAL_SCROLL_DISPATCH, true) + bundle.putBoolean(WebFragment.KEY_FORCE_ENABLE_NESTED_SCROLL, true) + bundle.putBoolean( + WebFragment.KEY_LEAVE_WEB_PAGE_TO_HANDLE_BACK_PRESSED, + tabEntity.link?.link?.contains("leave_web_page_handle_back_pressed=true") == true + ) } GameDetailTabEntity.TYPE_GIFT -> { diff --git a/app/src/main/java/com/halo/assistant/fragment/WebFragment.kt b/app/src/main/java/com/halo/assistant/fragment/WebFragment.kt index cb0a047b92..2335a0581b 100644 --- a/app/src/main/java/com/halo/assistant/fragment/WebFragment.kt +++ b/app/src/main/java/com/halo/assistant/fragment/WebFragment.kt @@ -117,6 +117,7 @@ class WebFragment : LazyFragment(), IScrollable { private var mLeaveWebpageToHandleTitle = false //是否由网页处理标题 private var mClearHistoryOnLoaded = false // 是否加载完成以后清理掉旧的加载历史 private var mIsWebViewInstalled = true // 当前设备是否存在可用的 WebView + private var mForceEnableNestedScroll = false // 强制启用嵌套滚动 private var mTimeElapsedHelper: TimeElapsedHelper? = null private lateinit var mJsApi: DefaultJsApi @@ -347,6 +348,7 @@ class WebFragment : LazyFragment(), IScrollable { mIsSecurityCertification = args.getBoolean(KEY_IS_SECURITY_CERTIFICATION, false) mLeaveWebpageToHandleTitle = args.getBoolean(KEY_LEAVE_WEB_PAGE_TO_HANDLE_TITLE, false) mWebUrl = dealWithUrl(args.getString(EntranceConsts.KEY_URL, "")) + mForceEnableNestedScroll = args.getBoolean(KEY_ENABLE_HORIZONTAL_SCROLL_DISPATCH) } mJsApi = DefaultJsApi( requireContext(), @@ -698,6 +700,9 @@ class WebFragment : LazyFragment(), IScrollable { if (mIsHorizontalDispatcherEnabled) { webview.enableHorizontalScrollDispatch() } + if (mForceEnableNestedScroll) { + webview.enableForceNestedScroll() + } webview.addJavascriptObject(mJsApi, null) webview.addJavascriptObject(ShareNativeCallback(), "share") webview.addJavascriptObject(InternalJsApi(), "internal") @@ -1047,6 +1052,7 @@ class WebFragment : LazyFragment(), IScrollable { const val KEY_GAME_NAME = "game_name" const val KEY_CLOSE_BUTTON = "close_button" const val KEY_ENABLE_HORIZONTAL_SCROLL_DISPATCH = "enable_horizontal_scroll_dispatch" + const val KEY_FORCE_ENABLE_NESTED_SCROLL = "force_enable_nested_scroll" private const val REQUEST_PICK_IMAGE = 101 } } \ No newline at end of file diff --git a/module_common/src/main/java/com/gh/gamecenter/common/view/NestedScrollWebView2.java b/module_common/src/main/java/com/gh/gamecenter/common/view/NestedScrollWebView2.java index 93e0543227..e8803bfab7 100644 --- a/module_common/src/main/java/com/gh/gamecenter/common/view/NestedScrollWebView2.java +++ b/module_common/src/main/java/com/gh/gamecenter/common/view/NestedScrollWebView2.java @@ -64,6 +64,8 @@ public class NestedScrollWebView2 extends DWebView implements NestedScrollingChi private boolean isScrollX = false; + private boolean mForceEnableNestedScroll = false; + public NestedScrollWebView2(Context context, AttributeSet attrs) { super(context, attrs); init(); @@ -117,7 +119,7 @@ public class NestedScrollWebView2 extends DWebView implements NestedScrollingChi @Override public boolean onInterceptTouchEvent(MotionEvent ev) { - if (!mIsParentViewImplNestedScrolling) { + if (!mIsParentViewImplNestedScrolling && !mForceEnableNestedScroll) { return super.onInterceptTouchEvent(ev); } @@ -193,7 +195,7 @@ public class NestedScrollWebView2 extends DWebView implements NestedScrollingChi @Override public boolean onTouchEvent(MotionEvent ev) { - if (!mIsParentViewImplNestedScrolling) { + if (!mIsParentViewImplNestedScrolling && !mForceEnableNestedScroll) { return super.onTouchEvent(ev); } @@ -527,7 +529,7 @@ public class NestedScrollWebView2 extends DWebView implements NestedScrollingChi @Override public void computeScroll() { - if (!mIsParentViewImplNestedScrolling) { + if (!mIsParentViewImplNestedScrolling && !mForceEnableNestedScroll) { super.computeScroll(); return; } @@ -839,4 +841,8 @@ public class NestedScrollWebView2 extends DWebView implements NestedScrollingChi public void enableHorizontalScrollDispatch() { mInterceptHorizontalScrollDispatch = false; } + + public void enableForceNestedScroll() { + mForceEnableNestedScroll = true; + } }