com.taobao.weex.ui.component.WXBasicComponentType Java Examples

The following examples show how to use com.taobao.weex.ui.component.WXBasicComponentType. 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: App.java    From CrazyDaily with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化Weex
 */
private void initWeex() {
    InitConfig config = new InitConfig.Builder()
            .setImgAdapter(new WXImageAdapter())
            .setHttpAdapter(new WXHttpAdapter(mAppComponent.provideOkhttpClient()))
            .build();
    WXSDKEngine.initialize(this, config);
    try {
        WXSDKEngine.registerComponent("tabPager", WXTabPagerComponent.class);
        WXSDKEngine.registerComponent(WXBasicComponentType.WEB, WXWebComponent.class);
        WXSDKEngine.registerModule("crazyDaily", CrazyDailyModule.class);
        WXSDKEngine.registerModule("webview", WXWebViewModule.class, true);
        WXSDKEngine.registerModule("log", LogModule.class);
    } catch (WXException e) {
        LoggerUtil.d(e.getMessage());
    }
}
 
Example #2
Source File: WXListDomObject.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
@Override
protected Map<String, String> getDefaultStyle() {
    Map<String,String> map = new ArrayMap<>();

    boolean isVertical = true;
    if (parent != null) {
        if (parent.getType() != null) {
            if (parent.getType().equals(WXBasicComponentType.HLIST)) {
                isVertical = false;
            }
        }
    }

    String prop = isVertical ? Constants.Name.HEIGHT : Constants.Name.WIDTH;
    if (getStyles().get(prop) == null &&
        getStyles().get(Constants.Name.FLEX) == null) {
        map.put(Constants.Name.FLEX, "1");
    }

    return map;
}
 
Example #3
Source File: WXListDomObject.java    From weex-uikit with MIT License 6 votes vote down vote up
@Override
protected Map<String, String> getDefaultStyle() {
    Map<String,String> map = new ArrayMap<>();

    boolean isVertical = true;
    if (parent != null) {
        if (parent.getType() != null) {
            if (parent.getType().equals(WXBasicComponentType.HLIST)) {
                isVertical = false;
            }
        }
    }

    String prop = isVertical ? Constants.Name.HEIGHT : Constants.Name.WIDTH;
    if (getStyles().get(prop) == null &&
        getStyles().get(Constants.Name.FLEX) == null) {
        map.put(Constants.Name.FLEX, "1");
    }

    return map;
}
 
Example #4
Source File: WXRenderStatement.java    From weex with Apache License 2.0 6 votes vote down vote up
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 #5
Source File: WXSDKEngine.java    From weex with Apache License 2.0 6 votes vote down vote up
private static void register() {
  try {
    registerComponent(WXBasicComponentType.TEXT, WXText.class, false);
    registerComponent(WXBasicComponentType.IMG, WXImage.class, false);
    registerComponent(WXBasicComponentType.DIV, WXDiv.class, false);
    registerComponent(WXBasicComponentType.IMAGE, WXImage.class, false);
    registerComponent(WXBasicComponentType.CONTAINER, WXDiv.class, false);
    registerComponent(WXBasicComponentType.SCROLLER, WXScroller.class, false);
    registerComponent(WXBasicComponentType.SLIDER, WXSlider.class, true);

    registerComponent(WXListComponent.class, false,WXBasicComponentType.LIST,WXBasicComponentType.VLIST);
    registerComponent(HorizontalListComponent.class,false,WXBasicComponentType.HLIST);
    registerComponent(WXBasicComponentType.CELL, WXCell.class, true);
    registerComponent(WXBasicComponentType.INDICATOR, WXIndicator.class, true);
    registerComponent(WXBasicComponentType.VIDEO, WXVideo.class, false);
    registerComponent(WXBasicComponentType.INPUT, WXInput.class, false);
    registerComponent(WXBasicComponentType.SWITCH, WXSwitch.class, false);
    registerComponent(WXBasicComponentType.A, WXA.class, false);
    registerComponent(WXBasicComponentType.EMBED, WXEmbed.class, true);
    registerComponent(WXBasicComponentType.WEB, WXWeb.class);
    registerComponent(WXBasicComponentType.REFRESH, WXRefresh.class);
    registerComponent(WXBasicComponentType.LOADING, WXLoading.class);
    registerComponent(WXBasicComponentType.LOADING_INDICATOR, WXLoadingIndicator.class);

    registerModule("dom", WXDomModule.class, true);
    registerModule("modal", WXModalUIModule.class, false);
    registerModule("instanceWrap", WXInstanceWrap.class, true);
    registerModule("animation", WXAnimationModule.class, true);
    registerModule("webview", WXWebViewModule.class, true);
    registerModule("navigator", WXNavigatorModule.class);
    registerModule("stream", WXStreamModule.class);

    registerDomObject(WXBasicComponentType.TEXT, WXTextDomObject.class);
    registerDomObject(WXBasicComponentType.INPUT, WXTextDomObject.class);
    registerDomObject(WXBasicComponentType.SWITCH, WXSwitchDomObject.class);
  } catch (WXException e) {
    WXLogUtils.e("[WXSDKEngine] register:" + WXLogUtils.getStackTrace(e));
  }
}
 
