use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.
the class WXSDKInstanceTest method setupRoot.
public static void setupRoot(WXSDKInstance instance) {
WXDomObject domObject = new WXDomObject();
WXVContainer comp = (WXVContainer) WXComponentFactory.newInstance(instance, domObject, null);
WXComponent root = WXDivTest.create(comp);
comp.addChild(root);
comp.createView();
instance.onCreateFinish();
ShadowLooper.idleMainLooper();
}
use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.
the class Layouts method setLayoutWaste.
private static final void setLayoutWaste(WXComponent component, boolean force) {
WXDomObject domObject = (WXDomObject) component.getDomObject();
if (domObject.hasUpdate() || force) {
domObject.markUpdateSeen();
if (domObject.hasUpdate()) {
domObject.markLayoutStateUpdated();
}
}
if (component instanceof WXVContainer) {
WXVContainer container = (WXVContainer) component;
int count = container.getChildCount();
for (int i = 0; i < count; ++i) {
WXComponent child = container.getChild(i);
if (child != null) {
setLayoutWaste(child, force);
}
}
}
}
use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.
the class Layouts method setLayout.
/**
* recursive set layout to component,
* dom extra will also be updated from dom object to component.
* if force is true, always set layout
*/
public static final void setLayout(WXComponent component, boolean force) {
if (component.isWaste()) {
return;
}
WXDomObject domObject = (WXDomObject) component.getDomObject();
if (domObject.hasUpdate() || force) {
domObject.markUpdateSeen();
if (domObject.hasUpdate()) {
domObject.markLayoutStateUpdated();
}
component.setLayout(component.getDomObject());
if (component.getDomObject().getExtra() != null) {
component.updateExtra(component.getDomObject().getExtra());
}
}
if (component instanceof WXVContainer) {
WXVContainer container = (WXVContainer) component;
int count = container.getChildCount();
for (int i = 0; i < count; ++i) {
WXComponent child = container.getChild(i);
if (child != null) {
setLayout(child, force);
}
}
}
}
use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.
the class Layouts method doLayoutAsync.
/**
* do dom layout async or sync , and set layout to component on main.
* on first use do sync layout, when compontnet reuse do async layout
*/
public static void doLayoutAsync(final TemplateViewHolder templateViewHolder, boolean async) {
final WXComponent component = templateViewHolder.getComponent();
final int position = templateViewHolder.getHolderPosition();
if (templateViewHolder.asyncTask != null) {
templateViewHolder.asyncTask.cancel(false);
templateViewHolder.asyncTask = null;
}
if (async) {
AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
if (templateViewHolder.getHolderPosition() == position) {
if (component.getInstance() != null && !component.getInstance().isDestroy()) {
doSafeLayout(component, templateViewHolder.getLayoutContext());
}
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
if (position == templateViewHolder.getHolderPosition()) {
if (component.getInstance() != null && !component.getInstance().isDestroy()) {
setLayout(component, false);
}
}
}
};
templateViewHolder.asyncTask = asyncTask;
// serial executor is better
asyncTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
} else {
doSafeLayout(component, templateViewHolder.getLayoutContext());
setLayout(component, false);
}
}
use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.
the class Statements method doInitCompontent.
public static final void doInitCompontent(List<WXComponent> updates) {
if (updates == null || updates.size() == 0) {
return;
}
for (WXComponent renderNode : updates) {
if (renderNode.getParent() == null) {
throw new IllegalArgumentException("render node parent cann't find");
}
WXVContainer parent = renderNode.getParent();
int renderIndex = parent.indexOf(renderNode);
if (renderIndex < 0) {
throw new IllegalArgumentException("render node cann't find");
}
parent.createChildViewAt(renderIndex);
renderNode.applyLayoutAndEvent(renderNode);
renderNode.bindData(renderNode);
}
}
Aggregations