rename dir
This commit is contained in:
10
doric-iOS/Pod/Classes/Plugin/DoricAnimatePlugin.h
Normal file
10
doric-iOS/Pod/Classes/Plugin/DoricAnimatePlugin.h
Normal file
@@ -0,0 +1,10 @@
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/11/29.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "DoricNativePlugin.h"
|
||||
|
||||
@interface DoricAnimatePlugin : DoricNativePlugin
|
||||
@end
|
33
doric-iOS/Pod/Classes/Plugin/DoricAnimatePlugin.m
Normal file
33
doric-iOS/Pod/Classes/Plugin/DoricAnimatePlugin.m
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/11/29.
|
||||
//
|
||||
|
||||
#import "DoricAnimatePlugin.h"
|
||||
#import "DoricRootNode.h"
|
||||
|
||||
@implementation DoricAnimatePlugin
|
||||
|
||||
- (void)submit:(NSDictionary *)args withPromise:(DoricPromise *)promise {
|
||||
[promise resolve:nil];
|
||||
}
|
||||
|
||||
- (void)animateRender:(NSDictionary *)args withPromise:(DoricPromise *)promise {
|
||||
NSNumber *duration = args[@"duration"];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSString *viewId = args[@"id"];
|
||||
[UIView animateWithDuration:[duration floatValue] / 1000
|
||||
animations:^{
|
||||
if (self.doricContext.rootNode.viewId == nil) {
|
||||
self.doricContext.rootNode.viewId = viewId;
|
||||
[self.doricContext.rootNode blend:args[@"props"]];
|
||||
} else {
|
||||
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
|
||||
[viewNode blend:args[@"props"]];
|
||||
}
|
||||
}
|
||||
completion:^(BOOL finished) {
|
||||
[promise resolve:nil];
|
||||
}];
|
||||
});
|
||||
}
|
||||
@end
|
32
doric-iOS/Pod/Classes/Plugin/DoricModalPlugin.h
Normal file
32
doric-iOS/Pod/Classes/Plugin/DoricModalPlugin.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
//
|
||||
// DoricModalPlugin.h
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/29.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricNativePlugin.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface DoricModalPlugin : DoricNativePlugin
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
115
doric-iOS/Pod/Classes/Plugin/DoricModalPlugin.m
Normal file
115
doric-iOS/Pod/Classes/Plugin/DoricModalPlugin.m
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
//
|
||||
// DoricModalPlugin.m
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/29.
|
||||
//
|
||||
|
||||
#import "DoricModalPlugin.h"
|
||||
#import "DoricUtil.h"
|
||||
#import "DoricExtensions.h"
|
||||
|
||||
@implementation DoricModalPlugin
|
||||
|
||||
- (void)toast:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
__block DoricGravity gravity = BOTTOM;
|
||||
[dic[@"gravity"] also:^(NSNumber *it) {
|
||||
gravity = (DoricGravity) [it integerValue];
|
||||
}];
|
||||
ShowToast(dic[@"msg"], gravity);
|
||||
});
|
||||
}
|
||||
|
||||
- (void)alert:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
UIAlertController *alert = [UIAlertController alertControllerWithTitle:dic[@"title"]
|
||||
message:dic[@"msg"]
|
||||
preferredStyle:UIAlertControllerStyleAlert];
|
||||
UIAlertAction *action = [UIAlertAction actionWithTitle:dic[@"okLabel"] ?: NSLocalizedString(@"OK", nil)
|
||||
style:UIAlertActionStyleDefault
|
||||
handler:^(UIAlertAction *action) {
|
||||
[promise resolve:nil];
|
||||
}];
|
||||
[alert addAction:action];
|
||||
UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController;
|
||||
[vc presentViewController:alert animated:YES completion:nil];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)confirm:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
UIAlertController *alert = [UIAlertController alertControllerWithTitle:dic[@"title"]
|
||||
message:dic[@"msg"]
|
||||
preferredStyle:UIAlertControllerStyleAlert];
|
||||
UIAlertAction *okAction = [UIAlertAction actionWithTitle:dic[@"okLabel"] ?: NSLocalizedString(@"Ok", nil)
|
||||
style:UIAlertActionStyleDefault
|
||||
handler:^(UIAlertAction *action) {
|
||||
[promise resolve:nil];
|
||||
}];
|
||||
[alert addAction:okAction];
|
||||
|
||||
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:dic[@"cancelLabel"] ?: NSLocalizedString(@"Cancel", nil)
|
||||
style:UIAlertActionStyleDefault
|
||||
handler:^(UIAlertAction *action) {
|
||||
[promise reject:nil];
|
||||
}];
|
||||
[alert addAction:cancelAction];
|
||||
UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController;
|
||||
[vc presentViewController:alert animated:YES completion:nil];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)prompt:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
UIAlertController *alert = [UIAlertController alertControllerWithTitle:dic[@"title"]
|
||||
message:dic[@"msg"]
|
||||
preferredStyle:UIAlertControllerStyleAlert];
|
||||
NSString *placeholder = dic[@"defaultText"];
|
||||
NSString *preText = dic[@"text"];
|
||||
[alert addTextFieldWithConfigurationHandler:^(UITextField *_Nonnull textField) {
|
||||
if (placeholder.length > 0) {
|
||||
textField.placeholder = placeholder;
|
||||
}
|
||||
if (preText.length > 0) {
|
||||
textField.text = preText;
|
||||
}
|
||||
}];
|
||||
__weak typeof(alert) _alert = alert;
|
||||
UIAlertAction *okAction = [UIAlertAction actionWithTitle:dic[@"okLabel"] ?: NSLocalizedString(@"Ok", nil)
|
||||
style:UIAlertActionStyleDefault
|
||||
handler:^(UIAlertAction *action) {
|
||||
__strong typeof(_alert) alert = _alert;
|
||||
[promise resolve:alert.textFields.lastObject.text];
|
||||
}];
|
||||
[alert addAction:okAction];
|
||||
|
||||
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:dic[@"cancelLabel"] ?: NSLocalizedString(@"Cancel", nil)
|
||||
style:UIAlertActionStyleDefault
|
||||
handler:^(UIAlertAction *action) {
|
||||
__strong typeof(_alert) alert = _alert;
|
||||
[promise reject:alert.textFields.lastObject.text];
|
||||
}];
|
||||
[alert addAction:cancelAction];
|
||||
|
||||
|
||||
UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController;
|
||||
[vc presentViewController:alert animated:YES completion:nil];
|
||||
});
|
||||
}
|
||||
@end
|
34
doric-iOS/Pod/Classes/Plugin/DoricNativePlugin.h
Normal file
34
doric-iOS/Pod/Classes/Plugin/DoricNativePlugin.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
//
|
||||
// DoricNativePlugin.h
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/29.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricContextHolder.h"
|
||||
#import "DoricPromise.h"
|
||||
#import "DoricRegistry.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface DoricNativePlugin : DoricContextHolder
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
27
doric-iOS/Pod/Classes/Plugin/DoricNativePlugin.m
Normal file
27
doric-iOS/Pod/Classes/Plugin/DoricNativePlugin.m
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
//
|
||||
// DoricNativePlugin.m
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/29.
|
||||
//
|
||||
|
||||
#import "DoricNativePlugin.h"
|
||||
|
||||
@implementation DoricNativePlugin
|
||||
|
||||
@end
|
26
doric-iOS/Pod/Classes/Plugin/DoricNavBarPlugin.h
Normal file
26
doric-iOS/Pod/Classes/Plugin/DoricNavBarPlugin.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/11/25.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "DoricNativePlugin.h"
|
||||
|
||||
@interface DoricNavBarPlugin : DoricNativePlugin
|
||||
|
||||
@end
|
68
doric-iOS/Pod/Classes/Plugin/DoricNavBarPlugin.m
Normal file
68
doric-iOS/Pod/Classes/Plugin/DoricNavBarPlugin.m
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/11/25.
|
||||
//
|
||||
|
||||
#import "DoricNavBarPlugin.h"
|
||||
#import "DoricUtil.h"
|
||||
|
||||
@implementation DoricNavBarPlugin
|
||||
- (void)isHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise {
|
||||
if (self.doricContext.navBar) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[promise resolve:@([self.doricContext.navBar doric_navBar_isHidden])];
|
||||
});
|
||||
} else {
|
||||
[promise reject:@"Not implement NavBar"];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise {
|
||||
if (self.doricContext.navBar) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.doricContext.navBar doric_navBar_setHidden:[param[@"hidden"] boolValue]];
|
||||
[promise resolve:nil];
|
||||
});
|
||||
} else {
|
||||
[promise reject:@"Not implement NavBar"];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setTitle:(NSDictionary *)param withPromise:(DoricPromise *)promise {
|
||||
if (self.doricContext.navBar) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.doricContext.navBar doric_navBar_setTitle:param[@"title"]];
|
||||
[promise resolve:nil];
|
||||
});
|
||||
} else {
|
||||
[promise reject:@"Not implement NavBar"];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setBgColor:(NSDictionary *)param withPromise:(DoricPromise *)promise {
|
||||
if (self.doricContext.navBar) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
UIColor *color = DoricColor(param[@"color"]);
|
||||
[self.doricContext.navBar doric_navBar_setBackgroundColor:color];
|
||||
[promise resolve:nil];
|
||||
});
|
||||
} else {
|
||||
[promise reject:@"Not implement NavBar"];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
24
doric-iOS/Pod/Classes/Plugin/DoricNavigatorPlugin.h
Normal file
24
doric-iOS/Pod/Classes/Plugin/DoricNavigatorPlugin.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/11/23.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricNativePlugin.h"
|
||||
|
||||
@interface DoricNavigatorPlugin : DoricNativePlugin
|
||||
@end
|
52
doric-iOS/Pod/Classes/Plugin/DoricNavigatorPlugin.m
Normal file
52
doric-iOS/Pod/Classes/Plugin/DoricNavigatorPlugin.m
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/11/23.
|
||||
//
|
||||
|
||||
#import "DoricNavigatorPlugin.h"
|
||||
|
||||
|
||||
@implementation DoricNavigatorPlugin
|
||||
- (void)push:(NSDictionary *)params {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
BOOL animated = YES;
|
||||
NSString *scheme = params[@"scheme"];
|
||||
NSString *alias = scheme;
|
||||
NSDictionary *config = params[@"config"];
|
||||
if (config) {
|
||||
if (config[@"animated"]) {
|
||||
animated = [config[@"animated"] boolValue];
|
||||
}
|
||||
|
||||
if (config[@"alias"]) {
|
||||
alias = config[@"alias"];
|
||||
}
|
||||
}
|
||||
[self.doricContext.navigator doric_navigator_push:scheme alias:alias animated:animated extra:config[@"extra"]];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)pop:(NSDictionary *)params {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
BOOL animated = YES;
|
||||
if (params[@"animated"]) {
|
||||
animated = [params[@"animated"] boolValue];
|
||||
}
|
||||
[self.doricContext.navigator doric_navigator_pop:animated];
|
||||
});
|
||||
}
|
||||
@end
|
24
doric-iOS/Pod/Classes/Plugin/DoricNetworkPlugin.h
Normal file
24
doric-iOS/Pod/Classes/Plugin/DoricNetworkPlugin.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/11/21.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricNativePlugin.h"
|
||||
|
||||
@interface DoricNetworkPlugin : DoricNativePlugin
|
||||
@end
|
59
doric-iOS/Pod/Classes/Plugin/DoricNetworkPlugin.m
Normal file
59
doric-iOS/Pod/Classes/Plugin/DoricNetworkPlugin.m
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/11/21.
|
||||
//
|
||||
|
||||
#import "DoricNetworkPlugin.h"
|
||||
|
||||
|
||||
@implementation DoricNetworkPlugin
|
||||
- (void)request:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
|
||||
NSString *url = dic[@"url"];
|
||||
NSString *method = dic[@"method"];
|
||||
NSDictionary <NSString *, NSString *> *headers = dic[@"headers"];
|
||||
NSNumber *timeout = dic[@"timeout"];
|
||||
NSString *data = dic[@"data"];
|
||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
|
||||
request.HTTPMethod = method.uppercaseString;
|
||||
if (timeout) {
|
||||
request.timeoutInterval = [timeout floatValue] / 1000;
|
||||
}
|
||||
if (headers) {
|
||||
[headers enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *obj, BOOL *stop) {
|
||||
[request setValue:obj forHTTPHeaderField:key];
|
||||
}];
|
||||
}
|
||||
if (data) {
|
||||
[request setHTTPBody:[data dataUsingEncoding:NSUTF8StringEncoding]];
|
||||
}
|
||||
[[[NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]
|
||||
dataTaskWithRequest:request
|
||||
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
|
||||
if (!error) {
|
||||
NSString *dataStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
NSDictionary *resDic = @{
|
||||
@"status": @(((NSHTTPURLResponse *) response).statusCode),
|
||||
@"headers": ((NSHTTPURLResponse *) response).allHeaderFields,
|
||||
@"data": dataStr,
|
||||
};
|
||||
[promise resolve:resDic];
|
||||
} else {
|
||||
[promise reject:error.description];
|
||||
}
|
||||
}] resume];
|
||||
}
|
||||
@end
|
9
doric-iOS/Pod/Classes/Plugin/DoricPopoverPlugin.h
Normal file
9
doric-iOS/Pod/Classes/Plugin/DoricPopoverPlugin.h
Normal file
@@ -0,0 +1,9 @@
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/11/28.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricNativePlugin.h"
|
||||
|
||||
@interface DoricPopoverPlugin : DoricNativePlugin
|
||||
@end
|
70
doric-iOS/Pod/Classes/Plugin/DoricPopoverPlugin.m
Normal file
70
doric-iOS/Pod/Classes/Plugin/DoricPopoverPlugin.m
Normal file
@@ -0,0 +1,70 @@
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/11/28.
|
||||
//
|
||||
|
||||
#import "DoricPopoverPlugin.h"
|
||||
#import "DoricRootNode.h"
|
||||
#import "Doric.h"
|
||||
|
||||
@interface DoricPopoverPlugin ()
|
||||
@property(nonatomic, strong) UIView *fullScreenView;
|
||||
@end
|
||||
|
||||
@implementation DoricPopoverPlugin
|
||||
- (void)show:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
UIView *superView = [UIApplication sharedApplication].windows.lastObject;
|
||||
if (!self.fullScreenView) {
|
||||
self.fullScreenView = [[DoricStackView new] also:^(UIView *it) {
|
||||
it.width = superView.width;
|
||||
it.height = superView.height;
|
||||
it.top = it.left = 0;
|
||||
[superView addSubview:it];
|
||||
}];
|
||||
}
|
||||
[superView bringSubviewToFront:self.fullScreenView];
|
||||
self.fullScreenView.hidden = NO;
|
||||
NSString *viewId = params[@"id"];
|
||||
NSString *type = params[@"type"];
|
||||
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
|
||||
if (!viewNode) {
|
||||
viewNode = [[DoricViewNode create:self.doricContext withType:type] also:^(DoricViewNode *it) {
|
||||
it.viewId = viewId;
|
||||
[it initWithSuperNode:nil];
|
||||
it.view.layoutConfig = [DoricLayoutConfig new];
|
||||
[self.fullScreenView addSubview:it.view];
|
||||
self.doricContext.headNodes[viewId] = it;
|
||||
}];
|
||||
}
|
||||
[viewNode blend:params[@"props"]];
|
||||
[promise resolve:nil];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)dismiss:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
||||
NSString *viewId = params[@"id"];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (viewId) {
|
||||
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
|
||||
[self dismissViewNode:viewNode];
|
||||
} else {
|
||||
[self dismissPopover];
|
||||
}
|
||||
[promise resolve:nil];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)dismissViewNode:(DoricViewNode *)node {
|
||||
[self.doricContext.headNodes removeObjectForKey:node.viewId];
|
||||
[node.view removeFromSuperview];
|
||||
if (self.doricContext.headNodes.count == 0) {
|
||||
self.fullScreenView.hidden = YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dismissPopover {
|
||||
for (DoricViewNode *node in self.doricContext.headNodes.allValues) {
|
||||
[self dismissViewNode:node];
|
||||
}
|
||||
}
|
||||
@end
|
32
doric-iOS/Pod/Classes/Plugin/DoricPromise.h
Normal file
32
doric-iOS/Pod/Classes/Plugin/DoricPromise.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
//
|
||||
// DoricPromise.h
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/29.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricContext.h"
|
||||
|
||||
@interface DoricPromise : NSObject
|
||||
- (instancetype)initWithContext:(DoricContext *)context callbackId:(NSString *)callbackId;
|
||||
|
||||
- (void)resolve:(id)result;
|
||||
|
||||
- (void)reject:(id)result;
|
||||
@end
|
49
doric-iOS/Pod/Classes/Plugin/DoricPromise.m
Normal file
49
doric-iOS/Pod/Classes/Plugin/DoricPromise.m
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
//
|
||||
// DoricPromise.m
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/29.
|
||||
//
|
||||
|
||||
#import "DoricPromise.h"
|
||||
#import "DoricConstant.h"
|
||||
|
||||
@interface DoricPromise ()
|
||||
@property(nonatomic, strong) DoricContext *context;
|
||||
@property(nonatomic, strong) NSString *callbackId;
|
||||
|
||||
@end
|
||||
|
||||
@implementation DoricPromise
|
||||
|
||||
- (instancetype)initWithContext:(DoricContext *)context callbackId:(NSString *)callbackId {
|
||||
if (self = [super init]) {
|
||||
_context = context;
|
||||
_callbackId = callbackId;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)resolve:(id)result {
|
||||
[self.context.driver invokeDoricMethod:DORIC_BRIDGE_RESOLVE, self.context.contextId, self.callbackId, result, nil];
|
||||
}
|
||||
|
||||
- (void)reject:(id)result {
|
||||
[self.context.driver invokeDoricMethod:DORIC_BRIDGE_REJECT, self.context.contextId, self.callbackId, result, nil];
|
||||
}
|
||||
@end
|
32
doric-iOS/Pod/Classes/Plugin/DoricShaderPlugin.h
Normal file
32
doric-iOS/Pod/Classes/Plugin/DoricShaderPlugin.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
//
|
||||
// DoricShaderPlugin.h
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/29.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricNativePlugin.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface DoricShaderPlugin : DoricNativePlugin
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
143
doric-iOS/Pod/Classes/Plugin/DoricShaderPlugin.m
Normal file
143
doric-iOS/Pod/Classes/Plugin/DoricShaderPlugin.m
Normal file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
//
|
||||
// DoricShaderPlugin.m
|
||||
// Doric
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/7/29.
|
||||
//
|
||||
|
||||
#import "DoricShaderPlugin.h"
|
||||
#import "DoricRootNode.h"
|
||||
#import "DoricUtil.h"
|
||||
|
||||
#import <objc/runtime.h>
|
||||
|
||||
@implementation DoricShaderPlugin
|
||||
|
||||
- (void)render:(NSDictionary *)argument {
|
||||
if (!argument) {
|
||||
return;
|
||||
}
|
||||
__weak typeof(self) _self = self;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
__strong typeof(_self) self = _self;
|
||||
|
||||
NSString *viewId = argument[@"id"];
|
||||
|
||||
if (self.doricContext.rootNode.viewId == nil) {
|
||||
self.doricContext.rootNode.viewId = viewId;
|
||||
[self.doricContext.rootNode blend:argument[@"props"]];
|
||||
} else {
|
||||
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
|
||||
[viewNode blend:argument[@"props"]];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (id)command:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
||||
NSArray *viewIds = argument[@"viewIds"];
|
||||
id args = argument[@"args"];
|
||||
NSString *name = argument[@"name"];
|
||||
DoricViewNode *viewNode = nil;
|
||||
for (NSString *viewId in viewIds) {
|
||||
if (!viewNode) {
|
||||
viewNode = [self.doricContext targetViewNode:viewId];
|
||||
} else {
|
||||
if ([viewNode isKindOfClass:[DoricSuperNode class]]) {
|
||||
viewNode = [((DoricSuperNode *) viewNode) subNodeWithViewId:viewId];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!viewNode) {
|
||||
[promise reject:@"Cannot find opposite view"];
|
||||
return nil;
|
||||
} else {
|
||||
return [self findClass:[viewNode class] target:viewNode method:name promise:promise argument:args];
|
||||
}
|
||||
}
|
||||
|
||||
- (id)createParamWithMethodName:(NSString *)method promise:(DoricPromise *)promise argument:(id)argument {
|
||||
if ([method isEqualToString:@"withPromise"]) {
|
||||
return promise;
|
||||
}
|
||||
return argument;
|
||||
}
|
||||
|
||||
- (id)findClass:(Class)clz target:(id)target method:(NSString *)name promise:(DoricPromise *)promise argument:(id)argument {
|
||||
unsigned int count;
|
||||
id ret = nil;
|
||||
Method *methods = class_copyMethodList(clz, &count);
|
||||
BOOL isFound = NO;
|
||||
for (int i = 0; i < count; i++) {
|
||||
NSString *methodName = [NSString stringWithCString:sel_getName(method_getName(methods[i])) encoding:NSUTF8StringEncoding];
|
||||
NSArray *array = [methodName componentsSeparatedByString:@":"];
|
||||
if (array && [array count] > 0) {
|
||||
if ([array[0] isEqualToString:name]) {
|
||||
isFound = YES;
|
||||
SEL selector = NSSelectorFromString(methodName);
|
||||
NSMethodSignature *methodSignature = [target methodSignatureForSelector:selector];
|
||||
if (methodSignature) {
|
||||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
|
||||
invocation.selector = selector;
|
||||
invocation.target = target;
|
||||
__weak __typeof__(self) _self = self;
|
||||
dispatch_block_t block = ^() {
|
||||
__strong __typeof__(_self) self = _self;
|
||||
@try {
|
||||
for (NSUInteger idx = 2; idx < methodSignature.numberOfArguments; idx++) {
|
||||
if (idx - 2 > [array count]) {
|
||||
break;
|
||||
}
|
||||
id param = [self createParamWithMethodName:array[idx - 2] promise:promise argument:argument];
|
||||
[invocation setArgument:¶m atIndex:idx];
|
||||
}
|
||||
[invocation invoke];
|
||||
} @catch (NSException *exception) {
|
||||
DoricLog(@"CallNative Error:%@", exception.reason);
|
||||
}
|
||||
};
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
void *retValue;
|
||||
block();
|
||||
const char *retType = methodSignature.methodReturnType;
|
||||
if (!strcmp(retType, @encode(void))) {
|
||||
} else {
|
||||
[invocation getReturnValue:&retValue];
|
||||
id returnValue = (__bridge id) retValue;
|
||||
[promise resolve:returnValue];
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (methods) {
|
||||
free(methods);
|
||||
}
|
||||
if (!isFound) {
|
||||
Class superclass = class_getSuperclass(clz);
|
||||
if (superclass && superclass != [NSObject class]) {
|
||||
return [self findClass:superclass target:target method:name promise:promise argument:argument];
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@end
|
24
doric-iOS/Pod/Classes/Plugin/DoricStoragePlugin.h
Normal file
24
doric-iOS/Pod/Classes/Plugin/DoricStoragePlugin.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/11/22.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricNativePlugin.h"
|
||||
|
||||
@interface DoricStoragePlugin : DoricNativePlugin
|
||||
@end
|
98
doric-iOS/Pod/Classes/Plugin/DoricStoragePlugin.m
Normal file
98
doric-iOS/Pod/Classes/Plugin/DoricStoragePlugin.m
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright [2019] [Doric.Pub]
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/11/22.
|
||||
//
|
||||
|
||||
#import "DoricStoragePlugin.h"
|
||||
#import "YYDiskCache.h"
|
||||
|
||||
static NSString *doric_prefix = @"pref";
|
||||
|
||||
@interface DoricStoragePlugin ()
|
||||
@property(atomic, strong) NSMutableDictionary <NSString *, YYDiskCache *> *cachedMap;
|
||||
@property(nonatomic, strong) YYDiskCache *defaultCache;
|
||||
@property(nonatomic, copy) NSString *basePath;
|
||||
@end
|
||||
|
||||
@implementation DoricStoragePlugin
|
||||
- (instancetype)initWithContext:(DoricContext *)doricContext {
|
||||
if (self = [super initWithContext:doricContext]) {
|
||||
_basePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
|
||||
stringByAppendingPathComponent:@"doric"];
|
||||
_cachedMap = [NSMutableDictionary new];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (YYDiskCache *)defaultCache {
|
||||
if (!_defaultCache) {
|
||||
_defaultCache = [[YYDiskCache alloc] initWithPath:[self.basePath stringByAppendingPathComponent:doric_prefix]];
|
||||
}
|
||||
return _defaultCache;
|
||||
}
|
||||
|
||||
- (YYDiskCache *)getDiskCache:(NSString *)zone {
|
||||
YYDiskCache *diskCache;
|
||||
if (zone) {
|
||||
diskCache = self.cachedMap[zone];
|
||||
if (!diskCache) {
|
||||
diskCache = [[YYDiskCache alloc] initWithPath:[self.basePath
|
||||
stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@", doric_prefix, zone]]];
|
||||
self.cachedMap[zone] = diskCache;
|
||||
}
|
||||
} else {
|
||||
diskCache = self.defaultCache;
|
||||
}
|
||||
return diskCache;
|
||||
}
|
||||
|
||||
- (void)setItem:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
||||
NSString *zone = argument[@"zone"];
|
||||
NSString *key = argument[@"key"];
|
||||
NSString *value = argument[@"value"];
|
||||
YYDiskCache *diskCache = [self getDiskCache:zone];
|
||||
[diskCache setObject:value forKey:key withBlock:^{
|
||||
[promise resolve:nil];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)getItem:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
||||
NSString *zone = argument[@"zone"];
|
||||
NSString *key = argument[@"key"];
|
||||
YYDiskCache *diskCache = [self getDiskCache:zone];
|
||||
[diskCache objectForKey:key withBlock:^(NSString *key, NSString *value) {
|
||||
[promise resolve:value];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)remove:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
||||
NSString *zone = argument[@"zone"];
|
||||
NSString *key = argument[@"key"];
|
||||
YYDiskCache *diskCache = [self getDiskCache:zone];
|
||||
[diskCache removeObjectForKey:key withBlock:^(NSString *key) {
|
||||
[promise resolve:nil];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)clear:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
||||
NSString *zone = argument[@"zone"];
|
||||
YYDiskCache *diskCache = [self getDiskCache:zone];
|
||||
[diskCache removeAllObjectsWithBlock:^{
|
||||
[promise resolve:nil];
|
||||
}];
|
||||
}
|
||||
@end
|
Reference in New Issue
Block a user