Java源码示例:com.taobao.weex.common.WXRenderStrategy

示例1
public void render(String initData, int position) {
//
      if (true) {

        mInstance.render(
            "testPage",
            loadAssets(),
            null,
            initData,
            WXRenderStrategy.DATA_RENDER
        );
      } else {
//
        mInstance.render(
            "testPage",
            loadBytes(),
            null,
            initData
        );
      }
      mTextView.setText(String.valueOf(position));
      mRendered = true;
    }
 
示例2
/**
 * 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();
  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.getInnerView() instanceof ScrollView) {
      mWXSDKInstance.setRootScrollView((ScrollView) scroller.getInnerView());
    }
  }
  mWXSDKInstance.onRootCreated(component);
  if (mWXSDKInstance.getRenderStrategy() != WXRenderStrategy.APPEND_ONCE) {
    mWXSDKInstance.onCreateFinish();
  }
}
 
示例3
/**
 * 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);
  }
}
 
示例4
protected void renderPage(String template,String source,String jsonInitData){
  AssertUtil.throwIfNull(mContainer,new RuntimeException("Can't render page, container is null"));
  Map<String, Object> options = new HashMap<>();
  options.put(WXSDKInstance.BUNDLE_URL, source);
  // Set options.bundleDigest
  try {
    String banner = WXUtils.getBundleBanner(template);
    JSONObject jsonObj = JSONObject.parseObject(banner);
    String digest = null;
    if (jsonObj != null) {
      digest = jsonObj.getString(Constants.CodeCache.BANNER_DIGEST);
    }
    if (digest != null) {
      options.put(Constants.CodeCache.DIGEST, digest);
    }
  } catch (Throwable t) {}
  //Set options.codeCachePath
  String path = WXEnvironment.getFilesDir(getApplicationContext());
  path += File.separator;
  path += Constants.CodeCache.SAVE_PATH;
  path += File.separator;
  options.put(Constants.CodeCache.PATH, path);

  mInstance.setTrackComponent(true);
  mInstance.render(
    getPageName(),
    template,
    options,
    jsonInitData,
    WXRenderStrategy.APPEND_ASYNC);
}
 
示例5
protected void renderPageByURL(String url,String jsonInitData){
  AssertUtil.throwIfNull(mContainer,new RuntimeException("Can't render page, container is null"));
  Map<String, Object> options = new HashMap<>();
  options.put(WXSDKInstance.BUNDLE_URL, url);
  mInstance.setTrackComponent(true);
  mInstance.renderByUrl(
    getPageName(),
    url,
    options,
    jsonInitData,
    WXRenderStrategy.APPEND_ASYNC);
}
 
示例6
public void preLoad(String url) {

        boolean preDownLoad = url.contains("preDownLoad=true");
        boolean preInit = url.contains("preInitInstance=rax") || url.contains("preInitInstance=vue");
        if (!preDownLoad && !preInit){
            return;
        }


        WXSDKInstance instance = new WXSDKInstance();
        Map<String, Object> options = new HashMap<>();
        options.put("bundleUrl", url);
        options.put("render_strategy", WXRenderStrategy.APPEND_ASYNC.toString());
        options.put("wxPreInit",preInit);
        options.put("wxPreDownLoad",preDownLoad);
        String script = null;
        if (preInit){
            if (url.contains("preInitInstance=rax")) {
                script = "// { \"framework\": \"Rax\" }\n";
            } else if (url.contains("preInitInstance=vue")) {
                script = "// { \"framework\": \"Vue\" }\n";
            } else {
                WXLogUtils.e("WXPreLoadManager", "unsupport init bundle type :" + url);
            }
            if (null != script) {
                mPreInitInstanceMap.put(url, instance);
                Log.d("test->", "start preInit: ");
                instance.preInit(url, script, options, null, WXRenderStrategy.APPEND_ASYNC);
            }
        }
        if (preDownLoad){
            if (!mPreInitInstanceMap.containsKey(url)) {
                mPreInitInstanceMap.put(url, instance);
            }
            Log.d("test->", "start preDownLoad: ");
            instance.preDownLoad(url, options, null, WXRenderStrategy.APPEND_ASYNC);
        }
    }
 
示例7
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mWXSDKInstance = new WXSDKInstance(this);
    mWXSDKInstance.registerRenderListener(this);
    final Intent intent = getIntent();
    mWXSDKInstance.render(intent.getStringExtra(ActivityConstant.PAGE), WXFileUtils.loadAsset(intent.getStringExtra(ActivityConstant.PATH), this), null, null, WXRenderStrategy.APPEND_ASYNC);
}
 
示例8
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    String type = getArguments().getString("type");
    mGankIoContent = (FrameLayout) inflater.inflate(R.layout.layout_weex_gank_io, container, false);
    final Context context = getActivity();
    mWXSDKInstance = new WXSDKInstance(context);
    mWXSDKInstance.registerRenderListener(this);
    Map<String, Object> options = new HashMap<>();
    options.put("type", type);
    mWXSDKInstance.render("GankioList", WXFileUtils.loadAsset("weex/gankio/gankiolist.js", context), options, null, WXRenderStrategy.APPEND_ASYNC);
    return mGankIoContent;
}
 
示例9
protected void renderPageByURL(String url, String jsonInitData) {
  CommonUtils.throwIfNull(mContainer, new RuntimeException("Can't render page, container is null"));
  Map<String, Object> options = new HashMap<>();
  options.put(WXSDKInstance.BUNDLE_URL, url);
  mInstance.renderByUrl(
      getPageName(),
      url,
      options,
      jsonInitData,
      CommonUtils.getDisplayWidth(this),
      CommonUtils.getDisplayHeight(this),
      WXRenderStrategy.APPEND_ASYNC);
}
 
示例10
private void render(String tempUrl) {
    mWXSDKInstance.renderByUrl(
            "",
            tempUrl,
            null,
            null,
            CommonUtils.getDisplayWidth(getActivity()),
            CommonUtils.getDisplayHeight(getActivity()),
            WXRenderStrategy.APPEND_ASYNC);
}
 
示例11
protected void renderPageByURL(String url, String jsonInitData) {
    mUrl = url;
    CommonUtils.throwIfNull(mContainer, new RuntimeException("Can't render page, container is null"));
    Map<String, Object> options = new HashMap<>();
    options.put(WXSDKInstance.BUNDLE_URL, url);
    mInstance.renderByUrl(
            getPageName(),
            url,
            options,
            jsonInitData,
            CommonUtils.getDisplayWidth(this),
            CommonUtils.getDisplayHeight(this),
            WXRenderStrategy.APPEND_ASYNC);
}
 
示例12
@Override
public void executeRender(RenderActionContext context) {
  WXSDKInstance instance = context.getInstance();
  if (instance.getRenderStrategy() == WXRenderStrategy.APPEND_ONCE) {
    instance.onCreateFinish();
  }
  instance.onRenderSuccess(mLayoutWidth, mLayoutHeight);
}
 
示例13
private WXSDKInstance createInstance() {
  WXSDKInstance sdkInstance = getInstance().createNestedInstance(this);
  getInstance().addOnInstanceVisibleListener(this);
  sdkInstance.registerRenderListener(mListener);

  String url=src;
  if(mListener != null && mListener.mEventListener != null){
    url=mListener.mEventListener.transformUrl(src);
    if(!mListener.mEventListener.onPreCreate(this,src)){
      //cancel render
      return null;
    }
  }

  if(TextUtils.isEmpty(url)){
    mListener.mEventListener.onException(this,WXRenderErrorCode.WX_USER_INTERCEPT_ERROR,"degradeToH5");
    return sdkInstance;
  }

  ViewGroup.LayoutParams layoutParams = getHostView().getLayoutParams();
  sdkInstance.renderByUrl(WXPerformance.DEFAULT,
                          url,
                          null, null, layoutParams.width,
                          layoutParams.height,
                          WXRenderStrategy.APPEND_ASYNC);
  return sdkInstance;
}
 
示例14
private void renderInternal(String pageName,
                            String template,
                            Map<String, Object> options,
                            String jsonInitData,
                            WXRenderStrategy flag){
  if (mRendered || TextUtils.isEmpty(template)) {
    return;
  }

  ensureRenderArchor();

  Map<String, Object> renderOptions = options;
  if (renderOptions == null) {
    renderOptions = new HashMap<>();
  }

  if (WXEnvironment.sDynamicMode && !TextUtils.isEmpty(WXEnvironment.sDynamicUrl) && renderOptions.get("dynamicMode") == null) {
    renderOptions.put("dynamicMode", "true");
    renderByUrl(pageName, WXEnvironment.sDynamicUrl, renderOptions, jsonInitData, flag);
    return;
  }

  mWXPerformance.pageName = pageName;
  mWXPerformance.JSTemplateSize = template.length() / 1024;

  mRenderStartTime = System.currentTimeMillis();
  mRenderStrategy = flag;

  WXSDKManager.getInstance().setCrashInfo(WXEnvironment.WEEX_CURRENT_KEY,pageName);

  WXSDKManager.getInstance().createInstance(this, template, renderOptions, jsonInitData);
  mRendered = true;

  if (TextUtils.isEmpty(mBundleUrl)) {
    mBundleUrl = pageName;
  }
}
 
示例15
private void renderByUrlInternal(String pageName,
                                 final String url,
                                 Map<String, Object> options,
                                 final String jsonInitData,
                                 final WXRenderStrategy flag) {

  ensureRenderArchor();
  pageName = wrapPageName(pageName, url);
  mBundleUrl = url;
  if(WXSDKManager.getInstance().getValidateProcessor()!=null) {
    mNeedValidate = WXSDKManager.getInstance().getValidateProcessor().needValidate(mBundleUrl);
  }

  Map<String, Object> renderOptions = options;
  if (renderOptions == null) {
    renderOptions = new HashMap<>();
  }
  if (!renderOptions.containsKey(BUNDLE_URL)) {
    renderOptions.put(BUNDLE_URL, url);
  }

  Uri uri = Uri.parse(url);
  if (uri != null && TextUtils.equals(uri.getScheme(), "file")) {
    render(pageName, WXFileUtils.loadFileOrAsset(assembleFilePath(uri), mContext), renderOptions, jsonInitData, flag);
    return;
  }

  IWXHttpAdapter adapter = WXSDKManager.getInstance().getIWXHttpAdapter();

  WXRequest wxRequest = new WXRequest();
  wxRequest.url = rewriteUri(Uri.parse(url),URIAdapter.BUNDLE).toString();
  if (wxRequest.paramMap == null) {
    wxRequest.paramMap = new HashMap<String, String>();
  }
  wxRequest.paramMap.put(KEY_USER_AGENT, WXHttpUtil.assembleUserAgent(mContext,WXEnvironment.getConfig()));
  WXHttpListener httpListener =
      new WXHttpListener(pageName, renderOptions, jsonInitData, flag, System.currentTimeMillis());
  httpListener.setSDKInstance(this);
  adapter.sendRequest(wxRequest, (IWXHttpAdapter.OnHttpListener) httpListener);
}
 
示例16
private WXHttpListener(String pageName, Map<String, Object> options, String jsonInitData, WXRenderStrategy flag, long startRequestTime) {
  this.pageName = pageName;
  this.options = options;
  this.jsonInitData = jsonInitData;
  this.flag = flag;
  this.startRequestTime = startRequestTime;
}
 
示例17
@Test
public void testRewrite() throws Exception {

  final String host = "http://127.0.0.1";
  final String base = host + "/test/123/";
  final String bundleWithSlash = base + "?arg=value";
  final String bundle = base + "bundle.js?arg=value";


  instance.renderByUrl("", bundle, null, null, 0, 0, WXRenderStrategy.APPEND_ONCE);
  testRelative(host, base, bundle);
  instance.renderByUrl("", bundleWithSlash, null, null, 0, 0, WXRenderStrategy.APPEND_ONCE);
  testRelative(host, base, bundleWithSlash);
}
 
示例18
protected void renderPageByURL(String url, String jsonInitData) {
  CommonUtils.throwIfNull(mContainer, new RuntimeException("Can't render page, container is null"));
  Map<String, Object> options = new HashMap<>();
  options.put(WXSDKInstance.BUNDLE_URL, url);
  mInstance.renderByUrl(
      getPageName(),
      url,
      options,
      jsonInitData,
      CommonUtils.getDisplayWidth(this),
      CommonUtils.getDisplayHeight(this),
      WXRenderStrategy.APPEND_ASYNC);
}
 
示例19
/**
 * weex render finish
 * @see  com.taobao.weex.dom.WXDomStatement#createFinish()
 */
