You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by mo...@apache.org on 2020/02/07 02:34:42 UTC
[incubator-weex] branch master updated: [iOS] support module
intercept
This is an automated email from the ASF dual-hosted git repository.
moshen 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 0d75d53 [iOS] support module intercept
new 1dfb498 Merge pull request #3131 from jianhan-he/master
0d75d53 is described below
commit 0d75d53b8855ee894fe0db4c0ad1b822df4bcab9
Author: linghe.lh <li...@alibaba-inc.com>
AuthorDate: Thu Feb 6 13:03:44 2020 +0800
[iOS] support module intercept
---
ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m | 6 ++++
ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h | 13 ++++++++
ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m | 40 ++++++++++++++++++++++++
3 files changed, 59 insertions(+)
diff --git a/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m b/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m
index d72c379..7f1e8f1 100644
--- a/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m
+++ b/ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m
@@ -336,6 +336,7 @@ _Pragma("clang diagnostic pop") \
WXLogInfo(@"instance not found for callNativeModule:%@.%@, maybe already destroyed", moduleName, methodName);
return nil;
}
+
#ifdef DEBUG
WXLogDebug(@"flexLayout -> action: callNativeModule : %@ . %@",moduleName,methodName);
#endif
@@ -363,6 +364,11 @@ _Pragma("clang diagnostic pop") \
[WXPrerenderManager storePrerenderModuleTasks:method forUrl:instance.scriptURL.absoluteString];
return nil;
}
+
+ BOOL intercepted = [instance moduleInterceptWithModuleName:moduleName methodName:methodName arguments:[newArguments copy] options:[newOptions copy]];
+ if (intercepted) {
+ return nil;
+ }
return [method invoke];
}];
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h
index e7d4fb1..84e6802 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h
+++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.h
@@ -32,6 +32,8 @@ NS_ASSUME_NONNULL_BEGIN
extern NSString *const bundleUrlOptionKey;
+typedef BOOL (^WXModuleInterceptCallback)(NSString *moduleName, NSString *methodName, NSArray *arguments, NSDictionary *options);
+
@interface WXSDKInstance : NSObject
/**
@@ -491,6 +493,17 @@ typedef enum : NSUInteger {
- (void)setCurrentSchemeName:(NSString*)name;
/**
+ register/unRegister module intercept
+ */
+- (void)registerModuleIntercept:(NSString*)moduleName callBack:(WXModuleInterceptCallback)callback;
+- (void)unRegisterModuleIntercept:(NSString*)moduleName;
+
+/**
+ call module intercept
+ */
+- (BOOL)moduleInterceptWithModuleName:(NSString*)moduleName methodName:(NSString*)methodName arguments:(NSArray*)arguments options:(NSDictionary*)options;
+
+/**
Choose final color between original color and dark-mode one.
Also considering invert.
*/
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
index 81bf780..67d2233 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
+++ b/ios/sdk/WeexSDK/Sources/Model/WXSDKInstance.m
@@ -87,6 +87,7 @@ typedef enum : NSUInteger {
BOOL _debugJS;
id<WXBridgeProtocol> _instanceJavaScriptContext; // sandbox javaScript context
BOOL _defaultDataRender;
+ NSMutableDictionary *_moduleIntercepts;
}
- (void)dealloc
@@ -157,6 +158,7 @@ typedef enum : NSUInteger {
_styleConfigs = [NSMutableDictionary new];
_attrConfigs = [NSMutableDictionary new];
_moduleEventObservers = [WXThreadSafeMutableDictionary new];
+ _moduleIntercepts = [NSMutableDictionary new];
_trackComponent = NO;
_performanceCommit = NO;
@@ -1223,6 +1225,44 @@ typedef enum : NSUInteger {
return [self.schemeName isEqualToString:@"dark"];
}
+- (void)registerModuleIntercept:(NSString*)moduleName callBack:(WXModuleInterceptCallback)callback {
+ __weak WXSDKInstance* weakSelf = self;
+ WXPerformBlockOnBridgeThread(^{
+ __strong WXSDKInstance* strongSelf = weakSelf;
+ if (strongSelf == nil) {
+ return;
+ }
+ if (![WXUtility isBlankString:moduleName] && callback) {
+ [strongSelf->_moduleIntercepts setObject:callback forKey:moduleName];
+ }
+ });
+}
+
+- (void)unRegisterModuleIntercept:(NSString*)moduleName {
+ __weak WXSDKInstance* weakSelf = self;
+ WXPerformBlockOnBridgeThread(^{
+ __strong WXSDKInstance* strongSelf = weakSelf;
+ if (strongSelf == nil) {
+ return;
+ }
+ if (![WXUtility isBlankString:moduleName]) {
+ [strongSelf->_moduleIntercepts removeObjectForKey:moduleName];
+ }
+ });
+}
+
+- (BOOL)moduleInterceptWithModuleName:(NSString*)moduleName methodName:(NSString*)methodName arguments:(NSArray*)arguments options:(NSDictionary*)options {
+ WXAssertBridgeThread();
+ if ([WXUtility isBlankString:moduleName]) {
+ return NO;
+ }
+ WXModuleInterceptCallback callBack = [_moduleIntercepts objectForKey:moduleName];
+ if (callBack) {
+ return callBack(moduleName, methodName, arguments, options);
+ }
+ return NO;
+}
+
- (void)setCurrentSchemeName:(NSString*)name
{
if (![WXUtility isDarkSchemeSupportEnabled]) {