com.taobao.weex.ui.IWXRenderTask Java Examples

The following examples show how to use com.taobao.weex.ui.IWXRenderTask. 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: WXDomStatement.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * Create a command object for notifying {@link WXRenderManager} that the process of update
 * given view is finished, and put the command object in the queue.
 */
void updateFinish() {
  if (mDestroy) {
    return;
  }
  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      mWXRenderManager.updateFinish(mInstanceId);
    }

    @Override
    public String toString() {
      return "updateFinish";
    }
  });

  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
  if (instance != null) {
    instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
  }
}
 
Example #2
Source File: WXDomStatement.java    From weex with Apache License 2.0 6 votes vote down vote up
/**
 * Create a command object for notifying {@link WXRenderManager} that the process of update
 * given view is finished, and put the command object in the queue.
 */
void updateFinish() {
  if (mDestroy) {
    return;
  }
  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      mWXRenderManager.updateFinish(mInstanceId);
    }
  });

  mDirty = true;
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
  if (instance != null) {
    instance.commitUTStab(WXConst.DOM_MODULE, WXErrorCode.WX_SUCCESS);
  }
}
 
Example #3
Source File: WXDomStatement.java    From weex with Apache License 2.0 6 votes vote down vote up
/**
 * Create a command object for notifying {@link WXRenderManager} that the process of refreshing
 * given view is finished, and put the command object in the queue.
 */
void refreshFinish() {
  if (mDestroy) {
    return;
  }
  final WXDomObject root = mRegistry.get(WXDomObject.ROOT);
  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      int realWidth = (int) root.getLayoutWidth();
      int realHeight = (int) root.getLayoutHeight();
      mWXRenderManager.refreshFinish(mInstanceId, realWidth, realHeight);
    }
  });

  mDirty = true;
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
  if (instance != null) {
    instance.commitUTStab(WXConst.DOM_MODULE, WXErrorCode.WX_SUCCESS);
  }
}
 
Example #4
Source File: WXDomStatement.java    From weex with Apache License 2.0 6 votes vote down vote up
/**
 * Create a command object for notifying {@link WXRenderManager} that the process of creating
 * given view is finished, and put the command object in the queue.
 */
void createFinish() {
  if (mDestroy) {
    return;
  }

  final WXDomObject root = mRegistry.get(WXDomObject.ROOT);
  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      mWXRenderManager.createFinish(mInstanceId,
                                    (int) root.getLayoutWidth(),
                                    (int) root.getLayoutHeight());
    }
  });

  mDirty = true;
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
  if (instance != null) {
    instance.commitUTStab(WXConst.DOM_MODULE, WXErrorCode.WX_SUCCESS);
  }
}
 
Example #5
Source File: WXDomStatement.java    From weex with Apache License 2.0 6 votes vote down vote up
/**
 * Create a command object for scroll the given view to the specified position.
 * @param ref {@link WXDomObject#ref} of the dom.
 * @param options the specified position
 */
void scrollToDom(final String ref, final JSONObject options) {
  if (mDestroy) {
    return;
  }
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);

  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      mWXRenderManager.scrollToComponent(mInstanceId, ref, options);
    }
  });

  mDirty = true;
  if (instance != null) {
    instance.commitUTStab(WXConst.DOM_MODULE, WXErrorCode.WX_SUCCESS);
  }
}
 
Example #6
Source File: WXDomStatement.java    From weex with Apache License 2.0 6 votes vote down vote up
/**
 * Create the command object for updating style and put it the queue. If the given style
 * contains border-width and padding that will affect layout, then a command object for reset
 * padding will also be created.
 * @param domObject the given dom object
 * @param update the given style.
 */