void createFinish(int width, int height) {
  if (mWXSDKInstance.getRenderStrategy() == WXRenderStrategy.APPEND_ONCE) {
    mWXSDKInstance.onCreateFinish();
  }
  mWXSDKInstance.onRenderSuccess(width, height);
}
 
示例20
private WXSDKInstance createInstance() {
  WXSDKInstance sdkInstance = getInstance().createNestedInstance(this);
  getInstance().addOnInstanceVisibleListener(this);
  sdkInstance.registerRenderListener(mListener);

  String url=src;
  if(mListener != null && mListener.mEventListener != null){
    url=mListener.mEventListener.transformUrl(src);
    if(!mListener.mEventListener.onPreCreate(this,src)){
      //cancel render
      return null;
    }
  }

  if(TextUtils.isEmpty(url)){
    mListener.mEventListener.onException(this,WXRenderErrorCode.WX_USER_INTERCEPT_ERROR,"degradeToH5");
    return sdkInstance;
  }

  ViewGroup.LayoutParams layoutParams = getHostView().getLayoutParams();
  sdkInstance.renderByUrl(WXPerformance.DEFAULT,
                          url,
                          null, null, layoutParams.width,
                          layoutParams.height,
                          WXRenderStrategy.APPEND_ASYNC);
  return sdkInstance;
}
 