Example #6
Source File: WXRecyclerDomObject.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Override
public void add(WXDomObject child, int index) {
    super.add(child, index);

    if (WXBasicComponentType.CELL.equals(child.getType())) {
        if (!mIsPreCalculateCellWidth) {
            preCalculateCellWidth();
        }
        if(mColumnWidth!=0 && mColumnWidth!= Float.NaN) {
            child.getStyles().put(Constants.Name.WIDTH, mColumnWidth);
        }
    }
}
 
Example #7
Source File: WXRecyclerDomObject.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public void updateRecyclerAttr(){
    preCalculateCellWidth();
    if(mColumnWidth ==0 && mColumnWidth == Float.NaN){
        WXLogUtils.w("preCalculateCellWidth mColumnGap :" + mColumnGap + " mColumnWidth:" + mColumnWidth + " mColumnCount:" + mColumnCount);
        return;
    }
    int count = getChildCount();
    for(int i=0;i<count; i++){
        WXDomObject domObject = getChild(i);
        if(WXBasicComponentType.CELL.equals(domObject.getType())) {
            getChild(i).getStyles().put(Constants.Name.WIDTH, mColumnWidth);
        }
    }
}
 
Example #8
Source File: WXListComponent.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public WXListComponent(WXSDKInstance instance, WXDomObject node, WXVContainer parent, boolean lazy) {
  super(instance, node, parent);
  if (node != null && node instanceof WXRecyclerDomObject) {
    mDomObject = (WXRecyclerDomObject) node;
    mDomObject.preCalculateCellWidth();

    if(WXBasicComponentType.WATERFALL.equals(node.getType())){
      mLayoutType = WXRecyclerView.TYPE_STAGGERED_GRID_LAYOUT;
    }else{
      mLayoutType = mDomObject.getLayoutType();
    }
    updateRecyclerAttr();

  }
}
 
Example #9
Source File: WXSDKInstance.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityPause() {
  onViewDisappear();
  if(!isCommit){
    Set<String> componentTypes= WXComponentFactory.getComponentTypesByInstanceId(getInstanceId());
    if(componentTypes!=null && componentTypes.contains(WXBasicComponentType.SCROLLER)){
      mWXPerformance.useScroller=1;
    }
    mWXPerformance.maxDeepViewLayer=getMaxDeepLayer();
    if (mUserTrackAdapter != null) {
      mUserTrackAdapter.commit(mContext, null, IWXUserTrackAdapter.LOAD, mWXPerformance, getUserTrackParams());
    }
    isCommit=true;
  }
  // module listen Activity onActivityPause
  WXModuleManager.onActivityPause(getInstanceId());
  if(mRootComp != null) {
    mRootComp.onActivityPause();
  }else{
    WXLogUtils.w("Warning :Component tree has not build completely,onActivityPause can not be call!");
  }

  WXLogUtils.i("Application onActivityPause()");
  if (!mCurrentGround) {
    WXLogUtils.i("Application to be in the backround");
    Intent intent = new Intent(WXGlobalEventReceiver.EVENT_ACTION);
    intent.putExtra(WXGlobalEventReceiver.EVENT_NAME, Constants.Event.PAUSE_EVENT);
    intent.putExtra(WXGlobalEventReceiver.EVENT_WX_INSTANCEID, getInstanceId());
    mContext.sendBroadcast(intent);
    this.mCurrentGround = true;
  }
}
 
