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

[WEEX-628][Android] add jsframework load adapter #1568

Merged
merged 1 commit into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/InitConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.taobao.weex.adapter.IWXHttpAdapter;
import com.taobao.weex.adapter.IWXImgLoaderAdapter;
import com.taobao.weex.adapter.IWXJSExceptionAdapter;
import com.taobao.weex.adapter.IWXJsFileLoaderAdapter;
import com.taobao.weex.adapter.IWXSoLoaderAdapter;
import com.taobao.weex.adapter.IWXUserTrackAdapter;
import com.taobao.weex.adapter.URIAdapter;
Expand All @@ -46,6 +47,7 @@ public class InitConfig {
private String framework;
private ClassLoaderAdapter classLoaderAdapter;
private IApmGenerator apmGenerater;
private IWXJsFileLoaderAdapter jsFileLoaderAdapter;

public IWXHttpAdapter getHttpAdapter() {
return httpAdapter;
Expand Down Expand Up @@ -91,6 +93,10 @@ public IApmGenerator getApmGenerater() {
return apmGenerater;
}

public IWXJsFileLoaderAdapter getJsFileLoaderAdapter() {
return jsFileLoaderAdapter;
}

public InitConfig setClassLoaderAdapter(ClassLoaderAdapter classLoaderAdapter) {
this.classLoaderAdapter = classLoaderAdapter;
return this;
Expand All @@ -116,6 +122,7 @@ public static class Builder{
IWebSocketAdapterFactory webSocketAdapterFactory;
ClassLoaderAdapter classLoaderAdapter;
IApmGenerator apmGenerater;
private IWXJsFileLoaderAdapter jsFileLoaderAdapter;

public Builder(){

Expand Down Expand Up @@ -181,6 +188,11 @@ public Builder setApmGenerater(IApmGenerator apmGenerater){
return this;
}

public Builder setJsFileLoaderAdapter(IWXJsFileLoaderAdapter jsFileLoaderAdapter) {
this.jsFileLoaderAdapter = jsFileLoaderAdapter;
return this;
}

public InitConfig build(){
InitConfig config = new InitConfig();
config.httpAdapter = this.httpAdapter;
Expand All @@ -195,6 +207,7 @@ public InitConfig build(){
config.mJSExceptionAdapter=this.mJSExceptionAdapter;
config.classLoaderAdapter = this.classLoaderAdapter;
config.apmGenerater = this.apmGenerater;
config.jsFileLoaderAdapter = this.jsFileLoaderAdapter;
return config;
}
}
Expand Down
5 changes: 5 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/WXSDKEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.taobao.weex.adapter.IWXHttpAdapter;
import com.taobao.weex.adapter.IWXImgLoaderAdapter;
import com.taobao.weex.adapter.IWXJSExceptionAdapter;
import com.taobao.weex.adapter.IWXJsFileLoaderAdapter;
import com.taobao.weex.adapter.IWXUserTrackAdapter;
import com.taobao.weex.appfram.clipboard.WXClipboardModule;
import com.taobao.weex.appfram.navigator.IActivityNavBarSetter;
Expand Down Expand Up @@ -562,6 +563,10 @@ public static IWXStorageAdapter getIWXStorageAdapter() {
}


public static IWXJsFileLoaderAdapter getIWXJsFileLoaderAdapter() {
return WXSDKManager.getInstance().getIWXJsFileLoaderAdapter();
}

public static IActivityNavBarSetter getActivityNavBarSetter() {
return WXSDKManager.getInstance().getActivityNavBarSetter();
}
Expand Down
7 changes: 7 additions & 0 deletions android/sdk/src/main/java/com/taobao/weex/WXSDKManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.taobao.weex.adapter.IWXHttpAdapter;
import com.taobao.weex.adapter.IWXImgLoaderAdapter;
import com.taobao.weex.adapter.IWXJSExceptionAdapter;
import com.taobao.weex.adapter.IWXJsFileLoaderAdapter;
import com.taobao.weex.adapter.IWXSoLoaderAdapter;
import com.taobao.weex.adapter.IWXUserTrackAdapter;
import com.taobao.weex.adapter.URIAdapter;
Expand Down Expand Up @@ -82,6 +83,7 @@ public class WXSDKManager {
private IWXAccessibilityRoleAdapter mRoleAdapter;
private List<IWXAnalyzer> mWXAnalyzerList;
private IApmGenerator mApmGenerater;
private IWXJsFileLoaderAdapter mWXJsFileLoaderAdapter;

private ICrashInfoReporter mCrashInfo;

Expand Down Expand Up @@ -325,6 +327,10 @@ public IWXImgLoaderAdapter getIWXImgLoaderAdapter() {
return mIWXImgLoaderAdapter;
}

public IWXJsFileLoaderAdapter getIWXJsFileLoaderAdapter() {
return mWXJsFileLoaderAdapter;
}

public IDrawableLoader getDrawableLoader() {
return mDrawableLoader;
}
Expand Down Expand Up @@ -392,6 +398,7 @@ void setInitConfig(InitConfig config){
this.mIWXSoLoaderAdapter = config.getIWXSoLoaderAdapter();
this.mClassLoaderAdapter = config.getClassLoaderAdapter();
this.mApmGenerater = config.getApmGenerater();
this.mWXJsFileLoaderAdapter = config.getJsFileLoaderAdapter();
}

public IWXStorageAdapter getIWXStorageAdapter(){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.taobao.weex.adapter;

public interface IWXJsFileLoaderAdapter {
String loadRaxApi();
String loadJsFramework();
String loadJsFrameworkForSandBox();
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.WXSDKManager;
import com.taobao.weex.adapter.IWXJSExceptionAdapter;
import com.taobao.weex.adapter.IWXJsFileLoaderAdapter;
import com.taobao.weex.adapter.IWXUserTrackAdapter;
import com.taobao.weex.common.*;
import com.taobao.weex.dom.CSSShorthand;
Expand Down Expand Up @@ -1442,7 +1443,14 @@ private void invokeCreateInstance(@NonNull WXSDKInstance instance, Script templa
WXJSObject apiObj;
if (type == BundType.Rax) {
if (mRaxApi == null) {
mRaxApi = WXFileUtils.loadAsset("weex-rax-api.js", WXEnvironment.getApplication());
IWXJsFileLoaderAdapter iwxJsFileLoaderAdapter = WXSDKEngine.getIWXJsFileLoaderAdapter();
if(iwxJsFileLoaderAdapter != null) {
mRaxApi = iwxJsFileLoaderAdapter.loadRaxApi();
}

if(TextUtils.isEmpty(mRaxApi)) {
mRaxApi = WXFileUtils.loadAsset("weex-rax-api.js", WXEnvironment.getApplication());
}
}
apiObj = new WXJSObject(WXJSObject.String,
mRaxApi);
Expand Down Expand Up @@ -1798,10 +1806,25 @@ private void initFramework(String framework) {
// if (WXEnvironment.isApkDebugable()) {
WXLogUtils.d("weex JS framework from assets");
// }

IWXJsFileLoaderAdapter wxJsFileLoaderAdapter = WXSDKEngine.getIWXJsFileLoaderAdapter();

if (!isSandBoxContext) {
framework = WXFileUtils.loadAsset("main.js", WXEnvironment.getApplication());
if(wxJsFileLoaderAdapter != null) {
framework = wxJsFileLoaderAdapter.loadJsFramework();
}

if(TextUtils.isEmpty(framework)) {
framework = WXFileUtils.loadAsset("main.js", WXEnvironment.getApplication());
}
} else {
framework = WXFileUtils.loadAsset("weex-main-jsfm.js", WXEnvironment.getApplication());
if(wxJsFileLoaderAdapter != null) {
framework = wxJsFileLoaderAdapter.loadJsFrameworkForSandBox();
}

if(TextUtils.isEmpty(framework)) {
framework = WXFileUtils.loadAsset("weex-main-jsfm.js", WXEnvironment.getApplication());
}
}
sInitFrameWorkMsg.append("| weex JS framework from assets, isSandBoxContext: ").append(isSandBoxContext);
}
Expand Down