You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ky...@apache.org on 2019/11/20 10:50:41 UTC

[incubator-weex] branch master updated: [Android] support loadMore for horizontalScrollView (#3025)

This is an automated email from the ASF dual-hosted git repository.

kyork pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-weex.git


The following commit(s) were added to refs/heads/master by this push:
     new 2fa03e5  [Android] support loadMore for horizontalScrollView (#3025)
2fa03e5 is described below

commit 2fa03e58d313144772d9e8bee44f64b039c45e20
Author: chen <lu...@users.noreply.github.com>
AuthorDate: Wed Nov 20 18:50:29 2019 +0800

    [Android] support loadMore for horizontalScrollView (#3025)
    
    demo:http://editor.weex.io/p/lucky-chen/scroler-appear/commit/0b489fe4c8e095ed908577ff1f1f62d8
---
 .../org/apache/weex/ui/component/WXScroller.java   | 32 +++++++++++++++-------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/android/sdk/src/main/java/org/apache/weex/ui/component/WXScroller.java b/android/sdk/src/main/java/org/apache/weex/ui/component/WXScroller.java
index d814eb3..52d5c36 100644
--- a/android/sdk/src/main/java/org/apache/weex/ui/component/WXScroller.java
+++ b/android/sdk/src/main/java/org/apache/weex/ui/component/WXScroller.java
@@ -124,6 +124,7 @@ public class WXScroller extends WXVContainer<ViewGroup> implements WXScrollViewL
   private FrameLayout mScrollerView;
 
   private int mContentHeight = 0;
+  private int mContentWidth = 0;
 
   private WXStickyHelper stickyHelper;
   private Handler handler=new Handler(Looper.getMainLooper());
@@ -478,6 +479,7 @@ public class WXScroller extends WXVContainer<ViewGroup> implements WXScrollViewL
         @Override
         public void onScrollChanged(WXHorizontalScrollView scrollView, int x, int y, int oldx, int oldy) {
           procAppear(x,y,oldx,oldy);
+          onLoadMore(scrollView,x,y);
         }
       });
       FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
@@ -970,7 +972,7 @@ public class WXScroller extends WXVContainer<ViewGroup> implements WXScrollViewL
    * @param x the X direction
    * @param y the Y direction
    */
-  protected void onLoadMore(WXScrollView scrollView, int x, int y) {
+  protected void onLoadMore(FrameLayout scrollView, int x, int y) {
     try {
       String offset = getAttrs().getLoadMoreOffset();
       if (TextUtils.isEmpty(offset)) {
@@ -978,18 +980,28 @@ public class WXScroller extends WXVContainer<ViewGroup> implements WXScrollViewL
       }
       int offsetInt = (int)WXViewUtils.getRealPxByWidth(Float.parseFloat(offset), getInstance().getInstanceViewPortWidth());
 
-      int contentH = scrollView.getChildAt(0).getHeight();
-      int scrollerH = scrollView.getHeight();
-      int offScreenY = contentH - y - scrollerH;
-      if (offScreenY < offsetInt) {
-        if (WXEnvironment.isApkDebugable()) {
-          WXLogUtils.d("[WXScroller-onScroll] offScreenY :" + offScreenY);
-        }
-        if (mContentHeight != contentH || mForceLoadmoreNextTime) {
+      if (scrollView instanceof WXHorizontalScrollView){
+        int contentWidth = scrollView.getChildAt(0).getWidth();
+        int offScreenX =  contentWidth-x-scrollView.getWidth();
+        if (offScreenX < offsetInt && (mContentWidth != contentWidth || mForceLoadmoreNextTime)){
           fireEvent(Constants.Event.LOADMORE);
-          mContentHeight = contentH;
+          mContentWidth=contentWidth;
           mForceLoadmoreNextTime = false;
         }
+      }else {
+        int contentH = scrollView.getChildAt(0).getHeight();
+        int scrollerH = scrollView.getHeight();
+        int offScreenY = contentH - y - scrollerH;
+        if (offScreenY < offsetInt) {
+          if (WXEnvironment.isApkDebugable()) {
+            WXLogUtils.d("[WXScroller-onScroll] offScreenY :" + offScreenY);
+          }
+          if (mContentHeight != contentH || mForceLoadmoreNextTime) {
+            fireEvent(Constants.Event.LOADMORE);
+            mContentHeight = contentH;
+            mForceLoadmoreNextTime = false;
+          }
+        }
       }
     } catch (Exception e) {
       WXLogUtils.d("[WXScroller-onScroll] ", e);