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

The following examples show how to use com.taobao.weex.ui.component.WXComponent#getParent() . 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: WXSvgAbsComponent.java    From Svg-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
protected WXSvgContainer getSvgComponent() {
  if (mSvgShadowNode != null) {
    return mSvgShadowNode;
  }

  WXComponent parent = getParent();

  while (!(parent instanceof WXSvgContainer)) {
    if (parent == null) {
      return null;
    } else {
      parent = parent.getParent();
    }
  }
  mSvgShadowNode = (WXSvgContainer) parent;
  return mSvgShadowNode;
}
 
Example 2
Source File: MoveElementAction.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Override
public void executeRender(RenderActionContext context) {
  WXComponent component = context.getComponent(mRef);
  WXComponent newParent = context.getComponent(mParentRef);
  if (component == null || component.getParent() == null
      || newParent == null || !(newParent instanceof WXVContainer)) {
    return;
  }
  WXVContainer oldParent = component.getParent();
  oldParent.remove(component,false);
  ((WXVContainer) newParent).addChild(component, mNewIndex);
}
 
Example 3
Source File: RemoveElementAction.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Override
public void executeRender(RenderActionContext context) {
  WXComponent component = context.getComponent(mRef);
  if (component == null || component.getParent() == null) {
    return;
  }
  WXVContainer parent = component.getParent();
  clearRegistryForComponent(context, component);
  parent.remove(component, true);
  context.unregisterComponent(mRef);
}
 
Example 4
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 5
Source File: BasicListComponent.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
private
@Nullable
WXComponent findDirectListChild(WXComponent comp) {
  WXComponent parent;
  if (comp == null || (parent = comp.getParent()) == null) {
    return null;
  }

  if (parent instanceof BasicListComponent) {
    return comp;
  }

  return findDirectListChild(parent);
}
 
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: WXRenderStatement.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 *@see com.taobao.weex.dom.WXDomStatement#removeDom(String)
 */
WXComponent removeComponent(String ref) {
  WXComponent component = mRegistry.get(ref);
  if (component == null || component.getParent() == null) {
    return component;
  }
  WXVContainer parent = component.getParent();
  clearRegistryForComponent(component);
  parent.remove(component,true);
  mRegistry.remove(ref);
  return component;
}
 
Example 8
Source File: WXRenderStatement.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * @see com.taobao.weex.dom.WXDomStatement#moveDom(String, String, int)
 */
void move(String ref, String parentRef, int index) {
  WXComponent component = mRegistry.get(ref);
  WXComponent newParent = mRegistry.get(parentRef);
  if (component == null || component.getParent() == null
      || newParent == null || !(newParent instanceof WXVContainer)) {
    return;
  }
  WXVContainer oldParent = component.getParent();
  oldParent.remove(component,false);
  ((WXVContainer) newParent).addChild(component, index);
}
 
Example 9
Source File: BasicListComponent.java    From weex-uikit with MIT License 5 votes vote down vote up
private
@Nullable
WXComponent findDirectListChild(WXComponent comp) {
  WXComponent parent;
  if (comp == null || (parent = comp.getParent()) == null) {
    return null;
  }

  if (parent instanceof WXListComponent) {
    return comp;
  }

  return findDirectListChild(parent);
}
 
Example 10
Source File: WXRenderStatement.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 *@see com.taobao.weex.dom.WXDomStatement#removeDom(String)
 */
WXComponent removeComponent(String ref) {
  WXComponent component = mRegistry.get(ref);
  if (component == null || component.getParent() == null) {
    return component;
  }
  WXVContainer parent = component.getParent();
  clearRegistryForComponent(component);
  parent.remove(component);
  component.destroy();
  return component;
}
 
Example 11
Source File: WXRenderStatement.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * @see com.taobao.weex.dom.WXDomStatement#moveDom(String, String, int)
 */
void move(String ref, String parentRef, int index) {
  WXComponent component = mRegistry.get(ref);
  WXComponent newParent = mRegistry.get(parentRef);
  if (component == null || component.getParent() == null
      || newParent == null || !(newParent instanceof WXVContainer)) {
    return;
  }
  WXVContainer oldParent = component.getParent();
  oldParent.remove(component,false);
  ((WXVContainer) newParent).addChild(component, index);
}
 
