Beispiel #1
0
  @Override
  public void onBeforeScroll(int dx, int dy) {
    if (mStickyMap == null) {
      return;
    }
    HashMap<String, WXComponent> stickyMap = mStickyMap.get(getRef());
    if (stickyMap == null) {
      return;
    }
    Iterator<Map.Entry<String, WXComponent>> iterator = stickyMap.entrySet().iterator();
    Map.Entry<String, WXComponent> entry;
    WXComponent stickyComponent;
    while (iterator.hasNext()) {
      entry = iterator.next();
      stickyComponent = entry.getValue();

      if (stickyComponent != null
          && stickyComponent.getDomObject() != null
          && stickyComponent instanceof WXCell) {
        if (stickyComponent.getHostView() == null) {
          return;
        }

        int[] location = new int[2];
        stickyComponent.getHostView().getLocationOnScreen(location);
        int[] parentLocation = new int[2];
        stickyComponent.getParentScroller().getView().getLocationOnScreen(parentLocation);

        int top = location[1] - parentLocation[1];

        boolean showSticky = ((WXCell) stickyComponent).lastLocationY > 0 && top <= 0 && dy > 0;
        boolean removeSticky = ((WXCell) stickyComponent).lastLocationY <= 0 && top > 0 && dy < 0;
        if (showSticky) {
          bounceRecyclerView.notifyStickyShow((WXCell) stickyComponent);
        } else if (removeSticky) {
          bounceRecyclerView.notifyStickyRemove((WXCell) stickyComponent);
        }
        ((WXCell) stickyComponent).lastLocationY = top;
      }
    }
  }
Beispiel #2
0
 /**
  * Check last Sticky after scrollTo
  *
  * @param position scroll to position
  */
 public void checkLastSticky(final int position) {
   bounceRecyclerView.clearSticky();
   for (int i = 0; i <= position; i++) {
     WXComponent component = getChild(i);
     if (component.isSticky() && component instanceof WXCell) {
       if (component.getHostView() == null) {
         return;
       }
       bounceRecyclerView.notifyStickyShow((WXCell) component);
     }
   }
 }
Beispiel #3
0
  @Override
  public void notifyAppearStateChange(
      int firstVisible, int lastVisible, int directionX, int directionY) {
    // notify appear state
    Iterator<AppearanceHelper> it = mAppearComponents.values().iterator();
    String direction = directionY > 0 ? "up" : "down";
    if (getOrientation() == Constants.Orientation.HORIZONTAL) {
      direction = directionX > 0 ? "left" : "right";
    }

    while (it.hasNext()) {
      AppearanceHelper item = it.next();
      WXComponent component = item.getAwareChild();

      if (!item.isWatch()) {
        continue;
      }

      boolean outOfVisibleRange =
          item.getCellPositionINScollable() < firstVisible
              || item.getCellPositionINScollable() > lastVisible;

      View view = component.getHostView();
      if (view == null) {
        continue;
      }

      boolean visible = (!outOfVisibleRange) && item.isViewVisible();

      int result = item.setAppearStatus(visible);
      if (WXEnvironment.isApkDebugable()) {
        WXLogUtils.d("appear", "item " + item.getCellPositionINScollable() + " result " + result);
      }
      if (result == AppearanceHelper.RESULT_NO_CHANGE) {
        continue;
      }
      component.notifyAppearStateChange(
          result == AppearanceHelper.RESULT_APPEAR
              ? Constants.Event.APPEAR
              : Constants.Event.DISAPPEAR,
          direction);
    }
  }
Beispiel #4
0
  /** @param loading should be {@link WXRefreshView} */
  public void setFooterView(WXComponent loading) {
    setLoadmoreEnable(true);
    if (swipeLayout != null) {
      if (swipeLayout.getFooterView() != null) {
        swipeLayout.setLoadingHeight((int) loading.getDomObject().getLayoutHeight());

        String colorStr =
            (String) loading.getDomObject().getStyles().get(Constants.Name.BACKGROUND_COLOR);
        String bgColor = WXUtils.getString(colorStr, null);

        if (bgColor != null) {
          if (!TextUtils.isEmpty(bgColor)) {
            int colorInt = WXResourceUtils.getColor(bgColor);
            if (!(colorInt == Color.TRANSPARENT)) {
              swipeLayout.setLoadingBgColor(colorInt);
            }
          }
        }
        swipeLayout.getFooterView().setRefreshView(loading.getHostView());
      }
    }
  }