Search in sources :

Example 76 with WXComponent

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();
}
Also used : WXVContainer(com.taobao.weex.ui.component.WXVContainer) WXDomObject(com.taobao.weex.dom.WXDomObject) WXComponent(com.taobao.weex.ui.component.WXComponent)

Example 77 with WXComponent

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);
            }
        }
    }
}
Also used : WXVContainer(com.taobao.weex.ui.component.WXVContainer) WXDomObject(com.taobao.weex.dom.WXDomObject) WXComponent(com.taobao.weex.ui.component.WXComponent)

Example 78 with WXComponent

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);
            }
        }
    }
}
Also used : WXVContainer(com.taobao.weex.ui.component.WXVContainer) WXDomObject(com.taobao.weex.dom.WXDomObject) WXComponent(com.taobao.weex.ui.component.WXComponent)

Example 79 with WXComponent

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);
    }
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) AsyncTask(android.os.AsyncTask)

Example 80 with WXComponent

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);
    }
}
Also used : WXVContainer(com.taobao.weex.ui.component.WXVContainer) WXComponent(com.taobao.weex.ui.component.WXComponent)

Aggregations

WXComponent (com.taobao.weex.ui.component.WXComponent)101 Point (android.graphics.Point)21 WXDomObject (com.taobao.weex.dom.WXDomObject)20 WXVContainer (com.taobao.weex.ui.component.WXVContainer)19 HashMap (java.util.HashMap)13 View (android.view.View)9 WXSDKInstanceTest (com.taobao.weex.WXSDKInstanceTest)9 WXRecyclerView (com.taobao.weex.ui.view.listview.WXRecyclerView)9 Map (java.util.Map)9 Test (org.junit.Test)9 ArrayMap (android.support.v4.util.ArrayMap)8 RecyclerView (android.support.v7.widget.RecyclerView)8 JSONObject (com.alibaba.fastjson.JSONObject)8 WXSDKInstance (com.taobao.weex.WXSDKInstance)8 ComponentTest (com.taobao.weex.ui.component.ComponentTest)8 WXDivTest (com.taobao.weex.ui.component.WXDivTest)8 Scrollable (com.taobao.weex.ui.component.Scrollable)6 WXBaseRefresh (com.taobao.weex.ui.component.WXBaseRefresh)6 WXHeaderTest (com.taobao.weex.ui.component.WXHeaderTest)6 AppearanceHelper (com.taobao.weex.ui.component.AppearanceHelper)5