Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[Android] Add weex-rax-api.js for eagle (#2446)
Browse files Browse the repository at this point in the history
* * [Android] Add weex-rax-api.js for eagle

* Pass options to c++

* Revert bundle type judgement.

* Revert "Pass options to c++"

This reverts commit 406d1f0

* [Android] Change the json structure weex.config.env.

# Before
## Normal Page

    {
        "bundleType": "Vue",
        "bundleUrl": "xxxx",
        "env": {
            "deviceHeight": "1200",
            "deviceWidth": "720",
            "enableBackupThread": "true",
            "enableBackupThreadCache": "true",
            .....
        },
        "render_strategy": "DATA_RENDER"
    }
## Eagle Page
As bundleType is `Others`, `env.options` will not be merged into `env`.

    {
        "bundleType": "Others",
        "bundleUrl": "xxxx",
        "env": {
            "deviceHeight": "1200",
            "deviceWidth": "720",
            "options": {
                "enableBackupThread": "true",
                "enableBackupThreadCache": "true",
                .....
            }
            ....
        },
        "render_strategy": "DATA_RENDER"
    }

# After
1. No matter what bundleType, always merge `env.options` into `env`
1. For compatibility reason, remain the `env.options` at its original place.

    {
        "bundleType": "Other",
        "bundleUrl": "xxxx",
        "env": {
            "deviceHeight": "1200",
            "deviceWidth": "720",
            "enableBackupThread": "true",
            "enableBackupThreadCache": "true",
            "options": {
                "enableBackupThread": "true",
                "enableBackupThreadCache": "true",
                .....
            }
            .....
        },
        "render_strategy": "DATA_RENDER"
    }
  • Loading branch information
YorkShen authored and jianhan-he committed May 16, 2019
1 parent eef7654 commit d4fdf75
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
Expand Down Expand Up @@ -108,7 +107,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -1581,7 +1579,7 @@ private void invokeCreateInstance(@NonNull WXSDKInstance instance, Script templa
data == null ? "{}" : data);

WXJSObject apiObj;
if (type == BundType.Rax) {
if (type == BundType.Rax || instance.getRenderStrategy() == WXRenderStrategy.DATA_RENDER) {
if (mRaxApi == null) {
IWXJsFileLoaderAdapter iwxJsFileLoaderAdapter = WXSDKEngine.getIWXJsFileLoaderAdapter();
if(iwxJsFileLoaderAdapter != null) {
Expand Down Expand Up @@ -1660,31 +1658,22 @@ private void invokeCreateInstance(@NonNull WXSDKInstance instance, Script templa
}

public WXJSObject optionObjConvert(boolean useSandBox, BundType type, WXJSObject opt) {
if (!useSandBox || type == BundType.Others) {
if (!useSandBox) {
return opt;
}
try {
String data = opt.data.toString();
JSONObject obj = JSON.parseObject(data);
if (obj.getJSONObject("env") != null) {
JSONObject optEnv = obj.getJSONObject("env");
// obj.replace()
if (optEnv != null) {
JSONObject opts = optEnv.getJSONObject("options");
if (opts!= null) {
optEnv.remove("options");
Set<String> set = opts.keySet();
for(Iterator it = set.iterator(); it.hasNext();) {
String key = it.next().toString();
optEnv.put(key, opts.getString(key));
}
JSONObject optEnv;
if ((optEnv = obj.getJSONObject("env")) != null) {
JSONObject opts = optEnv.getJSONObject("options");
if (opts != null) {
for (String s : opts.keySet()) {
optEnv.put(s, opts.getString(s));
}
}
obj.remove("env");
obj.put("env", optEnv);
}
WXJSObject optionsObj = new WXJSObject(WXJSObject.JSON, obj.toString());
return optionsObj;
return new WXJSObject(WXJSObject.JSON, obj.toString());
} catch (Throwable e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

#include "cstring"
#include "core/bridge/platform/core_side_in_platform.h"
#include "base/string_util.h"
#include "base/log_defines.h"
Expand Down Expand Up @@ -491,7 +492,8 @@ int CoreSideInPlatform::CreateInstance(const char *instanceId, const char *func,
->script_side()
->CreateInstance(instanceId.c_str(), func.c_str(), result,
opts_json.dump().c_str(), initData.c_str(),
extendsApi.c_str(),params);
strcmp("Rax", bundleType) ? "\0" : extendsApi.c_str(),
params);
};
if (strcmp(render_strategy, "DATA_RENDER") == 0) {
auto handler = EagleBridge::GetInstance()->data_render_handler();
Expand Down

0 comments on commit d4fdf75

Please sign in to comment.