示例21
private void renderInternal(String pageName,
                            String template,
                            Map<String, Object> options,
                            String jsonInitData,
                            WXRenderStrategy flag){
  if (mRendered || TextUtils.isEmpty(template)) {
    return;
  }

  ensureRenderArchor();

  Map<String, Object> renderOptions = options;
  if (renderOptions == null) {
    renderOptions = new HashMap<>();
  }

  if (WXEnvironment.sDynamicMode && !TextUtils.isEmpty(WXEnvironment.sDynamicUrl) && renderOptions.get("dynamicMode") == null) {
    renderOptions.put("dynamicMode", "true");
    renderByUrl(pageName, WXEnvironment.sDynamicUrl, renderOptions, jsonInitData, flag);
    return;
  }

  mWXPerformance.pageName = pageName;
  mWXPerformance.JSTemplateSize = template.length() / 1024;

  mRenderStartTime = System.currentTimeMillis();
  mRenderStrategy = flag;

  WXSDKManager.getInstance().createInstance(this, template, renderOptions, jsonInitData);
  mRendered = true;

  if (TextUtils.isEmpty(mBundleUrl)) {
    mBundleUrl = pageName;
  }
}
 
示例22
private void renderByUrlInternal(String pageName,
                                 final String url,
                                 Map<String, Object> options,
                                 final String jsonInitData,
                                 final WXRenderStrategy flag) {

  ensureRenderArchor();
  pageName = wrapPageName(pageName, url);
  mBundleUrl = url;

  Map<String, Object> renderOptions = options;
  if (renderOptions == null) {
    renderOptions = new HashMap<>();
  }
  if (!renderOptions.containsKey(BUNDLE_URL)) {
    renderOptions.put(BUNDLE_URL, url);
  }

  Uri uri = Uri.parse(url);
  if (uri != null && TextUtils.equals(uri.getScheme(), "file")) {
    render(pageName, WXFileUtils.loadAsset(assembleFilePath(uri), mContext), renderOptions, jsonInitData, flag);
    return;
  }

  IWXHttpAdapter adapter = WXSDKManager.getInstance().getIWXHttpAdapter();

  WXRequest wxRequest = new WXRequest();
  wxRequest.url = rewriteUri(Uri.parse(url),URIAdapter.BUNDLE).toString();
  if (wxRequest.paramMap == null) {
    wxRequest.paramMap = new HashMap<String, String>();
  }
  wxRequest.paramMap.put(KEY_USER_AGENT, WXHttpUtil.assembleUserAgent(mContext,WXEnvironment.getConfig()));
  adapter.sendRequest(wxRequest, new WXHttpListener(pageName, renderOptions, jsonInitData, flag, System.currentTimeMillis()));
}
 