Example 12
Source File: BasicListComponent.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
@Override
public void scrollTo(WXComponent component, Map<String, Object> options) {
  float offsetFloat = 0;
  boolean smooth = true;

  if (options != null) {
    String offsetStr = options.get(Constants.Name.OFFSET) == null ? "0" : options.get(Constants.Name.OFFSET).toString();
    smooth = WXUtils.getBoolean(options.get(Constants.Name.ANIMATED), true);
    if (offsetStr != null) {
      try {
        offsetFloat = WXViewUtils.getRealPxByWidth(Float.parseFloat(offsetStr), getInstance().getInstanceViewPortWidth());
      }catch (Exception e ){
        WXLogUtils.e("Float parseFloat error :"+e.getMessage());
      }
    }
  }

  final int offset = (int) offsetFloat;

  T bounceRecyclerView = getHostView();
  if (bounceRecyclerView == null) {
    return;
  }

  WXComponent parent = component;
  WXCell cell = null;
  while (parent != null) {
    if (parent instanceof WXCell) {
      cell = (WXCell) parent;
      break;
    }
    parent = parent.getParent();
  }

  if (cell != null) {
    final int pos = mChildren.indexOf(cell);
    final WXRecyclerView view = bounceRecyclerView.getInnerView();

    if (!smooth) {
      RecyclerView.LayoutManager layoutManager = view.getLayoutManager();
      if (layoutManager instanceof LinearLayoutManager) {
        //GridLayoutManager is also instance of LinearLayoutManager
        ((LinearLayoutManager) layoutManager).scrollToPositionWithOffset(pos, -offset);
      } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        ((StaggeredGridLayoutManager) layoutManager).scrollToPositionWithOffset(pos, -offset);
      }
      //Any else?
    } else {
      view.smoothScrollToPosition(pos);
      if (offset != 0) {
        view.addOnScrollListener(new RecyclerView.OnScrollListener() {
          @Override
          public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_IDLE) {
              if (getOrientation() == Constants.Orientation.VERTICAL) {
                recyclerView.smoothScrollBy(0, offset);
              } else {
                recyclerView.smoothScrollBy(offset, 0);
              }
              recyclerView.removeOnScrollListener(this);
            }
          }
        });
      }
    }
  }
}
 
Example 13
Source File: BasicListComponent.java    From weex-uikit with MIT License 4 votes vote down vote up
@Override
public void scrollTo(WXComponent component, final int offset) {
  if (bounceRecyclerView == null) {
    return;
  }

  WXComponent parent = component;
  WXCell cell = null;
  while (parent != null) {
    if (parent instanceof WXCell) {
      cell = (WXCell) parent;
      break;
    }
    parent = parent.getParent();
  }
  if (cell != null) {
    int pos = mChildren.indexOf(cell);
    final WXRecyclerView view = bounceRecyclerView.getInnerView();
    view.scrollToPosition(pos);
    final WXComponent cellComp = cell;
    //scroll cell to top
    view.postDelayed(new Runnable() {
      @Override
      public void run() {
        if (cellComp.getHostView() == null) {
          return;
        }
        View cellView = cellComp.getHostView();
        if (getOrientation() == Constants.Orientation.VERTICAL) {
          int scrollY = cellView.getTop() + offset;
          view.smoothScrollBy(0, scrollY);
        } else {
          int scrollX = cellView.getLeft() + offset;
          view.smoothScrollBy(scrollX, 0);
        }
      }
    }, 50);

  }

}
 
Example 14
Source File: WXRenderStatement.java    From weex with Apache License 2.0 4 votes vote down vote up
/**
 * @see com.taobao.weex.dom.WXDomStatement#scrollToDom(String, JSONObject)
 */
void scrollTo(String ref, Map<String, Object> options) {
  WXComponent component = mRegistry.get(ref);
  if (component == null) {
    return;
  }

  int offsetInt = 0;
  if (options != null) {
    String offset = options.get("offset") == null ? "0" : options.get("offset").toString();
    if (offset != null) {
      offsetInt = Integer.parseInt(offset);
    }
  }

  WXScroller scroller = component.getParentScroller();
  if (scroller == null) {
    return;
  }
  int offsetIntF = (int) WXViewUtils.getRealPxByWidth(offsetInt);
  int[] scrollerP = new int[2];
  scroller.getView().getLocationOnScreen(scrollerP);
  if (scrollerP[1] == component.getAbsoluteY() && scroller.getView() instanceof WXScrollView) {
    return;
  }

  if(scrollerP[0] == component.getAbsoluteX() && scroller.getView() instanceof WXHorizontalScrollView){
    return;
  }

  int viewYInScroller=component.getAbsoluteY();
  int viewXInScroller=component.getAbsoluteX();
  WXComponent ancestor=component;
  while((ancestor=ancestor.getParent())!=null){
    if(ancestor instanceof WXScroller){
      viewYInScroller-=ancestor.getAbsoluteY();
      viewXInScroller-=ancestor.getAbsoluteX();
    }
  }
  scroller.scrollBy(scroller.getView().getScrollX()-viewXInScroller-offsetIntF,
                    scroller.getView().getScrollY() - viewYInScroller - offsetIntF);
}