You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ji...@apache.org on 2019/04/30 07:45:42 UTC

[incubator-weex] branch master updated: fix ios call native component method before the plugin register (#2387)

This is an automated email from the ASF dual-hosted git repository.

jianhan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-weex.git


The following commit(s) were added to refs/heads/master by this push:
     new 14a6760  fix ios call native component method before the plugin register (#2387)
14a6760 is described below

commit 14a6760d7206f3d71cf6ece027017090ca447c87
Author: pengtaopt <46...@users.noreply.github.com>
AuthorDate: Tue Apr 30 15:45:36 2019 +0800

    fix ios call native component method before the plugin register (#2387)
---
 ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.h  |  2 +-
 ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm | 47 +++++++++++++++++++++++---
 weex_core/Source/core/bridge/eagle_bridge.cpp  |  6 ++++
 weex_core/Source/core/bridge/eagle_bridge.h    |  2 +-
 weex_core/Source/core/bridge/platform_bridge.h |  1 +
 5 files changed, 51 insertions(+), 7 deletions(-)

diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.h b/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.h
index dace1ac..70b57e3 100644
--- a/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.h
+++ b/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.h
@@ -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 ;
diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm b/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm
index 50aa502..e39c901 100644
--- a/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm
+++ b/ios/sdk/WeexSDK/Sources/Bridge/WXCoreBridge.mm
@@ -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"
@@ -178,6 +178,47 @@ namespace WeexCore
         
         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();
@@ -196,10 +237,6 @@ namespace WeexCore
                 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;
diff --git a/weex_core/Source/core/bridge/eagle_bridge.cpp b/weex_core/Source/core/bridge/eagle_bridge.cpp
index 82dcf6e..7f2640d 100644
--- a/weex_core/Source/core/bridge/eagle_bridge.cpp
+++ b/weex_core/Source/core/bridge/eagle_bridge.cpp
@@ -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);
diff --git a/weex_core/Source/core/bridge/eagle_bridge.h b/weex_core/Source/core/bridge/eagle_bridge.h
index 7ae2c23..f119e64 100644
--- a/weex_core/Source/core/bridge/eagle_bridge.h
+++ b/weex_core/Source/core/bridge/eagle_bridge.h
@@ -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
         };
diff --git a/weex_core/Source/core/bridge/platform_bridge.h b/weex_core/Source/core/bridge/platform_bridge.h
index b994847..593e4b1 100644
--- a/weex_core/Source/core/bridge/platform_bridge.h
+++ b/weex_core/Source/core/bridge/platform_bridge.h
@@ -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;