/** * Update styles according to the given style. Then creating a command object for updating * corresponding view and put the command object in the queue. * * @param ref Reference of the dom. * @param style the new style. This style is only a part of the full style, and will be merged * into styles * @see #updateAttrs(String, JSONObject) */ void updateStyle(String ref, JSONObject style) { if (mDestroy || style == null) { 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_UPDATESTYLE); } return; } Map<String, Object> animationMap = WXDataStructureUtil.newHashMapWithExpectedSize(2); animationMap.put(WXDomObject.TRANSFORM, style.remove(WXDomObject.TRANSFORM)); animationMap.put(WXDomObject.TRANSFORM_ORIGIN, style.remove(WXDomObject.TRANSFORM_ORIGIN)); animations.add(new Pair<>(ref, animationMap)); if (!style.isEmpty()) { domObject.updateStyle(style); transformStyle(domObject, false); updateStyle(domObject, style); } mDirty = true; if (instance != null) { instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS); } }
/** * Create command object for creating body according to the JSONObject. And put the command object * in the queue. * * @param element the jsonObject according to which to create command object. */ void createBody(JSONObject element) { if (mDestroy) { return; } WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId); if (element == null) { if (instance != null) { instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_ERR_DOM_CREATEBODY); } return; } WXDomObject domObject = parseInner(element); if (domObject == null) { return; } Map<String, Object> style = new HashMap<>(5); if (!domObject.getStyles().containsKey(Constants.Name.FLEX_DIRECTION)) { style.put(Constants.Name.FLEX_DIRECTION, "column"); } if (!domObject.getStyles().containsKey(Constants.Name.BACKGROUND_COLOR)) { style.put(Constants.Name.BACKGROUND_COLOR, "#ffffff"); } // If there is height or width in JS, then that value will override value here. if (!domObject.getStyles().containsKey(Constants.Name.WIDTH)) { style.put( Constants.Name.WIDTH, WXViewUtils.getWebPxByWidth(WXViewUtils.getWeexWidth(mInstanceId))); domObject.setModifyWidth(true); } if (!domObject.getStyles().containsKey(Constants.Name.HEIGHT)) { style.put( Constants.Name.HEIGHT, WXViewUtils.getWebPxByWidth(WXViewUtils.getWeexHeight(mInstanceId))); domObject.setModifyHeight(true); } WXDomObject.prepareRoot(domObject); domObject.updateStyle(style); transformStyle(domObject, true); try { final WXComponent component = mWXRenderManager.createBodyOnDomThread(mInstanceId, domObject); AddDomInfo addDomInfo = new AddDomInfo(); addDomInfo.component = component; mAddDom.put(domObject.getRef(), addDomInfo); mNormalTasks.add( new IWXRenderTask() { @Override public void execute() { WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId); if (instance == null || instance.getContext() == null) { WXLogUtils.e("instance is null or instance is destroy!"); return; } try { mWXRenderManager.createBody(mInstanceId, component); } catch (Exception e) { WXLogUtils.e("create body failed.", e); } } @Override public String toString() { return "createBody"; } }); animations.add( new Pair<String, Map<String, Object>>(domObject.getRef(), domObject.getStyles())); mDirty = true; if (instance != null) { instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS); } } catch (Exception e) { WXLogUtils.e("create body in dom thread failed." + e.getMessage()); } }