private void updateStyle(final WXDomObject domObject, final Map<String, Object> update) {
  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      mWXRenderManager.updateStyle(mInstanceId, domObject.ref, update);
    }
  });
  if (update.containsKey("padding") || update.containsKey("paddingTop") ||
      update.containsKey("paddingLeft") ||
      update.containsKey("paddingRight") ||
      update.containsKey("paddingBottom") || update.containsKey("borderWidth")) {
    mNormalTasks.add(new IWXRenderTask() {

      @Override
      public void execute() {
        Spacing padding = domObject.getPadding();
        Spacing border = domObject.getBorder();
        mWXRenderManager.setPadding(mInstanceId, domObject.ref, padding, border);
      }
    });
  }
}
 
Example #7
Source File: WXDomStatement.java    From weex-uikit with MIT License 6 votes vote down vote up
public void getComponentSize(final String ref, final JSCallback callback) {
  if (mDestroy) {
    Map<String, Object> options = new HashMap<>();
    options.put("result", false);
    options.put("errMsg", "Component does not exist");
    callback.invoke(options);
    return;
  }

  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      mWXRenderManager.getComponentSize(mInstanceId, ref, callback);
    }

    @Override
    public String toString() {
      return "getComponentSize";
    }
  });
  mDirty=true;

}
 
Example #8
Source File: WXDomStatement.java    From weex-uikit with MIT License 6 votes vote down vote up
void startAnimation(@NonNull final String ref, @NonNull String animation,
                    @Nullable final String callBack){
  if (mDestroy) {
    return;
  }
  WXDomObject domObject = mRegistry.get(ref);
  if (domObject == null) {
    return;
  }
  final WXAnimationBean animationBean=createAnimationBean(ref, animation);
  if(animationBean!=null) {
    mNormalTasks.add(new IWXRenderTask() {
      @Override
      public void execute() {
        mWXRenderManager.startAnimation(mInstanceId, ref, animationBean, callBack);
      }

      @Override
      public String toString() {
        return "startAnimationByCall";
      }
    });
    mDirty=true;
  }
}
 
Example #9
Source File: WXDomStatement.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * Create a command object for scroll the given view to the specified position.
 * @param ref Reference of the dom.
 * @param options the specified position
 */
void scrollToDom(final String ref, final JSONObject options) {
  if (mDestroy) {
    return;
  }
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);

  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      mWXRenderManager.scrollToComponent(mInstanceId, ref, options);
    }

    @Override
    public String toString() {
      return "scrollToPosition";
    }
  });

  mDirty = true;
  if (instance != null) {
    instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
  }
}
 
Example #10
Source File: WXDomStatement.java    From weex-uikit with MIT License 6 votes vote down vote up
private void parseAnimation() {
  for(final Pair<String, Map<String, Object>> pair:animations) {
    if (!TextUtils.isEmpty(pair.first)) {
      final WXAnimationBean animationBean = createAnimationBean(pair.first, pair.second);
      if (animationBean != null) {
        mNormalTasks.add(new IWXRenderTask() {
          @Override
          public void execute() {
            mWXRenderManager.startAnimation(mInstanceId, pair.first, animationBean, null);
          }

          @Override
          public String toString() {
            return "startAnimationByStyle";
          }
        });
      }
    }
  }
}
 
Example #11
Source File: WXDomStatement.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Create a command object for removing the specified {@link WXDomObject}.
 * If the domObject is null or its parent is null, this method returns directly.
 * Otherwise, put the command object in the queue.
 * @param ref {@link WXDomObject#ref} of the dom.
 */
void removeDom(final String ref) {
  if (mDestroy) {
    return;
  }
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
  WXDomObject domObject = mRegistry.get(ref);
  if (domObject == null) {
    if (instance != null) {
      instance.commitUTStab(WXConst.DOM_MODULE, WXErrorCode.WX_ERR_DOM_REMOVEELEMENT);
    }
    return;
  }
  WXDomObject parent = domObject.parent;
  if (parent == null) {
    if (instance != null) {
      instance.commitUTStab(WXConst.DOM_MODULE, WXErrorCode.WX_ERR_DOM_REMOVEELEMENT);
    }
    return;
  }
  clearRegistryForDom(domObject);
  parent.remove(domObject);

  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      mWXRenderManager.removeComponent(mInstanceId, ref);
    }
  });

  mDirty = true;
  if (instance != null) {
    instance.commitUTStab(WXConst.DOM_MODULE, WXErrorCode.WX_SUCCESS);
  }
}
 
