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

The following examples show how to use com.taobao.weex.ui.component.WXComponent#createView() . 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-uikit with MIT License 6 votes vote down vote up
/**
 * create RootView ,every weex Instance View has a rootView;
 * @see com.taobao.weex.dom.WXDomStatement#createBody(JSONObject)
 */
void createBody(WXComponent component) {
  long start = System.currentTimeMillis();
  component.createView();
  if (WXEnvironment.isApkDebugable()) {
    WXLogUtils.renderPerformanceLog("createView", (System.currentTimeMillis() - start));
  }
  start = System.currentTimeMillis();
  component.applyLayoutAndEvent(component);
  component.bindData(component);

  if (WXEnvironment.isApkDebugable()) {
    WXLogUtils.renderPerformanceLog("bind", (System.currentTimeMillis() - start));
  }

  if (component instanceof WXScroller) {
    WXScroller scroller = (WXScroller) component;
    if (scroller.getInnerView() instanceof ScrollView) {
      mWXSDKInstance.setRootScrollView((ScrollView) scroller.getInnerView());
    }
  }
  mWXSDKInstance.onRootCreated(component);
  if (mWXSDKInstance.getRenderStrategy() != WXRenderStrategy.APPEND_ONCE) {
    mWXSDKInstance.onCreateFinish();
  }
}
 
Example 2
Source File: WXRenderStatement.java    From weex with Apache License 2.0 6 votes vote down vote up
/**
 * create RootView ,every weex Instance View has a rootView;
 * @see com.taobao.weex.dom.WXDomStatement#createBody(JSONObject)
 */
void createBody(WXComponent component) {
  long start = System.currentTimeMillis();
  component.createView(mGodComponent, -1);
  if (WXEnvironment.isApkDebugable()) {
    WXLogUtils.renderPerformanceLog("createView", (System.currentTimeMillis() - start));
  }
  start = System.currentTimeMillis();
  component.applyLayoutAndEvent(component);
  component.bindData(component);

  if (WXEnvironment.isApkDebugable()) {
    WXLogUtils.renderPerformanceLog("bind", (System.currentTimeMillis() - start));
  }

  if (component instanceof WXScroller) {
    WXScroller scroller = (WXScroller) component;
    if (scroller.getView() instanceof ScrollView) {
      mWXSDKInstance.setRootScrollView((ScrollView) scroller.getView());
    }
  }
  mWXSDKInstance.setRootView(mGodComponent.getRealView());
  if (mWXSDKInstance.getRenderStrategy() != WXRenderStrategy.APPEND_ONCE) {
    mWXSDKInstance.onViewCreated(mGodComponent);
  }
}
 
Example 3
Source File: WXListComponent.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Override
public void createChildViewAt(int index) {
  int indexToCreate = index;
  if (indexToCreate < 0) {
    indexToCreate = childCount() - 1;
    if (indexToCreate < 0) {
      return;
    }
  }
  final WXComponent child = getChild(indexToCreate);
  if (child instanceof WXBaseRefresh) {
    child.createView();
    if (child instanceof WXRefresh) {
      getHostView().setOnRefreshListener((WXRefresh) child);
      getHostView().postDelayed(new Runnable() {
        @Override
        public void run() {
          getHostView().setHeaderView(child);
        }
      }, 100);
    } else if (child instanceof WXLoading) {
      getHostView().setOnLoadingListener((WXLoading) child);
      getHostView().postDelayed(new Runnable() {
        @Override
        public void run() {
          getHostView().setFooterView(child);
        }
      }, 100);
    }
  } else {
    super.createChildViewAt(indexToCreate);
  }
}
 
Example 4
Source File: WXListComponent.java    From weex-uikit with MIT License 5 votes vote down vote up
@Override
public void createChildViewAt(int index) {
  int indexToCreate = index;
  if (indexToCreate < 0) {
    indexToCreate = childCount() - 1;
    if (indexToCreate < 0) {
      return;
    }
  }
  final WXComponent child = getChild(indexToCreate);
  if (child instanceof WXBaseRefresh) {
    child.createView();
    if (child instanceof WXRefresh) {
      getHostView().setOnRefreshListener((WXRefresh) child);
      getHostView().postDelayed(new Runnable() {
        @Override
        public void run() {
          getHostView().setHeaderView(child);
        }
      }, 100);
    } else if (child instanceof WXLoading) {
      getHostView().setOnLoadingListener((WXLoading) child);
      getHostView().postDelayed(new Runnable() {
        @Override
        public void run() {
          getHostView().setFooterView(child);
        }
      }, 100);
    }
  } else {
    super.createChildViewAt(indexToCreate);
  }
}
 
Example 5
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 6
Source File: WXListComponent.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Create an instance of {@link ListBaseViewHolder} for the given viewType (not for the given
 * index). This method will look up for the first component that fits the viewType requirement and
 * doesn't be used. Then create the certain type of view, detach the view f[rom the component.
 *
 * @param parent   the ViewGroup into which the new view will be inserted
 * @param viewType the type of the new view
 * @return the created view holder.
 */
