Java Code Examples for com.taobao.weex.ui.component.WXComponent#getHostView()

The following examples show how to use com.taobao.weex.ui.component.WXComponent#getHostView() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WXPageActivity.java    From incubator-weex-playground with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param map <weexid,viewId>
 */
private static void collectId(WXComponent comp, Map<String,String> map){
  if(comp == null){
    return;
  }
  String id;
  View view;
  if((view = comp.getHostView())!=null &&
      (id = (String) comp.getAttrs().get("testId"))!=null &&
      !map.containsKey(id)){
    Pair<String,Integer> pair = Utility.nextID();
    view.setId(pair.second);
    map.put(id,pair.first);
  }
  if(comp instanceof WXVContainer){
    WXVContainer container = (WXVContainer) comp;
    for(int i = container.getChildCount()-1;i>=0;i--){
      collectId(container.getChild(i),map);
    }
  }
}
 
Example 2
Source File: AnimationAction.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
private void startAnimation(@NonNull WXSDKInstance instance, @Nullable WXComponent component) {
  if (component != null) {
    if (mAnimationBean != null) {
      component.setNeedLayoutOnAnimation(mAnimationBean.needLayout);
    }
    if (component.getHostView() == null) {
      WXAnimationModule.AnimationHolder holder = new WXAnimationModule.AnimationHolder(mAnimationBean, callback);
      component.postAnimation(holder);
    } else {
      try {
        Animator animator = createAnimator(component.getHostView(), instance
            .getInstanceViewPortWidth());
        if (animator != null) {
          Animator.AnimatorListener animatorCallback = createAnimatorListener(instance, callback);
          if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2 && component
              .isLayerTypeEnabled() ) {
            component.getHostView().setLayerType(View.LAYER_TYPE_HARDWARE, null);
          }
          Interpolator interpolator = createTimeInterpolator();
          if (animatorCallback != null) {
            animator.addListener(animatorCallback);
          }
          if (interpolator != null) {
            animator.setInterpolator(interpolator);
          }
          animator.setDuration(mAnimationBean.duration);
          animator.start();
        }
      } catch (RuntimeException e) {
        WXLogUtils.e(TAG, WXLogUtils.getStackTrace(e));
      }
    }
  }
}
 
Example 3
Source File: WXScrollView.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
private View procSticky(Map<String, Map<String, WXComponent>> mStickyMap) {
  if (mStickyMap == null) {
    return null;
  }
  Map<String, WXComponent> stickyMap = mStickyMap.get(mWAScroller.getRef());
  if (stickyMap == null) {
    return null;
  }

  Iterator<Entry<String, WXComponent>> iterator = stickyMap.entrySet().iterator();
  Entry<String, WXComponent> entry = null;
  WXComponent stickyData;
  while (iterator.hasNext()) {
    entry = iterator.next();
    stickyData = entry.getValue();

    getLocationOnScreen(stickyScrollerP);
    stickyData.getHostView().getLocationOnScreen(stickyViewP);
    int parentH = 0;
    if(stickyData.getParent()!=null && stickyData.getParent().getRealView()!=null){
      parentH=stickyData.getParent().getRealView().getHeight();
    }
    int stickyViewH = stickyData.getHostView().getHeight();
    int stickyShowPos = stickyScrollerP[1];
    int stickyStartHidePos = -parentH + stickyScrollerP[1] + stickyViewH;
    if (stickyViewP[1] <= stickyShowPos && stickyViewP[1] >= (stickyStartHidePos - stickyViewH)) {
      mStickyOffset = stickyViewP[1] - stickyStartHidePos;
      stickyData.setStickyOffset(stickyViewP[1]-stickyScrollerP[1]);
      return stickyData.getHostView();
    }else{
      stickyData.setStickyOffset(0);
    }
  }
  return null;
}
 
Example 4
Source File: BasicListComponent.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@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 ? Constants.Value.DIRECTION_UP :
      directionY < 0 ? Constants.Value.DIRECTION_DOWN : null;
  if (getOrientation() == Constants.Orientation.HORIZONTAL && directionX != 0) {
    direction = directionX > 0 ? Constants.Value.DIRECTION_LEFT : Constants.Value.DIRECTION_RIGHT;
  }

  if (mColumnCount > 0)
    visibleCellCount = (lastVisible - firstVisible) * mColumnCount;

  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);
  }
}
 