Example #12
Source File: WXDomStatement.java    From weex-uikit with MIT License 5 votes vote down vote up
@Override
public void accept(WXDomObject dom) {
  if (dom.hasUpdate()) {
    dom.markUpdateSeen();
    if (!dom.isYoung()) {
      final WXDomObject copy = dom.clone();
      if (copy == null) {
        return;
      }
      mNormalTasks.add(new IWXRenderTask() {

        @Override
        public void execute() {
          mWXRenderManager.setLayout(mInstanceId, copy.getRef(), copy);
          if(copy.getExtra() != null) {
            mWXRenderManager.setExtra(mInstanceId, copy.getRef(), copy.getExtra());
          }
        }

        @Override
        public String toString() {
          return "setLayout & setExtra";
        }
      });
    }
  }
}
 
Example #13
Source File: WXDomStatement.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Create a command object for removing the event listener of the corresponding {@link
 * WXDomObject} and put the command event in the queue.
 * @param ref {@link WXDomObject#ref} of the dom.
 * @param type the type of the event, this may be a plain event defined in
 * {@link com.taobao.weex.ui.component.WXEventType} or a gesture defined in {@link com.taobao
 * .weex.ui.view.gesture.WXGestureType}
 */
void removeEvent(final String ref, final String type) {
  if (mDestroy) {
    return;
  }
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
  WXDomObject domObject = mRegistry.get(ref);
  if (domObject == null) {
    if (instance != null) {
      instance.commitUTStab(WXConst.DOM_MODULE, WXErrorCode.WX_ERR_DOM_REMOVEEVENT);
    }
    return;
  }
  domObject.removeEvent(type);
  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      mWXRenderManager.removeEvent(mInstanceId, ref, type);
    }
  });

  mDirty = true;
  if (instance != null) {
    instance.commitUTStab(WXConst.DOM_MODULE, WXErrorCode.WX_SUCCESS);
  }
}
 
Example #14
Source File: WXDomStatement.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Create a command object for adding a default event listener to the corresponding {@link
 * WXDomObject} and put the command object in the queue.
 * When the event is triggered, the eventListener will call {@link WXSDKManager#fireEvent
 * (String, String, String)}, and the JS will handle all the operations from there.
 *
 * @param ref {@link WXDomObject#ref} of the dom.
 * @param type the type of the event, this may be a plain event defined in
 * {@link com.taobao.weex.ui.component.WXEventType} or a gesture defined in {@link com.taobao
 * .weex.ui.view.gesture.WXGestureType}
 */
void addEvent(final String ref, final String type) {
  if (mDestroy) {
    return;
  }
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
  WXDomObject domObject = mRegistry.get(ref);
  if (domObject == null) {
    if (instance != null) {
      instance.commitUTStab(WXConst.DOM_MODULE, WXErrorCode.WX_ERR_DOM_ADDEVENT);
    }
    return;
  }
  domObject.addEvent(type);
  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      mWXRenderManager.addEvent(mInstanceId, ref, type);
    }
  });

  mDirty = true;
  if (instance != null) {
    instance.commitUTStab(WXConst.DOM_MODULE, WXErrorCode.WX_SUCCESS);
  }
}
 
Example #15
Source File: WXDomStatement.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Update the {@link WXDomObject#attr} according to the given attribute. Then creating a
 * command object for updating corresponding view and put the command object in the queue.
 * @param ref {@link WXDomObject#ref} of the dom.
 * @param attrs the new style. This style is only a part of the full attribute set, and will be
 *              merged into {@link WXDomObject#attr}
 * @see #updateStyle(String, JSONObject)
 */
void updateAttrs(String ref, final JSONObject attrs) {
  if (mDestroy) {
    return;
  }
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
  final WXDomObject domObject = mRegistry.get(ref);
  if (domObject == null) {
    if (instance != null) {
      instance.commitUTStab(WXConst.DOM_MODULE, WXErrorCode.WX_ERR_DOM_UPDATEATTRS);
    }
    return;
  }

  domObject.updateAttr(attrs);

  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      mWXRenderManager.updateAttrs(mInstanceId, domObject.ref, attrs);
    }
  });
  mDirty = true;

  if (instance != null) {
    instance.commitUTStab(WXConst.DOM_MODULE, WXErrorCode.WX_SUCCESS);
  }
}
 
