com.taobao.weex.ui.component.WXVContainer Java Examples

The following examples show how to use com.taobao.weex.ui.component.WXVContainer. 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: WXRenderStatement.java    From weex with Apache License 2.0 6 votes vote down vote up
WXComponent createBodyOnDomThread(WXDomObject dom) {
  if (mWXSDKInstance == null) {
    return null;
  }
  WXDomObject domObject = new WXDomObject();
  domObject.type = WXBasicComponentType.DIV;
  domObject.ref = "god";
  mGodComponent = (WXVContainer) WXComponentFactory.newInstance(mWXSDKInstance, domObject, null);
  mGodComponent.createView(null, -1);
  if (mGodComponent == null) {
    if (WXEnvironment.isApkDebugable()) {
      WXLogUtils.e("rootView failed!");
    }
    //TODO error callback
    return null;
  }
  FrameLayout frameLayout = (FrameLayout) mGodComponent.getView();
  ViewGroup.LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
  frameLayout.setLayoutParams(layoutParams);
  frameLayout.setBackgroundColor(Color.TRANSPARENT);

  WXComponent component = generateComponentTree(dom, mGodComponent);
  mGodComponent.addChild(component);
  mRegistry.put(component.getRef(), component);
  return component;
}
 
Example #2
Source File: WXParallax.java    From incubator-weex-playground with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isNeedScroller(String ref, Object option) {

  mBindingRef = (String) (getAttrs().get(BINDING_SCROLLER));
  if (TextUtils.isEmpty(mBindingRef)) {
    WXComponent root = getInstance().getRootComponent();
    if (root != null && root instanceof WXVContainer) {
      Scrollable scrollable = root.getFirstScroller();
      if (scrollable != null) {
        mBindingRef = scrollable.getRef();
      }
    }
  }
  if (!TextUtils.isEmpty(mBindingRef)
      && !TextUtils.isEmpty(ref)
      && ref.equals(mBindingRef)) {
    return true;
  }
  return false;
}
 
Example #3
Source File: DOMActionContextImpl.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
/**
 * Update the specified component's dom and mark it as old.
 * @param component the component to be updated
 */
private void updateDomObj(WXComponent component) {
  if (component == null) {
    return;
  }
  WXDomObject domObject = mRegistry.get(component.getRef());
  if (domObject == null) {
    return;
  }
  domObject.old();
  component.updateDom(domObject);
  if (component instanceof WXVContainer) {
    WXVContainer container = (WXVContainer) component;
    int count = container.childCount();
    for (int i = 0; i < count; ++i) {
      updateDomObj(container.getChild(i));
    }
  }
}
 
Example #4
Source File: SimpleComponentHolder.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
private void loadConstructor(){
  Class<? extends WXComponent> c = mCompClz;
  Constructor<? extends WXComponent> constructor;
  try {
    constructor = c.getConstructor(WXSDKInstance.class, WXDomObject.class, WXVContainer.class);
  } catch (NoSuchMethodException e) {
    WXLogUtils.d("ClazzComponentCreator","Use deprecated component constructor");
    try {
      //compatible deprecated constructor with 4 args
      constructor = c.getConstructor(WXSDKInstance.class, WXDomObject.class, WXVContainer.class, boolean.class);
    } catch (NoSuchMethodException e1) {
      try {
        //compatible deprecated constructor with 5 args
        constructor = c.getConstructor(WXSDKInstance.class, WXDomObject.class, WXVContainer.class,String.class, boolean.class);
      } catch (NoSuchMethodException e2) {
        throw new WXRuntimeException("Can't find constructor of component.");
      }
    }
  }
  mConstructor = constructor;
}
 
Example #5
Source File: SimpleComponentHolder.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
public WXComponent createInstance(WXSDKInstance instance, WXDomObject node, WXVContainer parent) throws IllegalAccessException, InvocationTargetException, InstantiationException {
  if(mConstructor == null){
    loadConstructor();
  }
  int parameters = mConstructor.getParameterTypes().length;
  WXComponent component;

  if(parameters == 3){
    component =  mConstructor.newInstance(instance,node,parent);
  }else if(parameters == 4){
    component =  mConstructor.newInstance(instance,node,parent,false);
  }else{
    //compatible deprecated constructor
    component =  mConstructor.newInstance(instance,node,parent,instance.getInstanceId(),parent.isLazy());
  }
  return component;
}
 