Example #10
Source File: WXSDKInstance.java    From weex-uikit with MIT License 5 votes vote down vote up
@Override
public void onActivityPause() {
  onViewDisappear();
  if(!isCommit){
    Set<String> componentTypes= WXComponentFactory.getComponentTypesByInstanceId(getInstanceId());
    if(componentTypes!=null && componentTypes.contains(WXBasicComponentType.SCROLLER)){
      mWXPerformance.useScroller=1;
    }
    mWXPerformance.maxDeepViewLayer=getMaxDeepLayer();
    if (mUserTrackAdapter != null) {
      mUserTrackAdapter.commit(mContext, null, IWXUserTrackAdapter.LOAD, mWXPerformance, getUserTrackParams());
    }
    isCommit=true;
  }
  // module listen Activity onActivityPause
  WXModuleManager.onActivityPause(getInstanceId());
  if(mRootComp != null) {
    mRootComp.onActivityPause();
  }else{
    WXLogUtils.w("Warning :Component tree has not build completely,onActivityPause can not be call!");
  }

  Intent intent=new Intent(WXGlobalEventReceiver.EVENT_ACTION);
  intent.putExtra(WXGlobalEventReceiver.EVENT_NAME,Constants.Event.PAUSE_EVENT);
  intent.putExtra(WXGlobalEventReceiver.EVENT_WX_INSTANCEID,getInstanceId());
  mContext.sendBroadcast(intent);
}
 
Example #11
Source File: WXDomObject.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
/**
 * Parse the jsonObject to {@link WXDomObject} recursively
 * @param json the original JSONObject
 * @return Dom Object corresponding to the JSONObject.
 */
public static  @Nullable WXDomObject parse(JSONObject json, WXSDKInstance wxsdkInstance){
    if (json == null || json.size() <= 0) {
      return null;
    }

    String type = (String) json.get(TYPE);

    if (wxsdkInstance.isNeedValidate()) {
      WXValidateProcessor processor = WXSDKManager.getInstance()
              .getValidateProcessor();
      if (processor != null) {
        WXValidateProcessor.WXComponentValidateResult result = processor
                .onComponentValidate(wxsdkInstance, type);
        if (result != null && !result.isSuccess) {
          type = TextUtils.isEmpty(result.replacedComponent) ? WXBasicComponentType.DIV
                  : result.replacedComponent;
          json.put(TYPE, type);
          if(WXEnvironment.isApkDebugable()&&result.validateInfo!=null){
            String tag = "[WXDomObject]onComponentValidate failure. >>> "+result.validateInfo.toJSONString();
            WXLogUtils.e(tag);
          }
        }
      }
    }

    WXDomObject domObject = WXDomObjectFactory.newInstance(type);

    domObject.setViewPortWidth(wxsdkInstance.getInstanceViewPortWidth());

    if(domObject == null){
      return null;
    }
    domObject.parseFromJson(json);
    domObject.mDomContext = wxsdkInstance;

    Object children = json.get(CHILDREN);
    if (children != null && children instanceof JSONArray) {
      JSONArray childrenArray = (JSONArray) children;
      int count = childrenArray.size();
      for (int i = 0; i < count; ++i) {
        domObject.add(parse(childrenArray.getJSONObject(i),wxsdkInstance),-1);
      }
    }

    return domObject;
}
 