Example #16
Source File: WXDomStatement.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * Create a command object for removing the event listener of the corresponding {@link
 * WXDomObject} and put the command event in the queue.
 * @param ref Reference of the dom.
 * @param type the type of the event, this may be a plain event defined in
 * {@link com.taobao.weex.common.Constants.Event} or a gesture defined in {@link com.taobao
 * .weex.ui.view.gesture.WXGestureType}
 */
void removeEvent(final String ref, final String type) {
  if (mDestroy) {
    return;
  }
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
  final WXDomObject domObject = mRegistry.get(ref);
  if (domObject == null) {
    if (instance != null) {
      instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_ERR_DOM_REMOVEEVENT);
    }
    return;
  }
  domObject.removeEvent(type);

  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      WXComponent comp = mWXRenderManager.getWXComponent(mInstanceId,ref);
      if(comp != null){
        //sync dom change to component
        comp.updateDom(domObject);
        mWXRenderManager.removeEvent(mInstanceId, ref, type);
      }

    }

    @Override
    public String toString() {
      return "removeEvent";
    }
  });

  mDirty = true;
  if (instance != null) {
    instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
  }
}
 
Example #17
Source File: WXDomStatement.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Create a command object for moving the specific {@link WXDomObject} to a new parent.
 * If any of the following situation is met,
 * <ul>
 * <li> dom to be moved is null </li>
 * <li> dom's parent is null </li>
 * <li> new parent is null </li>
 * <li> parent is under {@link CSSNode#hasNewLayout()} </li>
 * </ul>
 * this method will return. Otherwise, put the command object in the queue.
 * @param ref {@link WXDomObject#ref} of the dom to be moved.
 * @param parentRef {@link WXDomObject#ref} of the new parent DOM node
 * @param index the index of the dom to be inserted in the new parent.
 */
void moveDom(final String ref, final String parentRef, final int index) {
  if (mDestroy) {
    return;
  }
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
  WXDomObject domObject = mRegistry.get(ref);
  WXDomObject parentObject = mRegistry.get(parentRef);
  if (domObject == null || domObject.parent == null
      || parentObject == null || parentObject.hasNewLayout()) {
    if (instance != null) {
      instance.commitUTStab(WXConst.DOM_MODULE, WXErrorCode.WX_ERR_DOM_MOVEELEMENT);
    }
    return;
  }
  domObject.parent.remove(domObject);
  parentObject.add(domObject, index);

  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      mWXRenderManager.moveComponent(mInstanceId, ref, parentRef, index);
    }
  });

  mDirty = true;
  if (instance != null) {
    instance.commitUTStab(WXConst.DOM_MODULE, WXErrorCode.WX_SUCCESS);
  }
}
 
Example #18
Source File: WXDomStatement.java    From weex with Apache License 2.0 5 votes vote down vote up
/**
 * Walk through the dom tree and create command object of re-calculating
 * {@link android.view.ViewGroup.LayoutParams} for dom that is old.
 * @param dom the root dom of the walk through.
 */