Example #6
Source File: SimpleComponentHolder.java    From weex-uikit with MIT License 6 votes vote down vote up
private void loadConstructor(){
  Class<? extends WXComponent> c = mCompClz;
  Constructor<? extends WXComponent> constructor;
  try {
    constructor = c.getConstructor(WXSDKInstance.class, WXDomObject.class, WXVContainer.class);
  } catch (NoSuchMethodException e) {
    WXLogUtils.d("ClazzComponentCreator","Use deprecated component constructor");
    try {
      //compatible deprecated constructor with 4 args
      constructor = c.getConstructor(WXSDKInstance.class, WXDomObject.class, WXVContainer.class, boolean.class);
    } catch (NoSuchMethodException e1) {
      try {
        //compatible deprecated constructor with 5 args
        constructor = c.getConstructor(WXSDKInstance.class, WXDomObject.class, WXVContainer.class,String.class, boolean.class);
      } catch (NoSuchMethodException e2) {
        throw new WXRuntimeException("Can't find constructor of component.");
      }
    }
  }
  mConstructor = constructor;
}
 
Example #7
Source File: WXRenderStatement.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * Clear registry information that current instance contains.
 */
private void clearRegistryForComponent(WXComponent component) {
  WXComponent removedComponent = mRegistry.remove(component.getDomObject().getRef());
  if (removedComponent != null) {
    removedComponent.removeAllEvent();
    removedComponent.removeStickyStyle();
  }
  if (component instanceof WXVContainer) {
    WXVContainer container = (WXVContainer) component;
    int count = container.childCount();
    for (int i = count - 1; i >= 0; --i) {
      clearRegistryForComponent(container.getChild(i));
    }
  }

}
 
Example #8
Source File: WXRenderStatement.java    From weex with Apache License 2.0 6 votes vote down vote up
/**
 * Clear registry information that current instance contains.
 */
private void clearRegistryForComponent(WXComponent component) {
  WXComponent removedComponent = mRegistry.remove(component.getDomObject().ref);
  if (removedComponent != null) {
    removedComponent.removeAllEvent();
    removedComponent.removeStickyStyle();
  }
  if (component instanceof WXVContainer) {
    WXVContainer container = (WXVContainer) component;
    int count = container.childCount();
    for (int i = count - 1; i >= 0; --i) {
      clearRegistryForComponent(container.getChild(i));
    }
  }

}
 
Example #9
Source File: DomTracker.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
private int getComponentNumOfNode(@NonNull WXComponent rootNode) {
    Deque<WXComponent> deque = new ArrayDeque<>();
    deque.add(rootNode);
    int viewNum = 0;
    while (!deque.isEmpty()) {
        WXComponent node = deque.removeFirst();
        viewNum++;
        if (node instanceof WXVContainer) {
            WXVContainer container = (WXVContainer) node;
            for (int i = 0, count = container.childCount(); i < count; i++) {
                deque.add(container.getChild(i));
            }
        }
    }
    return viewNum;
}
 
Example #10
Source File: ComponentHolder.java    From weex with Apache License 2.0 6 votes vote down vote up
public WXComponent createInstance(WXSDKInstance instance, WXDomObject node, WXVContainer parent, boolean lazy) throws IllegalAccessException, InvocationTargetException, InstantiationException {
  if(mConstructor == null){
    generate();
  }
  int parameters = mConstructor.getParameterTypes().length;
  WXComponent component;
  if(parameters == 4){
    component =  mConstructor.newInstance(instance,node,parent,lazy);
  }else{
    //compatible deprecated constructor
    component =  mConstructor.newInstance(instance,node,parent,instance.getInstanceId(),lazy);
  }

  component.setHolder(this);
  return component;
}
 
Example #11
Source File: WXDomStatement.java    From weex with Apache License 2.0 6 votes vote down vote up
/**
 * Update the specified component's dom and mark it as old.
 * @param component the component to be updated
 */
private void updateDomObj(WXComponent component) {
  if (component == null) {
    return;
  }
  WXDomObject domObject = mRegistry.get(component.getRef());
  if (domObject == null) {
    return;
  }
  domObject.old();
  component.updateDom(domObject.clone());
  if (component instanceof WXVContainer) {
    WXVContainer container = (WXVContainer) component;
    int count = container.childCount();
    for (int i = 0; i < count; ++i) {
      updateDomObj(container.getChild(i));
    }
  }
}
 
