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

Commit

Permalink
[eagle] fix ios module reg problem for eagle
Browse files Browse the repository at this point in the history
  • Loading branch information
hpop1994 committed Apr 15, 2019
1 parent be06e3a commit 38801dc
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 6 deletions.
3 changes: 3 additions & 0 deletions ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ namespace WeexCore

void CallNativeComponent(const char* pageId, const char* ref, const char *method,
const char *arguments, int argumentsLength, const char *options, int optionsLength) override;
#if OS_IOS
std::unique_ptr<ValueWithType> RegisterPluginModule(const char *name, const char *class_name, const char *version) override;
#endif

void SetTimeout(const char* callbackID, const char* time) override ;

Expand Down
43 changes: 43 additions & 0 deletions ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#import "WXAppMonitorProtocol.h"
#import "WXComponentMethod.h"
#import "WXExceptionUtils.h"
#import "WXModuleFactory.h"

#include "base/core_constants.h"
#include "base/time_utils.h"
Expand Down Expand Up @@ -177,7 +178,49 @@ static void MergeBorderWidthValues(NSMutableDictionary* dict,

return result;
}

#if OS_IOS
std::unique_ptr<ValueWithType> IOSSide::RegisterPluginModule(const char *pcstr_name, const char *pcstr_class_name, const char *pcstr_version) {
ValueWithType *returnValue = new ValueWithType();
memset(returnValue, 0, sizeof(ValueWithType));
returnValue->type = ParamsType::VOID;
do {
if (!pcstr_class_name) {
break;
}
NSString *className = [NSString stringWithUTF8String:pcstr_class_name];
Class clazz = NSClassFromString(className);
if (!clazz) {
break;
}
if (!pcstr_name) {
break;
}
NSString *name = [NSString stringWithUTF8String:pcstr_name];
NSString *version = @"0";
if (pcstr_version) {
version = [NSString stringWithUTF8String:pcstr_version];
}
NSString *moduleName = [WXModuleFactory registerModule:name withClass:clazz];
if (!moduleName.length) {
break;
}
NSDictionary *moduleInfo = [WXModuleFactory moduleMethodMapsWithName:moduleName];
if (!moduleInfo || ![moduleInfo isKindOfClass:[NSDictionary class]]) {
break;
}
NSString *setting = [WXUtility JSONString:moduleInfo];
if (setting.length > 0) {
returnValue->type = ParamsType::BYTEARRAYSTRING;
const char *pcstr_utf8 = [setting UTF8String];
returnValue->value.byteArray = generator_bytes_array(pcstr_utf8, setting.length);
}

} while (0);

return std::unique_ptr<ValueWithType>(returnValue);
}
#endif
std::unique_ptr<ValueWithType> IOSSide::CallNativeModule(const char *page_id, const char *module, const char *method, const char *args, int args_length, const char *options, int options_length)
{
ValueWithType *returnValue = new ValueWithType();
Expand Down
3 changes: 2 additions & 1 deletion ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,9 @@ - (void)callBack:(NSString *)instanceId funcId:(NSString *)funcId params:(id)par
if (instance.wlasmRender) {
id<WXDataRenderHandler> dataRenderHandler = [WXHandlerFactory handlerForProtocol:@protocol(WXDataRenderHandler)];
if (dataRenderHandler) {
id strongArgs = params ? [params copy]:@"\"{}\"";
WXPerformBlockOnComponentThread(^{
[dataRenderHandler invokeCallBack:instanceId function:funcId args:params ? [params copy]:@"\"{}\"" keepAlive:keepAlive];
[dataRenderHandler invokeCallBack:instanceId function:funcId args:strongArgs keepAlive:keepAlive];
});
}
else {
Expand Down
9 changes: 8 additions & 1 deletion weex_core/Source/core/bridge/eagle_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,14 @@ namespace WeexCore {
->platform_side()
->CallNativeModule(page_id, module, method, arguments, arguments_length, options, options_length);
}

#if OS_IOS
std::unique_ptr<ValueWithType> EagleBridge::WeexCoreHandler::RegisterPluginModule(const std::string &name, const std::string &class_name, const std::string &version) {
return WeexCoreManager::Instance()
->getPlatformBridge()
->platform_side()
->RegisterPluginModule(name.c_str(), class_name.c_str(), version.c_str());
}
#endif
void EagleBridge::WeexCoreHandler::CallNativeComponent(const char* page_id, const char* module, const char* method,const char* arguments, int arguments_length, const char* options, int options_length) {
WeexCoreManager::Instance()
->getPlatformBridge()
Expand Down
3 changes: 3 additions & 0 deletions weex_core/Source/core/bridge/eagle_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ namespace WeexCore {
const char *func,
std::vector<VALUE_WITH_TYPE *> &params);
void PostTaskToMsgLoop(const weex::base::Closure& closure);
#if OS_IOS
std::unique_ptr<ValueWithType> RegisterPluginModule(const std::string &name, const std::string &class_name, const std::string &version);
#endif
};

class DataRenderHandler {
Expand Down
21 changes: 17 additions & 4 deletions weex_core/Source/core/bridge/platform/core_side_in_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ int CoreSideInPlatform::RefreshInstance(

std::string init_data = weex::base::to_utf8(params[1]->value.string->content,
params[1]->value.string->length);

if (EagleBridge::GetInstance()->data_render_handler()->RefreshPage(instanceId, init_data)) {
auto handler = EagleBridge::GetInstance()->data_render_handler();
if (handler && handler->RefreshPage(instanceId, init_data)) {
return true;
}
return ExecJS(instanceId, nameSpace, func, params);
Expand Down Expand Up @@ -443,7 +443,13 @@ int CoreSideInPlatform::CreateInstance(const char *instanceId, const char *func,
extendsApi.c_str(),params);
};
if (strcmp(render_strategy, "DATA_RENDER") == 0) {
EagleBridge::GetInstance()->data_render_handler()->CreatePage(script, instanceId, render_strategy, initData, exec_js);
auto handler = EagleBridge::GetInstance()->data_render_handler();
if(handler){
handler->CreatePage(script, instanceId, render_strategy, initData, exec_js);
}
else{
LOGE("DATA_RENDER mode should not be used if there is no data_render_handler");
}

return true;
} else if (strcmp(render_strategy, "DATA_RENDER_BINARY") == 0) {
Expand Down Expand Up @@ -475,7 +481,14 @@ int CoreSideInPlatform::CreateInstance(const char *instanceId, const char *func,
};
option = json11::Json(new_option).dump();
}
EagleBridge::GetInstance()->data_render_handler()->CreatePage(script, static_cast<size_t>(script_length), instanceId, option, env_str, initData, exec_js);

auto handler = EagleBridge::GetInstance()->data_render_handler();
if(handler){
handler->CreatePage(script, static_cast<size_t>(script_length), instanceId, option, env_str, initData, exec_js);
}
else{
LOGE("DATA_RENDER_BINARY mode should not be used if there is no data_render_handler");
}
return true;
}
}
Expand Down
3 changes: 3 additions & 0 deletions weex_core/Source/core/bridge/platform_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ class PlatformBridge {
const char* method, const char* arguments,
int arguments_length, const char* options,
int options_length) = 0;
#if OS_IOS
virtual std::unique_ptr<ValueWithType> RegisterPluginModule(const char *name, const char *class_name, const char *version) = 0;
#endif
virtual void SetTimeout(const char* callback_id, const char* time) = 0;
virtual void NativeLog(const char* str_array) = 0;
virtual int UpdateFinish(const char* page_id, const char* task, int taskLen,
Expand Down

0 comments on commit 38801dc

Please sign in to comment.