You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by bo...@apache.org on 2017/04/18 09:51:14 UTC

[5/8] incubator-weex git commit: * [ios] add config for componentWithName

* [ios] add config for componentWithName


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/b2d38557
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/b2d38557
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/b2d38557

Branch: refs/heads/0.12-dev
Commit: b2d38557969853b34e4b803ea2aba7a02500d4b3
Parents: e433321
Author: acton393 <zh...@gmail.com>
Authored: Tue Apr 18 11:09:31 2017 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Tue Apr 18 11:09:31 2017 +0800

----------------------------------------------------------------------
 .../Sources/Handler/WXConfigDefaultImpl.h       | 26 ++++++++++
 .../Sources/Handler/WXConfigDefaultImpl.m       | 54 ++++++++++++++++++++
 .../Sources/Manager/WXComponentFactory.m        |  7 +++
 .../WeexSDK/Sources/Protocol/WXConfigProtocol.h | 27 ++++++++++
 4 files changed, 114 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b2d38557/ios/sdk/WeexSDK/Sources/Handler/WXConfigDefaultImpl.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Handler/WXConfigDefaultImpl.h b/ios/sdk/WeexSDK/Sources/Handler/WXConfigDefaultImpl.h
new file mode 100644
index 0000000..ccd7280
--- /dev/null
+++ b/ios/sdk/WeexSDK/Sources/Handler/WXConfigDefaultImpl.h
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#import <Foundation/Foundation.h>
+
+#import "WXConfigProtocol.h"
+
+@interface WXConfigDefaultImpl : NSObject<WXConfigProtocol>
+
+@end

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b2d38557/ios/sdk/WeexSDK/Sources/Handler/WXConfigDefaultImpl.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Handler/WXConfigDefaultImpl.m b/ios/sdk/WeexSDK/Sources/Handler/WXConfigDefaultImpl.m
new file mode 100644
index 0000000..1d2ebf5
--- /dev/null
+++ b/ios/sdk/WeexSDK/Sources/Handler/WXConfigDefaultImpl.m
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#import "WXConfigDefaultImpl.h"
+#import "WXThreadSafeMutableDictionary.h"
+#import "WXUtility.h"
+
+@interface WXConfigDefaultImpl()
+@property(nonatomic, strong) WXThreadSafeMutableDictionary* configDic;
+@end
+@implementation WXConfigDefaultImpl
+
+- (instancetype)init
+{
+    if (self = [super init]) {
+        _configDic = [WXThreadSafeMutableDictionary new];
+    }
+    
+    return self;
+}
+
+- (void)setClassWithName:(Class)className name:(NSString *)name
+{
+    if (![WXUtility isBlankString:name] && className) {
+        [_configDic setObject:className forKey:name];
+    }
+}
+
+- (Class)classWithName:(NSString *)name
+{
+    if (![WXUtility isBlankString:name]) {
+        return [_configDic objectForKey:name];
+    }
+    
+    return nil;
+}
+
+@end

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b2d38557/ios/sdk/WeexSDK/Sources/Manager/WXComponentFactory.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXComponentFactory.m b/ios/sdk/WeexSDK/Sources/Manager/WXComponentFactory.m
index aa79bad..7589dfe 100644
--- a/ios/sdk/WeexSDK/Sources/Manager/WXComponentFactory.m
+++ b/ios/sdk/WeexSDK/Sources/Manager/WXComponentFactory.m
@@ -21,6 +21,8 @@
 #import "WXAssert.h"
 #import "WXLog.h"
 #import "WXInvocationConfig.h"
+#import "WXHandlerFactory.h"
+#import "WXConfigProtocol.h"
 
 #import <objc/runtime.h>
 
@@ -189,6 +191,11 @@
     if(!config || !config.clazz) {
         return nil;
     }
+    id<WXConfigProtocol> configHandler = [WXHandlerFactory handlerForProtocol:NSProtocolFromString(@"WXConfigProtocol")];
+    
+    if ([configHandler respondsToSelector:@selector(classWithName:)]) {
+        return [configHandler classWithName:name];
+    }
     
     return NSClassFromString(config.clazz);
 }

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b2d38557/ios/sdk/WeexSDK/Sources/Protocol/WXConfigProtocol.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Protocol/WXConfigProtocol.h b/ios/sdk/WeexSDK/Sources/Protocol/WXConfigProtocol.h
new file mode 100644
index 0000000..a4a9e93
--- /dev/null
+++ b/ios/sdk/WeexSDK/Sources/Protocol/WXConfigProtocol.h
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+@protocol WXConfigProtocol <NSObject>
+
+@optional
+
+- (Class)classWithName:(NSString*)name;
+- (void)setClassWithName:(Class)className name:(NSString*)name;
+
+@end