Example #12
Source File: WXRenderStatement.java    From weex-uikit with MIT License 6 votes vote down vote up
private WXComponent generateComponentTree(WXDomObject dom, WXVContainer parent) {
  if (dom == null ) {
    return null;
  }
  WXComponent component = WXComponentFactory.newInstance(mWXSDKInstance, dom,parent);

  mRegistry.put(dom.getRef(), component);
  if (component instanceof WXVContainer) {
    WXVContainer parentC = (WXVContainer) component;
    int count = dom.childCount();
    WXDomObject child = null;
    for (int i = 0; i < count; ++i) {
      child = dom.getChild(i);
      if (child != null) {
        parentC.addChild(generateComponentTree(child, parentC));
      }
    }
  }

  return component;
}
 
Example #13
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 #14
Source File: WXSvgContainer.java    From Svg-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
public WXSvgContainer(WXSDKInstance instance, WXDomObject dom, WXVContainer parent) {
  super(instance, dom, parent);
  mDom = dom;
  Log.v("WXSvgContainer", mDom.getAttrs().values().toString());
  if (mDom.getStyles().get(Constants.Name.HEIGHT) == null) {
    mDom.getStyles().put(Constants.Name.HEIGHT, "0");
  }
  if (mDom.getStyles().get(Constants.Name.WIDTH) == null) {
    mDom.getStyles().put(Constants.Name.WIDTH, "0");
  }
  mScale = (float) (WXViewUtils.getScreenWidth(parent.getContext()) * 1.0 / dom.getViewPortWidth());
}
 
Example #15
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 #16
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 #17
Source File: ExternalLoaderComponentHolder.java    From weex-uikit with MIT License 5 votes vote down vote up
@Override
public synchronized WXComponent createInstance(WXSDKInstance instance, WXDomObject node, WXVContainer parent) throws IllegalAccessException, InvocationTargetException, InstantiationException {
  if(mClass == null){
    mClass = mClzGetter.getExternalComponentClass(mType,instance);
  }
  ComponentCreator creator = new SimpleComponentHolder.ClazzComponentCreator(mClass);
  WXComponent component = creator.createInstance(instance,node,parent);

  component.bindHolder(this);
  return component;
}
 
Example #18
Source File: WXRenderStatement.java    From weex-uikit with MIT License 5 votes vote down vote up
@Nullable WXComponent createComponentOnDomThread(WXDomObject dom, String parentRef, int index) {
  WXComponent comp = mRegistry.get(parentRef);
  if(comp == null || !(comp instanceof WXVContainer)){
    return null;
  }
  return generateComponentTree(dom, (WXVContainer) comp);
}
 
Example #19
Source File: WXRenderStatement.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * @see com.taobao.weex.dom.WXDomStatement#addDom(JSONObject, String, int)
 */
void addComponent(WXComponent component, String parentRef, int index) {
  WXVContainer parent = (WXVContainer) mRegistry.get(parentRef);
  if (parent == null || component == null) {
    return;
  }
  component.createView(parent, index);
  component.applyLayoutAndEvent(component);
  component.bindData(component);
  parent.addChild(component, index);
  WXAnimationModule.applyTransformStyle(component.mDomObj.style, component);
}
 
Example #20
Source File: ComponentHolder.java    From weex with Apache License 2.0 5 votes vote down vote up
private synchronized void generate(){
  WXLogUtils.d(TAG,"Generate Component:"+mClz.getSimpleName());
  HashMap<String, Invoker> methods = new HashMap<>();

  Annotation[] annotations;
  Annotation anno;
  for (Method method : mClz.getMethods()) {
    annotations = method.getDeclaredAnnotations();
    for (int i = 0,annotationsCount = annotations.length;
         i < annotationsCount; ++i) {
      anno = annotations[i];
      if (anno != null && anno instanceof WXComponentProp) {
        String name = ((WXComponentProp) anno).name();
        methods.put(name, new MethodInvoker(method));
        break;
      }
    }
  }

  mMethods = methods;
  try {
    mConstructor = mClz.getConstructor(WXSDKInstance.class, WXDomObject.class, WXVContainer.class, boolean.class);
  } catch (NoSuchMethodException e) {
    try {
      //compatible deprecated constructor
      mConstructor = mClz.getConstructor(WXSDKInstance.class, WXDomObject.class, WXVContainer.class,String.class, boolean.class);
    } catch (NoSuchMethodException e1) {
      e1.printStackTrace();
      throw new WXRuntimeException("Can't find constructor of component.");
    }
    e.printStackTrace();
  }
}
 
