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

Commit

Permalink
fix ios call native component method before the plugin register (#2387)
Browse files Browse the repository at this point in the history
  • Loading branch information
pengtaopt authored and jianhan-he committed Apr 30, 2019
1 parent 507dc0b commit 14a6760
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace WeexCore
void CallNativeComponent(const char* pageId, const char* ref, const char *method,
const char *arguments, int argumentsLength, const char *options, int optionsLength) override;
std::unique_ptr<ValueWithType> RegisterPluginModule(const char *name, const char *class_name, const char *version) override;

std::unique_ptr<ValueWithType> RegisterPluginComponent(const char *name, const char *class_name, const char *version) override;
void SetTimeout(const char* callbackID, const char* time) override ;

void NativeLog(const char* str_array) override ;
Expand Down
47 changes: 42 additions & 5 deletions ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#import "WXComponentMethod.h"
#import "WXExceptionUtils.h"
#import "WXModuleFactory.h"

#import "WXComponentFactory.h"
#include "base/core_constants.h"
#include "base/time_utils.h"
#include "core/manager/weex_core_manager.h"
Expand Down Expand Up @@ -178,6 +178,47 @@ static void MergeBorderWidthValues(NSMutableDictionary* dict,

return result;
}
std::unique_ptr<ValueWithType> IOSSide::RegisterPluginComponent(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;
}
NSDictionary *properties = @{ @"append" : @"tree" };
NSString *name = [NSString stringWithUTF8String:pcstr_name];
[WXComponentFactory registerComponent:name withClass:clazz withPros:properties];
NSMutableDictionary *info = [WXComponentFactory componentMethodMapsWithName:name];
if (![info isKindOfClass:[NSDictionary class]]) {
break;
}
NSArray *methods = info[@"methods"];
if (![methods isKindOfClass:[NSArray class]] || !methods.count) {
break;
}
info[@"type"] = name;
NSMutableDictionary *props = [properties mutableCopy];
[props addEntriesFromDictionary:info];
NSString *componentsInfo = [WXUtility JSONString:@[props]];
if (componentsInfo.length > 0) {
returnValue->type = ParamsType::BYTEARRAYSTRING;
const char *pcstr_utf8 = [componentsInfo UTF8String];
returnValue->value.byteArray = generator_bytes_array(pcstr_utf8, componentsInfo.length);
}

} while (0);

return std::unique_ptr<ValueWithType>(returnValue);
}

std::unique_ptr<ValueWithType> IOSSide::RegisterPluginModule(const char *pcstr_name, const char *pcstr_class_name, const char *pcstr_version) {
ValueWithType *returnValue = new ValueWithType();
Expand All @@ -196,10 +237,6 @@ static void MergeBorderWidthValues(NSMutableDictionary* dict,
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;
Expand Down
6 changes: 6 additions & 0 deletions weex_core/Source/core/bridge/eagle_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ namespace WeexCore {
->platform_side()
->RegisterPluginModule(name.c_str(), class_name.c_str(), version.c_str());
}
std::unique_ptr<ValueWithType> EagleBridge::WeexCoreHandler::RegisterPluginComponent(const std::string &name, const std::string &class_name, const std::string &version) {
return WeexCoreManager::Instance()
->getPlatformBridge()
->platform_side()
->RegisterPluginComponent(name.c_str(), class_name.c_str(), version.c_str());
}

void EagleBridge::WeexCoreHandler::PostTaskOnComponentThread(const weex::base::Closure& closure) {
WeexCoreManager::Instance()->getPlatformBridge()->platform_side()->PostTaskOnComponentThread(closure);
Expand Down
2 changes: 1 addition & 1 deletion weex_core/Source/core/bridge/eagle_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace WeexCore {
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);

std::unique_ptr<ValueWithType> RegisterPluginComponent(const std::string &name, const std::string &class_name, const std::string &version);
void PostTaskOnComponentThread(const weex::base::Closure& closure);
#endif
};
Expand Down
1 change: 1 addition & 0 deletions weex_core/Source/core/bridge/platform_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class PlatformBridge {
int options_length) = 0;
#if OS_IOS
virtual std::unique_ptr<ValueWithType> RegisterPluginModule(const char *name, const char *class_name, const char *version) = 0;
virtual std::unique_ptr<ValueWithType> RegisterPluginComponent(const char *name, const char *class_name, const char *version) = 0;
virtual void PostTaskOnComponentThread(const weex::base::Closure closure) = 0;
#endif
virtual void SetTimeout(const char* callback_id, const char* time) = 0;
Expand Down

0 comments on commit 14a6760

Please sign in to comment.