当前位置:网站首页>Resolve the horizontal (vertical) sliding conflict between viewpager and WebView

Resolve the horizontal (vertical) sliding conflict between viewpager and WebView

2022-07-05 09:36:00 Black Mountain demon 2018

Rookies still talk about the problems encountered in the project .

Problem description :

Use... In projects viewpager + fragment To achieve multi-channel switching , One of them fragment There's a webview, This webview Loaded H5 page

There are left and right sliding carousels , Outer parent control (viewpager) Will intercept and consume left-right sliding events , therefore H5 You can't slide the left and right rotating pictures in .

Problem solving :

1. The first scheme is when the channel page is H5 When , Ban the outer layer viewpager Slide left and right , namely webview call requestDisallowInterceptTouchEvent(true) Don't let the parent layout intercept events . But this plan is too violent , If the product manager agrees .

2. The second scheme is native native And H5 Interact , from H5 tell native Location of its own rotation map , And then in webview Of onTouchListener Of onTouch Do the corresponding processing in the method , If the sliding gesture is in this range , be requestDisallowInterceptTouchEvent(true) Don't let the parent layout intercept events . conversely , Then let the parent layout intercept events . This scheme has many limitations , If H5 The need is clear , Just fixed in a certain area, there is a rotating broadcast that slides left and right , And the future will not change much , Then this plan is feasible , But if H5 The page has many controls that can slide left and right , And future demand is not necessarily , Then the scope of these controls must be told to the native . And the range judgment of the client will also follow H5 The changes of change follow the changes , In this case, it is not advisable . Specific reference https://www.jianshu.com/p/a6f9d4046985

3. The third scheme is also Native native And H5 Interact , Principle similarity . But it is different from scheme II ,H5 There is no need to tell native native The scope of specific rotation control , Native native You only need to define whether to let the parent layout intercept events for H5 Call .H5 The rotation control on only needs to be in the corresponding touchstart and touchmove Just adjust the original method . For details, please refer to https://www.jianshu.com/p/818d566c4c5a, I adopted this plan in the project .

原网站

版权声明
本文为[Black Mountain demon 2018]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140536454484.html