com.taobao.weex.ui.component.WXComponent Java Examples
The following examples show how to use
com.taobao.weex.ui.component.WXComponent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BasicListComponent.java From weex-uikit with MIT License | 6 votes |
/** * @param child the inserted child * @param index the index of the child to be inserted. * @see #addChild(WXComponent) */ @Override public void addChild(WXComponent child, int index) { super.addChild(child, index); if (child == null || index < -1) { return; } int count = mChildren.size(); index = index >= count ? -1 : index; bindViewType(child); int adapterPosition = index == -1 ? mChildren.size() - 1 : index; T view = getHostView(); if (view != null) { view.getRecyclerViewBaseAdapter().notifyItemInserted(adapterPosition); } relocateAppearanceHelper(); }
Example #2
Source File: BaseBounceView.java From weex-uikit with MIT License | 6 votes |
/** * * @param loading should be {@link WXRefreshView} */ public void setFooterView(WXComponent loading) { setLoadmoreEnable(true); if (swipeLayout != null) { if (swipeLayout.getFooterView() != null) { swipeLayout.setLoadingHeight((int) loading.getDomObject().getLayoutHeight()); String colorStr = (String) loading.getDomObject().getStyles().get(Constants.Name.BACKGROUND_COLOR); String bgColor = WXUtils.getString(colorStr, null); if (bgColor != null) { if (!TextUtils.isEmpty(bgColor)) { int colorInt = WXResourceUtils.getColor(bgColor); if (!(colorInt == Color.TRANSPARENT)) { swipeLayout.setLoadingBgColor(colorInt); } } } swipeLayout.getFooterView().setRefreshView(loading.getHostView()); } } }
Example #3
Source File: SimpleComponentHolder.java From ucar-weex-core with Apache License 2.0 | 6 votes |
private void loadConstructor(){ Class<? extends WXComponent> c = mCompClz; Constructor<? extends WXComponent> constructor; try { constructor = c.getConstructor(WXSDKInstance.class, WXDomObject.class, WXVContainer.class); } catch (NoSuchMethodException e) { WXLogUtils.d("ClazzComponentCreator","Use deprecated component constructor"); try { //compatible deprecated constructor with 4 args constructor = c.getConstructor(WXSDKInstance.class, WXDomObject.class, WXVContainer.class, boolean.class); } catch (NoSuchMethodException e1) { try { //compatible deprecated constructor with 5 args constructor = c.getConstructor(WXSDKInstance.class, WXDomObject.class, WXVContainer.class,String.class, boolean.class); } catch (NoSuchMethodException e2) { throw new WXRuntimeException("Can't find constructor of component."); } } } mConstructor = constructor; }
Example #4
Source File: WXDomStatement.java From weex with Apache License 2.0 | 6 votes |
/** * Update the specified component's dom and mark it as old. * @param component the component to be updated */ private void updateDomObj(WXComponent component) { if (component == null) { return; } WXDomObject domObject = mRegistry.get(component.getRef()); if (domObject == null) { return; } domObject.old(); component.updateDom(domObject.clone()); if (component instanceof WXVContainer) { WXVContainer container = (WXVContainer) component; int count = container.childCount(); for (int i = 0; i < count; ++i) { updateDomObj(container.getChild(i)); } } }
Example #5
Source File: UWXFrameBaseActivity.java From ucar-weex-core with Apache License 2.0 | 6 votes |
@Override public void onPause() { super.onPause(); WXComponent comp = mInstance.getRootComponent(); if (comp != null) { WXEvent events = comp.getDomObject().getEvents(); boolean hasDeactived = events.contains(UConstants.Event.DEACTIVED); if (hasDeactived) { WXBridgeManager.getInstance().fireEvent(mInstance.getInstanceId(), comp.getRef(), UConstants.Event.DEACTIVED, null, null); } } if (mIsShakeDetectorStarted && mShakeDetector != null) { mShakeDetector.stop(); mIsShakeDetectorStarted = false; } }
Example #6
Source File: WXRenderStatement.java From weex with Apache License 2.0 | 6 votes |
private WXComponent generateComponentTree(WXDomObject dom, WXVContainer parent) { if (dom == null || parent == null) { return null; } WXComponent component = WXComponentFactory.newInstance(mWXSDKInstance, dom, parent, parent.isLazy()); mRegistry.put(dom.ref, component); if (component instanceof WXVContainer) { WXVContainer parentC = (WXVContainer) component; int count = dom.childCount(); WXDomObject child = null; for (int i = 0; i < count; ++i) { child = dom.getChild(i); if (child != null) { parentC.addChild(generateComponentTree(child, parentC)); } } } return component; }
Example #7
Source File: SimpleComponentHolder.java From weex-uikit with MIT License | 6 votes |
private void loadConstructor(){ Class<? extends WXComponent> c = mCompClz; Constructor<? extends WXComponent> constructor; try { constructor = c.getConstructor(WXSDKInstance.class, WXDomObject.class, WXVContainer.class); } catch (NoSuchMethodException e) { WXLogUtils.d("ClazzComponentCreator","Use deprecated component constructor"); try { //compatible deprecated constructor with 4 args constructor = c.getConstructor(WXSDKInstance.class, WXDomObject.class, WXVContainer.class, boolean.class); } catch (NoSuchMethodException e1) { try { //compatible deprecated constructor with 5 args constructor = c.getConstructor(WXSDKInstance.class, WXDomObject.class, WXVContainer.class,String.class, boolean.class); } catch (NoSuchMethodException e2) { throw new WXRuntimeException("Can't find constructor of component."); } } } mConstructor = constructor; }
Example #8
Source File: WXRenderStatement.java From weex with Apache License 2.0 | 6 votes |
/** * create RootView ,every weex Instance View has a rootView; * @see com.taobao.weex.dom.WXDomStatement#createBody(JSONObject) */ void createBody(WXComponent component) { long start = System.currentTimeMillis(); component.createView(mGodComponent, -1); if (WXEnvironment.isApkDebugable()) { WXLogUtils.renderPerformanceLog("createView", (System.currentTimeMillis() - start)); } start = System.currentTimeMillis(); component.applyLayoutAndEvent(component); component.bindData(component); if (WXEnvironment.isApkDebugable()) { WXLogUtils.renderPerformanceLog("bind", (System.currentTimeMillis() - start)); } if (component instanceof WXScroller) { WXScroller scroller = (WXScroller) component; if (scroller.getView() instanceof ScrollView) { mWXSDKInstance.setRootScrollView((ScrollView) scroller.getView()); } } mWXSDKInstance.setRootView(mGodComponent.getRealView()); if (mWXSDKInstance.getRenderStrategy() != WXRenderStrategy.APPEND_ONCE) { mWXSDKInstance.onViewCreated(mGodComponent); } }
Example #9
Source File: WXRenderStatement.java From weex with Apache License 2.0 | 6 votes |
WXComponent createBodyOnDomThread(WXDomObject dom) { if (mWXSDKInstance == null) { return null; } WXDomObject domObject = new WXDomObject(); domObject.type = WXBasicComponentType.DIV; domObject.ref = "god"; mGodComponent = (WXVContainer) WXComponentFactory.newInstance(mWXSDKInstance, domObject, null); mGodComponent.createView(null, -1); if (mGodComponent == null) { if (WXEnvironment.isApkDebugable()) { WXLogUtils.e("rootView failed!"); } //TODO error callback return null; } FrameLayout frameLayout = (FrameLayout) mGodComponent.getView(); ViewGroup.LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); frameLayout.setLayoutParams(layoutParams); frameLayout.setBackgroundColor(Color.TRANSPARENT); WXComponent component = generateComponentTree(dom, mGodComponent); mGodComponent.addChild(component); mRegistry.put(component.getRef(), component); return component; }
Example #10
Source File: BasicListComponent.java From weex-uikit with MIT License | 6 votes |
private void setAppearanceWatch(WXComponent component, int event, boolean enable) { AppearanceHelper item = mAppearComponents.get(component.getRef()); if (item != null) { item.setWatchEvent(event, enable); } else if (!enable) { //Do nothing if disable target not exist. } else { WXComponent dChild = findDirectListChild(component); int index = mChildren.indexOf(dChild); if (index != -1) { item = new AppearanceHelper(component, index); item.setWatchEvent(event, true); mAppearComponents.put(component.getRef(), item); } } }
Example #11
Source File: BasicListComponent.java From ucar-weex-core with Apache License 2.0 | 5 votes |
@Nullable private WXComponent findComponentByAnchorName(@NonNull WXComponent root, @NonNull String anchorName) { long start = 0; if (WXEnvironment.isApkDebugable()) { start = System.currentTimeMillis(); } Deque<WXComponent> deque = new ArrayDeque<>(); deque.add(root); while (!deque.isEmpty()) { WXComponent curComponent = deque.removeFirst(); ImmutableDomObject object = curComponent.getDomObject(); if (object != null) { String isAnchorSet = WXUtils.getString(object.getAttrs().get(anchorName), null); //hit if (isAnchorSet != null && isAnchorSet.equals("true")) { if (WXEnvironment.isApkDebugable()) { WXLogUtils.d("dragPerf", "findComponentByAnchorName time: " + (System.currentTimeMillis() - start) + "ms"); } return curComponent; } } if (curComponent instanceof WXVContainer) { WXVContainer container = (WXVContainer) curComponent; for (int i = 0, len = container.childCount(); i < len; i++) { WXComponent child = container.getChild(i); deque.add(child); } } } if (WXEnvironment.isApkDebugable()) { WXLogUtils.d("dragPerf", "findComponentByAnchorName elapsed time: " + (System.currentTimeMillis() - start) + "ms"); } return null; }
Example #12
Source File: WXDomStatement.java From weex-uikit with MIT License | 5 votes |
/** * Create a command object for removing the event listener of the corresponding {@link * WXDomObject} and put the command event in the queue. * @param ref Reference of the dom. * @param type the type of the event, this may be a plain event defined in * {@link com.taobao.weex.common.Constants.Event} or a gesture defined in {@link com.taobao * .weex.ui.view.gesture.WXGestureType} */ void removeEvent(final String ref, final String type) { if (mDestroy) { return; } WXSDKInstance instance = WXSDKManager.getInstance().getSDKInstance(mInstanceId); final WXDomObject domObject = mRegistry.get(ref); if (domObject == null) { if (instance != null) { instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_ERR_DOM_REMOVEEVENT); } return; } domObject.removeEvent(type); mNormalTasks.add(new IWXRenderTask() { @Override public void execute() { WXComponent comp = mWXRenderManager.getWXComponent(mInstanceId,ref); if(comp != null){ //sync dom change to component comp.updateDom(domObject); mWXRenderManager.removeEvent(mInstanceId, ref, type); } } @Override public String toString() { return "removeEvent"; } }); mDirty = true; if (instance != null) { instance.commitUTStab(IWXUserTrackAdapter.DOM_MODULE, WXErrorCode.WX_SUCCESS); } }
Example #13
Source File: WXRenderStatement.java From weex-uikit with MIT License | 5 votes |
/** * @see WXDomObject#removeEvent(String) */ void removeEvent(String ref, String type) { WXComponent component = mRegistry.get(ref); if (component == null) { return ; } component.removeEvent(type); }
Example #14
Source File: BasicListComponent.java From ucar-weex-core with Apache License 2.0 | 5 votes |
private @Nullable WXComponent findDirectListChild(WXComponent comp) { WXComponent parent; if (comp == null || (parent = comp.getParent()) == null) { return null; } if (parent instanceof BasicListComponent) { return comp; } return findDirectListChild(parent); }
Example #15
Source File: WXSDKInstanceTest.java From ucar-weex-core with Apache License 2.0 | 5 votes |
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(); }
Example #16
Source File: WXRenderManager.java From weex-uikit with MIT License | 5 votes |
public @Nullable WXComponent getWXComponent(String instanceId, String ref) { if(instanceId == null || TextUtils.isEmpty(ref)){ return null; } WXRenderStatement stmt = getWXRenderStatement(instanceId); return stmt == null?null:stmt.getComponent(ref); }
Example #17
Source File: WXAnimationModule.java From weex-uikit with MIT License | 5 votes |
public static void startAnimation(WXSDKInstance mWXSDKInstance, WXComponent component, @NonNull WXAnimationBean animationBean, @Nullable String callback) { if(component == null){ return; } if (component.getHostView() == null) { AnimationHolder holder = new AnimationHolder(animationBean, callback); component.postAnimation(holder); return; } try { Animator animator = createAnimator(animationBean, component.getHostView(),mWXSDKInstance.getViewPortWidth()); if (animator != null) { Animator.AnimatorListener animatorCallback = createAnimatorListener(mWXSDKInstance, callback); if(Build.VERSION.SDK_INT<Build.VERSION_CODES.JELLY_BEAN_MR2) { component.getHostView().setLayerType(View.LAYER_TYPE_HARDWARE, null); } Interpolator interpolator = createTimeInterpolator(animationBean); if (animatorCallback != null) { animator.addListener(animatorCallback); } if (interpolator != null) { animator.setInterpolator(interpolator); } animator.setDuration(animationBean.duration); animator.start(); } } catch (RuntimeException e) { e.printStackTrace(); WXLogUtils.e("", e); } }
Example #18
Source File: PollingVDomMonitor.java From analyzer-of-android-for-Apache-Weex with Apache License 2.0 | 5 votes |
@Override public void onTrackNode(@NonNull WXComponent component, int layer) { if(layer < MAX_VDOM_LAYER) { return; } View hostView = component.getHostView(); if(hostView == null) { return; } if(mViewHighlighter != null) { mViewHighlighter.addHighlightedView(hostView); } }
Example #19
Source File: DefaultDragHelper.java From ucar-weex-core with Apache License 2.0 | 5 votes |
@Override public void onDragStart(@NonNull WXComponent component, int from) { if (WXEnvironment.isApkDebugable()) { WXLogUtils.d(TAG, "list on drag start : from index " + from); } mEventTrigger.triggerEvent(EVENT_START_DRAG, buildEvent(component.getRef(), from, -1)); }
Example #20
Source File: WXListComponent.java From weex-uikit with MIT License | 5 votes |
@Override public void addChild(WXComponent child, int index) { super.addChild(child, index); if (child == null || index < -1) { return; } setRefreshOrLoading(child); }
Example #21
Source File: WXScrollView.java From weex-uikit with MIT License | 5 votes |
private View procSticky(Map<String, HashMap<String, WXComponent>> mStickyMap) { if (mStickyMap == null) { return null; } HashMap<String, WXComponent> stickyMap = mStickyMap.get(mWAScroller.getRef()); if (stickyMap == null) { return null; } Iterator<Entry<String, WXComponent>> iterator = stickyMap.entrySet().iterator(); Entry<String, WXComponent> entry = null; WXComponent stickyData; while (iterator.hasNext()) { entry = iterator.next(); stickyData = entry.getValue(); getLocationOnScreen(stickyScrollerP); stickyData.getHostView().getLocationOnScreen(stickyViewP); int parentH = 0; if(stickyData.getParent()!=null && stickyData.getParent().getRealView()!=null){ parentH=stickyData.getParent().getRealView().getHeight(); } int stickyViewH = stickyData.getHostView().getHeight(); int stickyShowPos = stickyScrollerP[1]; int stickyStartHidePos = -parentH + stickyScrollerP[1] + stickyViewH; if (stickyViewP[1] <= stickyShowPos && stickyViewP[1] >= (stickyStartHidePos - stickyViewH)) { mStickyOffset = stickyViewP[1] - stickyStartHidePos; return stickyData.getHostView(); } } return null; }
Example #22
Source File: WXListComponent.java From weex with Apache License 2.0 | 5 votes |
/** * Create an instance of {@link ListBaseViewHolder} for the given viewType (not for the given * index). This method will look up for the first component that fits the viewType requirement and * doesn't be used. Then create the certain type of view, detach the view f[rom the component. * * @param parent the ViewGroup into which the new view will be inserted * @param viewType the type of the new view * @return the created view holder. */ @Override public ListBaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { WXLogUtils.d(TAG, "onCreateViewHolder"); if (mChildren != null) { for (int i = 0; i < childCount(); i++) { WXComponent component = getChild(i); setRefreshOrLoadingListener(component); if (component == null || component.isUsing() || getItemViewType(i) != viewType) continue; if (component instanceof WXRefresh) { bounceRecyclerView.setHeaderView(component.getView()); return createVHForWXRefresh(component, viewType); } else if (component instanceof WXLoading) { bounceRecyclerView.setFooterView(component.getView()); return createVHForWXLoading(component, viewType); } else if (component.mDomObj!=null && component.mDomObj.isFixed()) { return createVHForFakeComponent(viewType); } else { if (component.getRealView() != null) { return new ListBaseViewHolder(component, viewType); } else { long begin=System.currentTimeMillis(); component.lazy(false); component.createView(this, -1); WXLogUtils.d(TAG,"onCreateViewHolder lazy create:"+(System.currentTimeMillis()-begin)+" Thread:"+Thread.currentThread().getName()); return new ListBaseViewHolder(component, viewType); } } } } WXLogUtils.e(TAG, "Cannot find request viewType: " + viewType); throw new WXRuntimeException("mChildren is null"); }
Example #23
Source File: BaseBounceView.java From ucar-weex-core with Apache License 2.0 | 5 votes |
public void removeFooterView(WXComponent loading){ setLoadmoreEnable(false); if(swipeLayout!=null){ if(swipeLayout.getFooterView()!=null){ swipeLayout.setLoadingHeight(0); swipeLayout.getFooterView().removeView(loading.getHostView()); swipeLayout.finishPullLoad(); } } }
Example #24
Source File: BasicListComponent.java From ucar-weex-core with Apache License 2.0 | 5 votes |
/** * Remove the child from list. This method will use {@link * java.util.List#indexOf(Object)} to retrieve the component to be deleted. Like {@link * #addChild(WXComponent)}, this method will not refresh the view immediately, the adapter will * decide when to refresh. * * @param child the child to be removed */ @Override public void remove(WXComponent child, boolean destroy) { int index = mChildren.indexOf(child); if (destroy) { child.detachViewAndClearPreInfo(); } unBindViewType(child); T view = getHostView(); if (view == null) { return; } boolean isRemoveAnimation = isRemoveAnimation(child); if (isRemoveAnimation) { view.getInnerView().setItemAnimator(mItemAnimator); } else { view.getInnerView().setItemAnimator(null); } view.getRecyclerViewBaseAdapter().notifyItemRemoved(index); if (WXEnvironment.isApkDebugable()) { WXLogUtils.d(TAG, "removeChild child at " + index); } super.remove(child, destroy); }
Example #25
Source File: WXListComponent.java From weex-uikit with MIT License | 5 votes |
/** * Setting refresh view and loading view * * @param child the refresh_view or loading_view */ private boolean setRefreshOrLoading(final WXComponent child) { if (getHostView() == null) { WXLogUtils.e(TAG, "setRefreshOrLoading: HostView == null !!!!!! check list attr has append =tree"); return true; } if (child instanceof WXRefresh) { getHostView().setOnRefreshListener((WXRefresh) child); getHostView().postDelayed(new Runnable() { @Override public void run() { getHostView().setHeaderView(child); } }, 100); return true; } if (child instanceof WXLoading) { getHostView().setOnLoadingListener((WXLoading) child); getHostView().postDelayed(new Runnable() { @Override public void run() { getHostView().setFooterView(child); } }, 100); return true; } return false; }
Example #26
Source File: WXSDKInstance.java From weex-uikit with MIT License | 5 votes |
/******************************** * end hook Activity life cycle callback ********************************************************/ public void onViewDisappear(){ WXComponent comp = getRootComponent(); if(comp != null) { WXBridgeManager.getInstance().fireEvent(this.mInstanceId, comp.getRef(), Constants.Event.VIEWDISAPPEAR, null, null); //call disappear of nested instances for(OnInstanceVisibleListener instance:mVisibleListeners){ instance.onDisappear(); } } }
Example #27
Source File: LayoutParamsProperty.java From ucar-weex-core with Apache License 2.0 | 5 votes |
@Override public void set(View object, Integer value) { LayoutParams layoutParams; if (object != null && (layoutParams = object.getLayoutParams()) != null) { setProperty(layoutParams, value); if (object instanceof IRenderResult) { WXComponent component = ((IRenderResult) object).getComponent(); if (component != null) { component.notifyNativeSizeChanged(layoutParams.width, layoutParams.height); } } object.requestLayout(); } }
Example #28
Source File: WXListComponent.java From weex with Apache License 2.0 | 5 votes |
@Override public void remove(WXComponent child, boolean destroy) { int index = mChildren.indexOf(child); if (destroy) { child.detachViewAndClearPreInfo(); } getView().getAdapter().notifyItemRemoved(index); if (WXEnvironment.isApkDebugable()) { WXLogUtils.d(TAG, "removeChild child at " + index); } super.remove(child, destroy); }
Example #29
Source File: WXRenderStatement.java From weex-uikit with MIT License | 5 votes |
/** * set extra information of View */ void setExtra(String ref, Object extra) { WXComponent component = mRegistry.get(ref); if (component == null) { return; } component.updateExtra(extra); }
Example #30
Source File: RenderActionContextImpl.java From ucar-weex-core with Apache License 2.0 | 5 votes |
/** * set layout information of View */ void setLayout(String ref, WXDomObject domObject) { WXComponent component = mRegistry.get(ref); if (component == null) { return; } component.setLayout(domObject); }