Skip to content

Commit

Permalink
* [android] fix register order
Browse files Browse the repository at this point in the history
  • Loading branch information
sospartan committed Jun 23, 2016
1 parent 2d5284b commit 5c8a264
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 16 deletions.
3 changes: 2 additions & 1 deletion android/sdk/src/main/java/com/taobao/weex/WXSDKEngine.java
Expand Up @@ -241,12 +241,13 @@ public void run() {
return;
}
sm.initScriptsFramework(null);
register();

WXEnvironment.sSDKInitExecuteTime = System.currentTimeMillis() - start;
WXLogUtils.renderPerformanceLog("SDKInitInvokeTime", WXEnvironment.sSDKInitInvokeTime);
WXLogUtils.renderPerformanceLog("SDKInitExecuteTime", WXEnvironment.sSDKInitExecuteTime);
}
});
register();
}

@Deprecated
Expand Down
Expand Up @@ -240,26 +240,37 @@ public class WXModuleManager {
/**
* Register module to JavaScript and Android
*/
public static boolean registerModule(String moduleName, ModuleFactory factory, boolean global) throws WXException {
public static boolean registerModule(final String moduleName, final ModuleFactory factory, final boolean global) throws WXException {
if (moduleName == null || factory == null) {
return false;
}

if (sModuleFactoryMap.containsKey(moduleName)) {
WXLogUtils.w("WXComponentRegistry Duplicate the Module name: " + moduleName);
}
WXBridgeManager.getInstance().getJSHandler().post(new Runnable() {
@Override
public void run() {
if (sModuleFactoryMap.containsKey(moduleName)) {
WXLogUtils.w("WXComponentRegistry Duplicate the Module name: " + moduleName);
}

if (global) {
try {
WXModule wxModule = factory.buildInstance();
sGlobalModuleMap.put(moduleName, wxModule);
} catch (Exception e) {
WXLogUtils.e(moduleName + " class must have a default constructor without params. " + WXLogUtils.getStackTrace(e));
}
}

if (global) {
try {
WXModule wxModule = factory.buildInstance();
sGlobalModuleMap.put(moduleName, wxModule);
} catch (Exception e) {
WXLogUtils.e(moduleName + " class must have a default constructor without params. " + WXLogUtils.getStackTrace(e));
return false;
try {
registerNativeModule(moduleName, factory);
} catch (WXException e) {
e.printStackTrace();
}
registerJSModule(moduleName, factory);
}
}
});
return true;

return registerNativeModule(moduleName, factory) && registerJSModule(moduleName, factory);
}

static boolean registerNativeModule(String moduleName, ModuleFactory factory) throws WXException {
Expand Down
Expand Up @@ -208,6 +208,7 @@

import com.taobao.weex.WXEnvironment;
import com.taobao.weex.WXSDKManager;
import com.taobao.weex.bridge.WXBridgeManager;
import com.taobao.weex.common.WXException;
import com.taobao.weex.ui.component.WXComponent;
import com.taobao.weex.utils.WXLogUtils;
Expand All @@ -233,8 +234,23 @@ public static boolean registerComponent(String type, Class<? extends WXComponent
if (appendTree) {
componentInfo.put("append", "tree");
}
registerInternal(type,clazz,componentInfo);
return true;
}

return registerNativeComponent(type, clazz) && registerJSComponent(componentInfo);
private static void registerInternal(final String type,final Class<? extends WXComponent> clazz, final Map<String, String> componentInfo){
WXBridgeManager.getInstance().getJSHandler().post(new Runnable() {
@Override
public void run() {
try {
registerNativeComponent(type, clazz);
registerJSComponent(componentInfo);
} catch (WXException e) {
e.printStackTrace();
}

}
});
}

private static boolean registerNativeComponent(String type, Class<? extends WXComponent> clazz) throws WXException {
Expand Down Expand Up @@ -273,7 +289,12 @@ public static boolean registerComponent(Map<String, String> componentInfo, Class
}

String type = componentInfo.get("type");
return registerNativeComponent(type, clazz) && registerJSComponent(componentInfo);
if(type == null){
return false;
}else{
registerInternal(type,clazz,componentInfo);
return true;
}
}

public static ComponentHolder getComponent(String type) {
Expand Down

0 comments on commit 5c8a264

Please sign in to comment.