private void applyUpdate(WXDomObject dom) {
  if (dom == null) {
    return;
  }
  if (dom.hasUpdate()) {
    dom.markUpdateSeen();
    mUpdate.add(dom.ref);
    if (!dom.isYoung()) {
      final WXDomObject copy = dom.clone();
      if (copy == null) {
        return;
      }
      mNormalTasks.add(new IWXRenderTask() {

        @Override
        public void execute() {
          mWXRenderManager.setLayout(mInstanceId, copy.ref, copy);
        }
      });
      if (dom.getExtra() != null) {
        mNormalTasks.add(new IWXRenderTask() {

          @Override
          public void execute() {
            mWXRenderManager.setExtra(mInstanceId, copy.ref, copy.getExtra());
          }
        });
      }
    }
  }
  int count = dom.childCount();
  for (int i = 0; i < count; ++i) {
    applyUpdate(dom.getChild(i));
  }
}
 
Example #19
Source File: WXDomStatement.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * Update the attributes according to the given attribute. Then creating a
 * command object for updating corresponding view and put the command object in the queue.
 * @param ref Reference of the dom.
 * @param attrs the new style. This style is only a part of the full attribute set, and will be
 *              merged into attributes
 * @see #updateStyle(String, JSONObject)
 */
void updateAttrs(String ref, final JSONObject attrs) {
  if (mDestroy) {
    return;
  }
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
  final WXDomObject domObject = mRegistry.get(ref);
  if (domObject == null) {
    if (instance != null) {
      instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_ERR_DOM_UPDATEATTRS);
    }
    return;
  }

  domObject.updateAttr(attrs);

  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      mWXRenderManager.updateAttrs(mInstanceId, domObject.getRef(), attrs);
    }

    @Override
    public String toString() {
      return "updateAttr";
    }
  });
  mDirty = true;

  if (instance != null) {
    instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
  }
}
 
Example #20
Source File: WXDomStatement.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * Create the command object for updating style and put it the queue. If the given style
 * contains border-width and padding that will affect layout, then a command object for reset
 * padding will also be created.
 * @param domObject the given dom object
 * @param update the given style.
 */
private void updateStyle(final WXDomObject domObject, final Map<String, Object> update) {
  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      mWXRenderManager.updateStyle(mInstanceId, domObject.getRef(), update);
    }

    @Override
    public String toString() {
      return "updateStyle";
    }
  });
  if (update.containsKey(Constants.Name.PADDING) ||
      update.containsKey(Constants.Name.PADDING_TOP) ||
      update.containsKey(Constants.Name.PADDING_LEFT) ||
      update.containsKey(Constants.Name.PADDING_RIGHT) ||
      update.containsKey(Constants.Name.PADDING_BOTTOM) ||
      update.containsKey(Constants.Name.BORDER_WIDTH)) {
    mNormalTasks.add(new IWXRenderTask() {

      @Override
      public void execute() {
        Spacing padding = domObject.getPadding();
        Spacing border = domObject.getBorder();
        mWXRenderManager.setPadding(mInstanceId, domObject.getRef(), padding, border);
      }

      @Override
      public String toString() {
        return "setPadding";
      }
    });
  }
}
 
Example #21
Source File: DOMActionContextImpl.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Override
public void accept(WXDomObject dom) {
  if (dom.hasUpdate()) {
    dom.markUpdateSeen();
    if (!dom.isYoung()) {
      final WXDomObject copy = dom.clone();
      if (copy == null) {
        return;
      }
      mNormalTasks.add(new IWXRenderTask() {

        @Override
        public void execute() {
          mWXRenderManager.setLayout(mInstanceId, copy.getRef(), copy);
          if(copy.getExtra() != null) {
            mWXRenderManager.setExtra(mInstanceId, copy.getRef(), copy.getExtra());
          }
        }

        @Override
        public String toString() {
          return "setLayout & setExtra";
        }
      });
    }
  }
}
 
Example #22
Source File: WXDomStatement.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * Create a command object for notifying {@link WXRenderManager} that the process of refreshing
 * given view is finished, and put the command object in the queue.
 */
void refreshFinish() {
  if (mDestroy) {
    return;
  }
  final WXDomObject root = mRegistry.get(WXDomObject.ROOT);
  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      int realWidth = (int) root.getLayoutWidth();
      int realHeight = (int) root.getLayoutHeight();
      mWXRenderManager.refreshFinish(mInstanceId, realWidth, realHeight);
    }

    @Override
    public String toString() {
      return "refreshFinish";
    }
  });

  mDirty = true;
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
  if (instance != null) {
    instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
  }
}
 