@Override
public ListBaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    WXLogUtils.d(TAG, "onCreateViewHolder");
    if (mChildren != null) {
        for (int i = 0; i < childCount(); i++) {
            WXComponent component = getChild(i);
            setRefreshOrLoadingListener(component);
            if (component == null
                    || component.isUsing()
                    || getItemViewType(i) != viewType)
                continue;
            if (component instanceof WXRefresh) {
                bounceRecyclerView.setHeaderView(component.getView());
                return createVHForWXRefresh(component, viewType);
            } else if (component instanceof WXLoading) {
                bounceRecyclerView.setFooterView(component.getView());
                return createVHForWXLoading(component, viewType);
            } else if (component.mDomObj!=null && component.mDomObj.isFixed()) {
                return createVHForFakeComponent(viewType);
            } else {
                if (component.getRealView() != null) {
                    return new ListBaseViewHolder(component, viewType);
                } else {
                    long begin=System.currentTimeMillis();
                     component.lazy(false);
                     component.createView(this, -1);

                    WXLogUtils.d(TAG,"onCreateViewHolder lazy create:"+(System.currentTimeMillis()-begin)+"  Thread:"+Thread.currentThread().getName());
                    return new ListBaseViewHolder(component, viewType);
                }

            }
        }
    }
    WXLogUtils.e(TAG, "Cannot find request viewType: " + viewType);
    throw new WXRuntimeException("mChildren is null");
}
 
Example 7
Source File: BasicListComponent.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
/**
 * Create an instance of {@link ListBaseViewHolder} for the given viewType (not for the given
 * index). This  markComponentUsable();method will look up for the first component that fits the viewType requirement and
 * doesn't be used. Then create the certain type of view, detach the view f[rom the component.
 *
 * @param parent   the ViewGroup into which the new view will be inserted
 * @param viewType the type of the new view
 * @return the created view holder.
 */
@Override
public ListBaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  if (mChildren != null) {
    if (mViewTypes == null)
      return createVHForFakeComponent(viewType);
    ArrayList<WXComponent> mTypes = mViewTypes.get(viewType);
    checkRecycledViewPool(viewType);
    if (mTypes == null)
      return createVHForFakeComponent(viewType);

    for (int i = 0; i < mTypes.size(); i++) {
      WXComponent component = mTypes.get(i);
      if (component == null
          || component.isUsing()) {
        continue;
      }
      if (component.getDomObject() != null && component.getDomObject().isFixed()) {
        return createVHForFakeComponent(viewType);
      } else {
        if (component instanceof WXCell) {
          if (component.getRealView() != null) {
            return new ListBaseViewHolder(component, viewType);
          } else {
            ((WXCell) component).lazy(false);
            component.createView();
            component.applyLayoutAndEvent(component);
            return new ListBaseViewHolder(component, viewType);
          }
        } else if (component instanceof WXBaseRefresh) {
          return createVHForRefreshComponent(viewType);
        } else {
          WXLogUtils.e(TAG, "List cannot include element except cell、header、fixed、refresh and loading");
          return createVHForFakeComponent(viewType);
        }
      }
    }
  }
  if (WXEnvironment.isApkDebugable()) {
    WXLogUtils.e(TAG, "Cannot find request viewType: " + viewType);
  }
  return createVHForFakeComponent(viewType);
}
 
Example 8
Source File: BasicListComponent.java    From weex-uikit with MIT License 4 votes vote down vote up
/**
 * Create an instance of {@link ListBaseViewHolder} for the given viewType (not for the given
 * index). This method will look up for the first component that fits the viewType requirement and
 * doesn't be used. Then create the certain type of view, detach the view f[rom the component.
 *
 * @param parent   the ViewGroup into which the new view will be inserted
 * @param viewType the type of the new view
 * @return the created view holder.
 */
@Override
public ListBaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  if (mChildren != null) {
    if (mViewTypes == null)
      return createVHForFakeComponent(viewType);
    ArrayList<WXComponent> mTypes = mViewTypes.get(viewType);
    checkRecycledViewPool(viewType);
    if (mTypes == null)
      return createVHForFakeComponent(viewType);

    for (int i = 0; i < mTypes.size(); i++) {
      WXComponent component = mTypes.get(i);
      if (component == null
          || component.isUsing()) {
        continue;
      }
      if (component.getDomObject() != null && component.getDomObject().isFixed()) {
        return createVHForFakeComponent(viewType);
      } else {
        if (component instanceof WXCell) {
          if (component.getRealView() != null) {
            return new ListBaseViewHolder(component, viewType);
          } else {
            ((WXCell) component).lazy(false);
            component.createView();
            component.applyLayoutAndEvent(component);
            return new ListBaseViewHolder(component, viewType);
          }
        } else if (component instanceof WXBaseRefresh) {
          return createVHForRefreshComponent(viewType);
        } else {
          WXLogUtils.e(TAG, "List cannot include element except cell、header、fixed、refresh and loading");
          return createVHForFakeComponent(viewType);
        }
      }
    }
  }
  if (WXEnvironment.isApkDebugable()) {
    WXLogUtils.e(TAG, "Cannot find request viewType: " + viewType);
  }
  return createVHForFakeComponent(viewType);
}