Example 5
Source File: WXAnimationModule.java    From weex-uikit with MIT License 5 votes vote down vote up
public static void startAnimation(WXSDKInstance mWXSDKInstance, WXComponent component,
                                  @NonNull WXAnimationBean animationBean, @Nullable String callback) {
  if(component == null){
    return;
  }
  if (component.getHostView() == null) {
    AnimationHolder holder = new AnimationHolder(animationBean, callback);
    component.postAnimation(holder);
    return;
  }
  try {
    Animator animator = createAnimator(animationBean, component.getHostView(),mWXSDKInstance.getViewPortWidth());
    if (animator != null) {
      Animator.AnimatorListener animatorCallback = createAnimatorListener(mWXSDKInstance, callback);
      if(Build.VERSION.SDK_INT<Build.VERSION_CODES.JELLY_BEAN_MR2) {
        component.getHostView().setLayerType(View.LAYER_TYPE_HARDWARE, null);
      }
      Interpolator interpolator = createTimeInterpolator(animationBean);
      if (animatorCallback != null) {
        animator.addListener(animatorCallback);
      }
      if (interpolator != null) {
        animator.setInterpolator(interpolator);
      }
      animator.setDuration(animationBean.duration);
      animator.start();
    }
  } catch (RuntimeException e) {
    e.printStackTrace();
    WXLogUtils.e("", e);
  }
}
 
Example 6
Source File: WXScrollView.java    From weex-uikit with MIT License 5 votes vote down vote up
private View procSticky(Map<String, HashMap<String, WXComponent>> mStickyMap) {
  if (mStickyMap == null) {
    return null;
  }
  HashMap<String, WXComponent> stickyMap = mStickyMap.get(mWAScroller.getRef());
  if (stickyMap == null) {
    return null;
  }

  Iterator<Entry<String, WXComponent>> iterator = stickyMap.entrySet().iterator();
  Entry<String, WXComponent> entry = null;
  WXComponent stickyData;
  while (iterator.hasNext()) {
    entry = iterator.next();
    stickyData = entry.getValue();

    getLocationOnScreen(stickyScrollerP);
    stickyData.getHostView().getLocationOnScreen(stickyViewP);
    int parentH = 0;
    if(stickyData.getParent()!=null && stickyData.getParent().getRealView()!=null){
      parentH=stickyData.getParent().getRealView().getHeight();
    }
    int stickyViewH = stickyData.getHostView().getHeight();
    int stickyShowPos = stickyScrollerP[1];
    int stickyStartHidePos = -parentH + stickyScrollerP[1] + stickyViewH;
    if (stickyViewP[1] <= stickyShowPos && stickyViewP[1] >= (stickyStartHidePos - stickyViewH)) {
      mStickyOffset = stickyViewP[1] - stickyStartHidePos;
      return stickyData.getHostView();
    }
  }
  return null;
}
 
Example 7
Source File: BasicListComponent.java    From weex-uikit with MIT License 5 votes vote down vote up
@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 ? Constants.Value.DIRECTION_UP :
      directionY < 0 ? Constants.Value.DIRECTION_DOWN : null;
  if (getOrientation() == Constants.Orientation.HORIZONTAL && directionX != 0) {
    direction = directionX > 0 ? Constants.Value.DIRECTION_LEFT : Constants.Value.DIRECTION_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);
  }
}
 
Example 8
Source File: ProfileDomView.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
@Override
public void onTrackNode(@NonNull WXComponent component, int layer) {
    if(layer < MAX_VDOM_LAYER) {
        return;
    }
    View hostView = component.getHostView();
    if(hostView == null) {
        return;
    }

    if(mViewHighlighter != null) {
        mViewHighlighter.addHighlightedView(hostView);
    }
}
 
Example 9
Source File: ComponentHeightComputer.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
static int computeComponentContentHeight(@NonNull WXComponent component) {
    View view = component.getHostView();
    if(view == null) {
        return 0;
    }
    if(component instanceof WXListComponent) {
        WXListComponent listComponent = (WXListComponent) component;
        BounceRecyclerView bounceRecyclerView = listComponent.getHostView();
        if(bounceRecyclerView == null) {
            return 0;
        }
        WXRecyclerView innerView = bounceRecyclerView.getInnerView();
        if(innerView == null) {
            return bounceRecyclerView.getMeasuredHeight();
        } else {
            return innerView.computeVerticalScrollRange();
        }
    } else if(component instanceof WXScroller) {
        WXScroller scroller = (WXScroller) component;
        if(!ViewUtils.isVerticalScroller(scroller)) {
            return view.getMeasuredHeight();
        }
        ViewGroup group = scroller.getInnerView();
        if(group == null) {
            return view.getMeasuredHeight();
        }
        if(group.getChildCount() != 1) {
            return view.getMeasuredHeight();
        } else {
            return group.getChildAt(0).getMeasuredHeight();
        }
    } else {
        return view.getMeasuredHeight();
    }
}
 
Example 10
Source File: PollingVDomMonitor.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
@Override
public void onTrackNode(@NonNull WXComponent component, int layer) {
    if(layer < MAX_VDOM_LAYER) {
        return;
    }
    View hostView = component.getHostView();
    if(hostView == null) {
        return;
    }

    if(mViewHighlighter != null) {
        mViewHighlighter.addHighlightedView(hostView);
    }
}
 