Example #23
Source File: WXDomStatement.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * Create a command object for notifying {@link WXRenderManager} that the process of creating
 * given view is finished, and put the command object in the queue.
 */
void createFinish() {
  if (mDestroy) {
    return;
  }

  final WXDomObject root = mRegistry.get(WXDomObject.ROOT);
  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      mWXRenderManager.createFinish(mInstanceId,
                                    (int) root.getLayoutWidth(),
                                    (int) root.getLayoutHeight());
    }

    @Override
    public String toString() {
      return "createFinish";
    }
  });

  mDirty = true;
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
  if (instance != null) {
    instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
  }
}
 
Example #24
Source File: WXDomStatement.java    From weex-uikit with MIT License 5 votes vote down vote up
/**
 * Create a command object for adding a default event listener to the corresponding {@link
 * WXDomObject} and put the command object in the queue.
 * When the event is triggered, the eventListener will call {@link WXSDKManager#fireEvent(String, String, String)}
 * , and the JS will handle all the operations from there.
 *
 * @param ref Reference of the dom.
 * @param type the type of the event, this may be a plain event defined in
 * {@link com.taobao.weex.common.Constants.Event} or a gesture defined in {@link com.taobao
 * .weex.ui.view.gesture.WXGestureType}
 */
void addEvent(final String ref, final String type) {
  if (mDestroy) {
    return;
  }
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
  final WXDomObject domObject = mRegistry.get(ref);
  if (domObject == null) {
    if (instance != null) {
      instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_ERR_DOM_ADDEVENT);
    }
    return;
  }
  domObject.addEvent(type);
  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      WXComponent comp = mWXRenderManager.getWXComponent(mInstanceId,ref);
      if(comp != null){
        //sync dom change to component
        comp.updateDom(domObject);
        mWXRenderManager.addEvent(mInstanceId, ref, type);
      }
    }

    @Override
    public String toString() {
      return "Add event";
    }
  });

  mDirty = true;
  if (instance != null) {
    instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
  }
}
 
Example #25
Source File: WXDomStatement.java    From weex-uikit with MIT License 4 votes vote down vote up
/**
 * Create a command object for removing the specified {@link WXDomObject}.
 * If the domObject is null or its parent is null, this method returns directly.
 * Otherwise, put the command object in the queue.
 * @param ref Reference of the dom.
 */
void removeDom(final String ref) {
  if (mDestroy) {
    return;
  }
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
  WXDomObject domObject = mRegistry.get(ref);
  if (domObject == null) {
    if (instance != null) {
      instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_ERR_DOM_REMOVEELEMENT);
    }
    return;
  }
  WXDomObject parent = domObject.parent;
  if (parent == null) {
    if (instance != null) {
      instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_ERR_DOM_REMOVEELEMENT);
    }
    return;
  }
  domObject.traverseTree(new WXDomObject.Consumer() {
    @Override
    public void accept(WXDomObject dom) {
      mRegistry.remove(dom.getRef());
    }
  });
  parent.remove(domObject);
  mRegistry.remove(ref);

  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      mWXRenderManager.removeComponent(mInstanceId, ref);
    }

    @Override
    public String toString() {
      return "removeDom";
    }
  });

  mDirty = true;
  if (instance != null) {
    instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
  }
}
 
Example #26
Source File: WXDomStatement.java    From weex-uikit with MIT License 4 votes vote down vote up
/**
 * Create a command object for moving the specific {@link WXDomObject} to a new parent.
 * If any of the following situation is met,
 * <ul>
 * <li> dom to be moved is null </li>
 * <li> dom's parent is null </li>
 * <li> new parent is null </li>
 * <li> parent is under {@link CSSNode#hasNewLayout()} </li>
 * </ul>
 * this method will return. Otherwise, put the command object in the queue.
 * @param ref Reference of the dom to be moved.
 * @param parentRef Reference of the new parent DOM node
 * @param index the index of the dom to be inserted in the new parent.
 */
