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;
}
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);
}
}
}
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;
}
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);
}
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);
}
}
});
}
}
}
}
Aggregations