示例23
private WXHttpListener(String pageName, Map<String, Object> options, String jsonInitData, WXRenderStrategy flag, long startRequestTime) {
  this.pageName = pageName;
  this.options = options;
  this.jsonInitData = jsonInitData;
  this.flag = flag;
  this.startRequestTime = startRequestTime;
}
 
示例24
@Test
public void testRewrite() throws Exception {

  final String host = "http://127.0.0.1";
  final String base = host + "/test/123/";
  final String bundleWithSlash = base + "?arg=value";
  final String bundle = base + "bundle.js?arg=value";


  instance.renderByUrl("", bundle, null, null, 0, 0, WXRenderStrategy.APPEND_ONCE);
  testRelative(host, base);
  instance.renderByUrl("", bundleWithSlash, null, null, 0, 0, WXRenderStrategy.APPEND_ONCE);
  testRelative(host, base);
}
 
示例25
protected void renderPage(String template,String source,String jsonInitData){
  AssertUtil.throwIfNull(mContainer,new RuntimeException("Can't render page, container is null"));
  Map<String, Object> options = new HashMap<>();
  options.put(WXSDKInstance.BUNDLE_URL, source);
  mInstance.render(
    source,
    template,
    options,
    jsonInitData,
    ScreenUtil.getDisplayWidth(this),
    ScreenUtil.getDisplayHeight(this),
    WXRenderStrategy.APPEND_ASYNC);
}
 