Example #21
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 #22
Source File: AddElementAction.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Override
protected WXComponent createComponent(DOMActionContext context, WXDomObject domObject) {
  WXComponent comp = context.getCompByRef(mParentRef);
  if (comp == null || !(comp instanceof WXVContainer)) {
    return null;
  }
  return generateComponentTree(context, domObject, (WXVContainer) comp);
}
 
Example #23
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 #24
Source File: RemoveElementAction.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
private void clearRegistryForComponent(RenderActionContext context, WXComponent component) {
  WXComponent removedComponent = context.unregisterComponent(component.getDomObject().getRef());
  if (removedComponent != null) {
    removedComponent.removeAllEvent();
    removedComponent.removeStickyStyle();
  }
  if (component instanceof WXVContainer) {
    WXVContainer container = (WXVContainer) component;
    int count = container.childCount();
    for (int i = count - 1; i >= 0; --i) {
      clearRegistryForComponent(context, container.getChild(i));
    }
  }

}
 
Example #25
Source File: BasicListComponent.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Nullable
private WXComponent findComponentByAnchorName(@NonNull WXComponent root, @NonNull String anchorName) {
  long start = 0;
  if (WXEnvironment.isApkDebugable()) {
    start = System.currentTimeMillis();
  }

  Deque<WXComponent> deque = new ArrayDeque<>();
  deque.add(root);
  while (!deque.isEmpty()) {
    WXComponent curComponent = deque.removeFirst();
    ImmutableDomObject object = curComponent.getDomObject();
    if (object != null) {
      String isAnchorSet = WXUtils.getString(object.getAttrs().get(anchorName), null);

      //hit
      if (isAnchorSet != null && isAnchorSet.equals("true")) {
        if (WXEnvironment.isApkDebugable()) {
          WXLogUtils.d("dragPerf", "findComponentByAnchorName time: " + (System.currentTimeMillis() - start) + "ms");
        }
        return curComponent;
      }
    }
    if (curComponent instanceof WXVContainer) {
      WXVContainer container = (WXVContainer) curComponent;
      for (int i = 0, len = container.childCount(); i < len; i++) {
        WXComponent child = container.getChild(i);
        deque.add(child);
      }
    }
  }

  if (WXEnvironment.isApkDebugable()) {
    WXLogUtils.d("dragPerf", "findComponentByAnchorName elapsed time: " + (System.currentTimeMillis() - start) + "ms");
  }
  return null;

}
 
Example #26
Source File: SimpleComponentHolder.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized WXComponent createInstance(WXSDKInstance instance, WXDomObject node, WXVContainer parent) throws IllegalAccessException, InvocationTargetException, InstantiationException {
  WXComponent component = mCreator.createInstance(instance,node,parent);

  component.bindHolder(this);
  return component;
}
 
Example #27
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 #28
Source File: WXRenderStatement.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * @see com.taobao.weex.dom.WXDomStatement#addDom(JSONObject, String, int)
 */
void addComponent(WXDomObject dom, String parentRef, int index) {
  WXVContainer parent = (WXVContainer) mRegistry.get(parentRef);
  WXComponent component = generateComponentTree(dom, parent);
  parent.addChild(component, index);
  WXAnimationModule.applyTransformStyle(dom.style, component);
}
 
Example #29
Source File: WXListComponent.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public WXListComponent(WXSDKInstance instance, WXDomObject node, WXVContainer parent, boolean lazy) {
  super(instance, node, parent);
  if (node != null && node instanceof WXRecyclerDomObject) {
    mDomObject = (WXRecyclerDomObject) node;
    mDomObject.preCalculateCellWidth();

    if(WXBasicComponentType.WATERFALL.equals(node.getType())){
      mLayoutType = WXRecyclerView.TYPE_STAGGERED_GRID_LAYOUT;
    }else{
      mLayoutType = mDomObject.getLayoutType();
    }
    updateRecyclerAttr();

  }
}
 
Example #30
Source File: WXParallax.java    From incubator-weex-playground with Apache License 2.0 5 votes vote down vote up
public WXParallax(WXSDKInstance instance, WXVContainer parent, BasicComponentData basicComponentData) {
  super(instance, parent, basicComponentData);
  initTransform(getAttrs().get(WX_TRANSFORM));
  initOpacity(getAttrs().get(Constants.Name.OPACITY));
  initBackgroundColor(getAttrs().get(Constants.Name.BACKGROUND_COLOR));

  mBindingRef = (String) (getAttrs().get(BINDING_SCROLLER));
  instance.registerOnWXScrollListener(this);
}