Example 11
Source File: ViewInspectorManager.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
@Nullable
private WXComponent findBoundComponentBy(@NonNull View targetView,@NonNull WXComponent rootComponent) {
    Deque<WXComponent> deque = new ArrayDeque<>();
    deque.add(rootComponent);
    WXComponent targetComponent = null;

    while (!deque.isEmpty()) {
        WXComponent component = deque.removeFirst();

        View view = component.getHostView();
        if(view != null && view.equals(targetView)) {
            targetComponent = component;
        }

        //we should take embed into account
        if(component instanceof WXEmbed) {
            WXComponent nestedRootComponent = ViewUtils.getNestedRootComponent((WXEmbed) component);
            if(nestedRootComponent != null) {
                deque.add(nestedRootComponent);
            }
        } else if(component instanceof WXVContainer) {
            WXVContainer container = (WXVContainer) component;
            for(int i = 0,len = container.getChildCount(); i < len; i++) {
                WXComponent c = container.getChild(i);
                deque.add(c);
            }
        }
    }

    return targetComponent;
}
 
Example 12
Source File: ListBaseViewHolder.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
public ListBaseViewHolder(WXComponent component, int viewType) {
  super(component.getHostView());
  mViewType = viewType;
  mComponent = new WeakReference(component);
}
 
Example 13
Source File: BasicListComponent.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
/**
 * Bind the component of the position to the holder. Then flush the view.
 *
 * @param holder   viewHolder, which holds reference to the view
 * @param position position of component in list
 */
@Override
public void onBindViewHolder(final ListBaseViewHolder holder, int position) {
  if (holder == null) return;
  holder.setComponentUsing(true);
  WXComponent component = getChild(position);
  if (component == null
      || (component instanceof WXRefresh)
      || (component instanceof WXLoading)
      || (component.getDomObject() != null && component.getDomObject().isFixed())
      ) {
    if (WXEnvironment.isApkDebugable()) {
      WXLogUtils.d(TAG, "Bind WXRefresh & WXLoading " + holder);
    }
    return;
  }

  if (holder.getComponent() != null && holder.getComponent() instanceof WXCell) {
    if(holder.isRecycled()) {
      holder.bindData(component);
    }
    if (mDragHelper == null || !mDragHelper.isDraggable()) {
      return;
    }
    mTriggerType = (mTriggerType == null) ? DEFAULT_TRIGGER_TYPE : mTriggerType;

    WXCell cell = (WXCell) holder.getComponent();
    boolean isExcluded = isDragExcluded(cell.getDomObject());
    mDragHelper.setDragExcluded(holder, isExcluded);

    //NOTICE: event maybe consumed by other views
    if (DragTriggerType.PAN.equals(mTriggerType)) {
      mDragHelper.setLongPressDragEnabled(false);

      WXComponent anchorComponent = findComponentByAnchorName(cell, DRAG_ANCHOR);

      if (anchorComponent != null && anchorComponent.getHostView() != null && !isExcluded) {
        View anchor = anchorComponent.getHostView();
        anchor.setOnTouchListener(new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
              mDragHelper.startDrag(holder);
            }
            return true;
          }
        });
      } else {
        if (WXEnvironment.isApkDebugable()) {
          if(!isExcluded) {
            WXLogUtils.e(TAG, "[error] onBindViewHolder: the anchor component or view is not found");
          } else {
            WXLogUtils.d(TAG, "onBindViewHolder: position "+ position + " is drag excluded");
          }
        }
      }

    } else if (DragTriggerType.LONG_PRESS.equals(mTriggerType)) {
      mDragHelper.setLongPressDragEnabled(true);
    }
  }

}
 
Example 14
Source File: ListBaseViewHolder.java    From weex-uikit with MIT License 4 votes vote down vote up
public ListBaseViewHolder(WXComponent component, int viewType) {
  super(component.getHostView());
  mViewType = viewType;
  mComponent = new WeakReference(component);
}
 
Example 15
Source File: BasicListComponent.java    From weex-uikit with MIT License 4 votes vote down vote up
@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) {

      WXCell cell = (WXCell) stickyComponent;
      if (cell.getHostView() == null) {
        return;
      }

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

        RecyclerView.LayoutManager layoutManager;
        boolean beforeFirstVisibleItem = false;
        if ((layoutManager = getHostView().getInnerView().getLayoutManager()) instanceof LinearLayoutManager) {
          int fVisible = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
          int pos = mChildren.indexOf(cell);

          if (pos <= fVisible) {
            beforeFirstVisibleItem = true;
          }
        }

        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 = beforeFirstVisibleItem && cell.getLocationFromStart() >= 0 && top <= 0 && dy >= 0;
        boolean removeSticky = cell.getLocationFromStart() <= 0 && top > 0 && dy <= 0;
        if (showSticky) {
          bounceRecyclerView.notifyStickyShow(cell);
        } else if (removeSticky) {
          bounceRecyclerView.notifyStickyRemove(cell);
        }
        cell.setLocationFromStart(top);
      }
    }
  }
}