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

Commit 38801dc

Browse files
committed
[eagle] fix ios module reg problem for eagle
1 parent be06e3a commit 38801dc

File tree

7 files changed

+79
-6
lines changed

7 files changed

+79
-6
lines changed

ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ namespace WeexCore
5656

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

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

ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#import "WXAppMonitorProtocol.h"
3434
#import "WXComponentMethod.h"
3535
#import "WXExceptionUtils.h"
36+
#import "WXModuleFactory.h"
3637

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

178179
return result;
179180
}
181+
182+
#if OS_IOS
183+
std::unique_ptr<ValueWithType> IOSSide::RegisterPluginModule(const char *pcstr_name, const char *pcstr_class_name, const char *pcstr_version) {
184+
ValueWithType *returnValue = new ValueWithType();
185+
memset(returnValue, 0, sizeof(ValueWithType));
186+
returnValue->type = ParamsType::VOID;
187+
do {
188+
if (!pcstr_class_name) {
189+
break;
190+
}
191+
NSString *className = [NSString stringWithUTF8String:pcstr_class_name];
192+
Class clazz = NSClassFromString(className);
193+
if (!clazz) {
194+
break;
195+
}
196+
if (!pcstr_name) {
197+
break;
198+
}
199+
NSString *name = [NSString stringWithUTF8String:pcstr_name];
200+
NSString *version = @"0";
201+
if (pcstr_version) {
202+
version = [NSString stringWithUTF8String:pcstr_version];
203+
}
204+
NSString *moduleName = [WXModuleFactory registerModule:name withClass:clazz];
205+
if (!moduleName.length) {
206+
break;
207+
}
208+
NSDictionary *moduleInfo = [WXModuleFactory moduleMethodMapsWithName:moduleName];
209+
if (!moduleInfo || ![moduleInfo isKindOfClass:[NSDictionary class]]) {
210+
break;
211+
}
212+
NSString *setting = [WXUtility JSONString:moduleInfo];
213+
if (setting.length > 0) {
214+
returnValue->type = ParamsType::BYTEARRAYSTRING;
215+
const char *pcstr_utf8 = [setting UTF8String];
216+
returnValue->value.byteArray = generator_bytes_array(pcstr_utf8, setting.length);
217+
}
180218

219+
} while (0);
220+
221+
return std::unique_ptr<ValueWithType>(returnValue);
222+
}
223+
#endif
181224
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)
182225
{
183226
ValueWithType *returnValue = new ValueWithType();

ios/sdk/WeexSDK/Sources/Manager/WXBridgeManager.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,9 @@ - (void)callBack:(NSString *)instanceId funcId:(NSString *)funcId params:(id)par
491491
if (instance.wlasmRender) {
492492
id<WXDataRenderHandler> dataRenderHandler = [WXHandlerFactory handlerForProtocol:@protocol(WXDataRenderHandler)];
493493
if (dataRenderHandler) {
494+
id strongArgs = params ? [params copy]:@"\"{}\"";
494495
WXPerformBlockOnComponentThread(^{
495-
[dataRenderHandler invokeCallBack:instanceId function:funcId args:params ? [params copy]:@"\"{}\"" keepAlive:keepAlive];
496+
[dataRenderHandler invokeCallBack:instanceId function:funcId args:strongArgs keepAlive:keepAlive];
496497
});
497498
}
498499
else {

weex_core/Source/core/bridge/eagle_bridge.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,14 @@ namespace WeexCore {
151151
->platform_side()
152152
->CallNativeModule(page_id, module, method, arguments, arguments_length, options, options_length);
153153
}
154-
154+
#if OS_IOS
155+
std::unique_ptr<ValueWithType> EagleBridge::WeexCoreHandler::RegisterPluginModule(const std::string &name, const std::string &class_name, const std::string &version) {
156+
return WeexCoreManager::Instance()
157+
->getPlatformBridge()
158+
->platform_side()
159+
->RegisterPluginModule(name.c_str(), class_name.c_str(), version.c_str());
160+
}
161+
#endif
155162
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) {
156163
WeexCoreManager::Instance()
157164
->getPlatformBridge()

weex_core/Source/core/bridge/eagle_bridge.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ namespace WeexCore {
105105
const char *func,
106106
std::vector<VALUE_WITH_TYPE *> &params);
107107
void PostTaskToMsgLoop(const weex::base::Closure& closure);
108+
#if OS_IOS
109+
std::unique_ptr<ValueWithType> RegisterPluginModule(const std::string &name, const std::string &class_name, const std::string &version);
110+
#endif
108111
};
109112

110113
class DataRenderHandler {

weex_core/Source/core/bridge/platform/core_side_in_platform.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ int CoreSideInPlatform::RefreshInstance(
320320

321321
std::string init_data = weex::base::to_utf8(params[1]->value.string->content,
322322
params[1]->value.string->length);
323-
324-
if (EagleBridge::GetInstance()->data_render_handler()->RefreshPage(instanceId, init_data)) {
323+
auto handler = EagleBridge::GetInstance()->data_render_handler();
324+
if (handler && handler->RefreshPage(instanceId, init_data)) {
325325
return true;
326326
}
327327
return ExecJS(instanceId, nameSpace, func, params);
@@ -443,7 +443,13 @@ int CoreSideInPlatform::CreateInstance(const char *instanceId, const char *func,
443443
extendsApi.c_str(),params);
444444
};
445445
if (strcmp(render_strategy, "DATA_RENDER") == 0) {
446-
EagleBridge::GetInstance()->data_render_handler()->CreatePage(script, instanceId, render_strategy, initData, exec_js);
446+
auto handler = EagleBridge::GetInstance()->data_render_handler();
447+
if(handler){
448+
handler->CreatePage(script, instanceId, render_strategy, initData, exec_js);
449+
}
450+
else{
451+
LOGE("DATA_RENDER mode should not be used if there is no data_render_handler");
452+
}
447453

448454
return true;
449455
} else if (strcmp(render_strategy, "DATA_RENDER_BINARY") == 0) {
@@ -475,7 +481,14 @@ int CoreSideInPlatform::CreateInstance(const char *instanceId, const char *func,
475481
};
476482
option = json11::Json(new_option).dump();
477483
}
478-
EagleBridge::GetInstance()->data_render_handler()->CreatePage(script, static_cast<size_t>(script_length), instanceId, option, env_str, initData, exec_js);
484+
485+
auto handler = EagleBridge::GetInstance()->data_render_handler();
486+
if(handler){
487+
handler->CreatePage(script, static_cast<size_t>(script_length), instanceId, option, env_str, initData, exec_js);
488+
}
489+
else{
490+
LOGE("DATA_RENDER_BINARY mode should not be used if there is no data_render_handler");
491+
}
479492
return true;
480493
}
481494
}

weex_core/Source/core/bridge/platform_bridge.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ class PlatformBridge {
169169
const char* method, const char* arguments,
170170
int arguments_length, const char* options,
171171
int options_length) = 0;
172+
#if OS_IOS
173+
virtual std::unique_ptr<ValueWithType> RegisterPluginModule(const char *name, const char *class_name, const char *version) = 0;
174+
#endif
172175
virtual void SetTimeout(const char* callback_id, const char* time) = 0;
173176
virtual void NativeLog(const char* str_array) = 0;
174177
virtual int UpdateFinish(const char* page_id, const char* task, int taskLen,

0 commit comments

Comments
 (0)