Example #12
Source File: WXSDKEngine.java    From weex-uikit with MIT License 3 votes vote down vote up
private static void register() {
  BatchOperationHelper batchHelper = new BatchOperationHelper(WXBridgeManager.getInstance());
  try {
    registerComponent(
      new SimpleComponentHolder(
        WXText.class,
        new WXText.Creator()
      ),
      false,
      WXBasicComponentType.TEXT
    );
    registerComponent(
      new SimpleComponentHolder(
        WXDiv.class,
        new WXDiv.Ceator()
      ),
      false,
      WXBasicComponentType.CONTAINER,
      WXBasicComponentType.DIV,
      WXBasicComponentType.HEADER,
      WXBasicComponentType.FOOTER
    );
    registerComponent(
      new SimpleComponentHolder(
        WXImage.class,
        new WXImage.Ceator()
      ),
      false,
      WXBasicComponentType.IMAGE,
      WXBasicComponentType.IMG
    );
    registerComponent(
      new SimpleComponentHolder(
        WXScroller.class,
        new WXScroller.Creator()
      ),
      false,
      WXBasicComponentType.SCROLLER
    );
    registerComponent(
      new SimpleComponentHolder(
        WXSlider.class,
        new WXSlider.Creator()
      ),
      true,
      WXBasicComponentType.SLIDER
    );
    registerComponent(
      new SimpleComponentHolder(
              WXSliderNeighbor.class,
        new WXSliderNeighbor.Creator()
      ),
      true,
      WXBasicComponentType.SLIDER_NEIGHBOR
    );
    registerComponent(SimpleListComponent.class,false,"simplelist");
    registerComponent(WXListComponent.class, false,WXBasicComponentType.LIST,WXBasicComponentType.VLIST);
    registerComponent(HorizontalListComponent.class,false,WXBasicComponentType.HLIST);
    registerComponent(WXBasicComponentType.CELL, WXCell.class, true);
    registerComponent(WXBasicComponentType.INDICATOR, WXIndicator.class, true);
    registerComponent(WXBasicComponentType.VIDEO, WXVideo.class, false);
    registerComponent(WXBasicComponentType.INPUT, WXInput.class, false);
    registerComponent(WXBasicComponentType.TEXTAREA, Textarea.class,false);
    registerComponent(WXBasicComponentType.SWITCH, WXSwitch.class, false);
    registerComponent(WXBasicComponentType.A, WXA.class, false);
    registerComponent(WXBasicComponentType.EMBED, WXEmbed.class, true);
    registerComponent(WXBasicComponentType.WEB, WXWeb.class);
    registerComponent(WXBasicComponentType.REFRESH, WXRefresh.class);
    registerComponent(WXBasicComponentType.LOADING, WXLoading.class);
    registerComponent(WXBasicComponentType.LOADING_INDICATOR, WXLoadingIndicator.class);
    registerComponent(WXBasicComponentType.HEADER, WXHeader.class);

    registerModule("modal", WXModalUIModule.class, false);
    registerModule("instanceWrap", WXInstanceWrap.class, true);
    registerModule("animation", WXAnimationModule.class, true);
    registerModule("webview", WXWebViewModule.class, true);
    registerModule("navigator", WXNavigatorModule.class);
    registerModule("stream", WXStreamModule.class);
    registerModule("timer", WXTimerModule.class, true);
    registerModule("storage", WXStorageModule.class, true);
    registerModule("clipboard", WXClipboardModule.class, true);
    registerModule("globalEvent",WXGlobalEventModule.class);
    registerModule("picker", WXPickersModule.class);
    registerModule("meta", WXMetaModule.class,true);
    registerModule("webSocket", WebSocketModule.class);


    registerDomObject(WXBasicComponentType.INDICATOR, WXIndicator.IndicatorDomNode.class);
    registerDomObject(WXBasicComponentType.TEXT, WXTextDomObject.class);
    registerDomObject(WXBasicComponentType.INPUT, BasicEditTextDomObject.class);
    registerDomObject(WXBasicComponentType.TEXTAREA, TextAreaEditTextDomObject.class);
    registerDomObject(WXBasicComponentType.SWITCH, WXSwitchDomObject.class);
    registerDomObject(WXBasicComponentType.LIST, WXListDomObject.class);
    registerDomObject(WXBasicComponentType.VLIST, WXListDomObject.class);
    registerDomObject(WXBasicComponentType.HLIST, WXListDomObject.class);
    registerDomObject(WXBasicComponentType.SCROLLER, WXScrollerDomObject.class);
  } catch (WXException e) {
    WXLogUtils.e("[WXSDKEngine] register:", e);
  }
  batchHelper.flush();
}