void moveDom(final String ref, final String parentRef, int index) {
  if (mDestroy) {
    return;
  }
  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
  WXDomObject domObject = mRegistry.get(ref);
  WXDomObject parentObject = mRegistry.get(parentRef);
  if (domObject == null || domObject.parent == null
      || parentObject == null || parentObject.hasNewLayout()) {
    if (instance != null) {
      instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_ERR_DOM_MOVEELEMENT);
    }
    return;
  }
  if (domObject.parent.equals(parentObject)) {
    if(parentObject.index(domObject) == index) {
      return;
    } else if(domObject.parent.index(domObject)<index){
      index = index -1;
    }
  }

  final int newIndex = index;
  domObject.parent.remove(domObject);
  parentObject.add(domObject, newIndex);

  mNormalTasks.add(new IWXRenderTask() {

    @Override
    public void execute() {
      mWXRenderManager.moveComponent(mInstanceId, ref, parentRef, newIndex);
    }

    @Override
    public String toString() {
      return "moveDom";
    }
  });

  mDirty = true;
  if (instance != null) {
    instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
  }
}
 
Example #27
Source File: WXDomStatement.java    From weex-uikit with MIT License 4 votes vote down vote up
/**
 * Add DOM node.
 * @param dom
 * @param isRoot
 * @param parentRef
 * @param index
 */
private void addDomInternal(JSONObject dom,boolean isRoot, String parentRef, final int index){
  if (mDestroy) {
    return;
  }

  WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId);
  if (instance == null) {
    return;
  }
  WXErrorCode errCode = isRoot ? WXErrorCode.WX_ERR_DOM_CREATEBODY : WXErrorCode.WX_ERR_DOM_ADDELEMENT;
  if (dom == null) {
    instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, errCode);
  }

  //only non-root has parent.
  WXDomObject parent;
  WXDomObject domObject = WXDomObject.parse(dom,instance);

  if (domObject == null || mRegistry.containsKey(domObject.getRef())) {
    if (WXEnvironment.isApkDebugable()) {
      WXLogUtils.e("[WXDomStatement] " + (isRoot ? "createBody" : "addDom") + " error,DOM object is null or already registered!!");
    }
    instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, errCode);
    return;
  }
  if (isRoot) {
    WXDomObject.prepareRoot(domObject,
                            WXViewUtils.getWebPxByWidth(WXViewUtils.getWeexHeight(mInstanceId),WXSDKManager.getInstanceViewPortWidth(mInstanceId)),
                            WXViewUtils.getWebPxByWidth(WXViewUtils.getWeexWidth(mInstanceId),WXSDKManager.getInstanceViewPortWidth(mInstanceId)));
  } else if ((parent = mRegistry.get(parentRef)) == null) {
    instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, errCode);
    return;
  } else {
    //non-root and parent exist
    parent.add(domObject, index);
  }

  domObject.traverseTree(
      mAddDOMConsumer,
      ApplyStyleConsumer.getInstance()
                        );

  //Create component in dom thread
  WXComponent component = isRoot ?
                          mWXRenderManager.createBodyOnDomThread(mInstanceId, domObject) :
                          mWXRenderManager.createComponentOnDomThread(mInstanceId, domObject, parentRef, index);
  if (component == null) {
    instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, errCode);
    //stop redner, some fatal happened.
    return;
  }
  AddDomInfo addDomInfo = new AddDomInfo();
  addDomInfo.component = component;
  mAddDom.put(domObject.getRef(), addDomInfo);

  IWXRenderTask task = isRoot ? new CreateBodyTask(component) : new AddDOMTask(component, parentRef, index);
  mNormalTasks.add(task);
  addAnimationForDomTree(domObject);
  mDirty = true;

  instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS);
}