Search in sources :

Example 51 with WXComponent

use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.

the class WXSDKInstance method onBackPressed.

public boolean onBackPressed() {
    WXComponent comp = getRootComponent();
    if (comp != null) {
        WXEvent events = comp.getDomObject().getEvents();
        boolean hasBackPressed = events.contains(Constants.Event.CLICKBACKITEM);
        if (hasBackPressed) {
            fireEvent(comp.getRef(), Constants.Event.CLICKBACKITEM, null, null);
        }
        return hasBackPressed;
    }
    return false;
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) WXEvent(com.taobao.weex.dom.WXEvent)

Example 52 with WXComponent

use of com.taobao.weex.ui.component.WXComponent in project incubator-weex by apache.

the class WXSDKInstance method setSize.

public void setSize(int width, int height) {
    if (width < 0 || height < 0 || isDestroy || !mRendered) {
        return;
    }
    float realWidth = WXViewUtils.getWebPxByWidth(width, getInstanceViewPortWidth());
    float realHeight = WXViewUtils.getWebPxByWidth(height, getInstanceViewPortWidth());
    View godView = mRenderContainer;
    if (godView != null) {
        ViewGroup.LayoutParams layoutParams = godView.getLayoutParams();
        if (layoutParams != null) {
            if (godView.getWidth() != width || godView.getHeight() != height) {
                layoutParams.width = width;
                layoutParams.height = height;
                godView.setLayoutParams(layoutParams);
            }
            JSONObject style = new JSONObject();
            WXComponent rootComponent = mRootComp;
            if (rootComponent == null) {
                return;
            }
            style.put(Constants.Name.DEFAULT_WIDTH, realWidth);
            style.put(Constants.Name.DEFAULT_HEIGHT, realHeight);
            updateRootComponentStyle(style);
        }
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) WXComponent(com.taobao.weex.ui.component.WXComponent) ViewGroup(android.view.ViewGroup) View(android.view.View) WXScrollView(com.taobao.weex.ui.view.WXScrollView) ScrollView(android.widget.ScrollView)

Example 53 with WXComponent

use of com.taobao.weex.ui.component.WXComponent in project weex-example by KalicyZhou.

the class WXSDKInstance method onBackPressed.

public boolean onBackPressed() {
    WXComponent comp = getRootComponent();
    if (comp != null) {
        WXEvent events = comp.getDomObject().getEvents();
        boolean hasBackPressed = events.contains(Constants.Event.CLICKBACKITEM);
        if (hasBackPressed) {
            WXBridgeManager.getInstance().fireEvent(this.mInstanceId, comp.getRef(), Constants.Event.CLICKBACKITEM, null, null);
        }
        return hasBackPressed;
    }
    return false;
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) WXEvent(com.taobao.weex.dom.WXEvent)

Example 54 with WXComponent

use of com.taobao.weex.ui.component.WXComponent in project weex-example by KalicyZhou.

the class WXListComponentTest method testScrollTo.

@Test
public void testScrollTo() throws Exception {
    WXComponent child = WXDivTest.create(component);
    ComponentTest.create(child);
    component.addChild(child);
    child = WXHeaderTest.create(component);
    ComponentTest.create(child);
    component.addChild(child);
    Map<String, Object> options = new HashMap<>(2);
    options.put("offset", 10);
    options.put("animated", false);
    component.scrollTo(child, options);
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) HashMap(java.util.HashMap) WXDomObject(com.taobao.weex.dom.WXDomObject) WXListDomObject(com.taobao.weex.dom.WXListDomObject) Test(org.junit.Test) ComponentTest(com.taobao.weex.ui.component.ComponentTest) WXSDKInstanceTest(com.taobao.weex.WXSDKInstanceTest) WXHeaderTest(com.taobao.weex.ui.component.WXHeaderTest) WXDivTest(com.taobao.weex.ui.component.WXDivTest)

Example 55 with WXComponent

use of com.taobao.weex.ui.component.WXComponent in project weex-example by KalicyZhou.

the class BasicListComponent method scrollTo.

@Override
public void scrollTo(WXComponent component, Map<String, Object> options) {
    float offsetFloat = 0;
    boolean smooth = true;
    if (options != null) {
        String offsetStr = options.get(Constants.Name.OFFSET) == null ? "0" : options.get(Constants.Name.OFFSET).toString();
        smooth = WXUtils.getBoolean(options.get(Constants.Name.ANIMATED), true);
        if (offsetStr != null) {
            try {
                offsetFloat = WXViewUtils.getRealPxByWidth(Float.parseFloat(offsetStr), getInstance().getViewPortWidth());
            } catch (Exception e) {
                WXLogUtils.e("Float parseFloat error :" + e.getMessage());
            }
        }
    }
    final int offset = (int) offsetFloat;
    T bounceRecyclerView = getHostView();
    if (bounceRecyclerView == null) {
        return;
    }
    WXComponent parent = component;
    WXCell cell = null;
    while (parent != null) {
        if (parent instanceof WXCell) {
            cell = (WXCell) parent;
            break;
        }
        parent = parent.getParent();
    }
    if (cell != null) {
        final int pos = mChildren.indexOf(cell);
        final WXRecyclerView view = bounceRecyclerView.getInnerView();
        if (!smooth) {
            RecyclerView.LayoutManager layoutManager = view.getLayoutManager();
            if (layoutManager instanceof LinearLayoutManager) {
                //GridLayoutManager is also instance of LinearLayoutManager
                ((LinearLayoutManager) layoutManager).scrollToPositionWithOffset(pos, -offset);
            } else if (layoutManager instanceof StaggeredGridLayoutManager) {
                ((StaggeredGridLayoutManager) layoutManager).scrollToPositionWithOffset(pos, -offset);
            }
        //Any else?
        } else {
            view.smoothScrollToPosition(pos);
            if (offset != 0) {
                view.addOnScrollListener(new RecyclerView.OnScrollListener() {

                    @Override
                    public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                        if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                            if (getOrientation() == Constants.Orientation.VERTICAL) {
                                recyclerView.smoothScrollBy(0, offset);
                            } else {
                                recyclerView.smoothScrollBy(offset, 0);
                            }
                            recyclerView.removeOnScrollListener(this);
                        }
                    }
                });
            }
        }
    }
}
Also used : WXComponent(com.taobao.weex.ui.component.WXComponent) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) WXRuntimeException(com.taobao.weex.common.WXRuntimeException) Point(android.graphics.Point) WXRecyclerView(com.taobao.weex.ui.view.listview.WXRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView)

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