示例26
protected void renderPageByURL(String url,String jsonInitData){
  AssertUtil.throwIfNull(mContainer,new RuntimeException("Can't render page, container is null"));
  Map<String, Object> options = new HashMap<>();
  options.put(WXSDKInstance.BUNDLE_URL, url);
  mInstance.renderByUrl(
    getPageName(),
    url,
    options,
    jsonInitData,
    ScreenUtil.getDisplayWidth(this),
    ScreenUtil.getDisplayHeight(this),
    WXRenderStrategy.APPEND_ASYNC);
}
 
示例27
protected void renderPageByURL(String url, String jsonInitData) {
  AssertUtil.throwIfNull(mContainer, new RuntimeException("Can't render page, container is null"));
  Map<String, Object> options = new HashMap<>();
  options.put(WXSDKInstance.BUNDLE_URL, url);
  mInstance.renderByUrl(
      getPageName(),
      url,
      options,
      jsonInitData,
      ScreenUtil.getDisplayWidth(this),
      ScreenUtil.getDisplayHeight(this),
      WXRenderStrategy.APPEND_ASYNC);
}
 
示例28
protected void renderPage(String template,String source,String jsonInitData){
  AssertUtil.throwIfNull(mContainer,new RuntimeException("Can't render page, container is null"));
  Map<String, Object> options = new HashMap<>();
  options.put(WXSDKInstance.BUNDLE_URL, source);
  mInstance.render(
    getPageName(),
    template,
    options,
    jsonInitData,
    ScreenUtil.getDisplayWidth(this),
    ScreenUtil.getDisplayHeight(this),
    WXRenderStrategy.APPEND_ASYNC);
}
 
示例29
protected void renderPageByURL(String url,String jsonInitData){
  AssertUtil.throwIfNull(mContainer,new RuntimeException("Can't render page, container is null"));
  Map<String, Object> options = new HashMap<>();
  options.put(WXSDKInstance.BUNDLE_URL, url);
  mInstance.renderByUrl(
    getPageName(),
    url,
    options,
    jsonInitData,
    ScreenUtil.getDisplayWidth(this),
    ScreenUtil.getDisplayHeight(this),
    WXRenderStrategy.APPEND_ASYNC);
}
 
示例30
/**
 * weex render finish
 * @see  com.taobao.weex.dom.WXDomStatement#createFinish()
 */
void createFinish(int width, int height) {
  if (mWXSDKInstance.getRenderStrategy() == WXRenderStrategy.APPEND_ONCE) {
    mWXSDKInstance.onViewCreated(mGodComponent);
  }
  mWXSDKInstance.onRenderSuccess(width, height);
}