iOS:Native plugin use safe method to get from dictionary,avoid type error
This commit is contained in:
parent
156f70bb97
commit
fe4e90ec53
@ -17,8 +17,10 @@
|
|||||||
// Created by pengfei.zhou on 2019/11/29.
|
// Created by pengfei.zhou on 2019/11/29.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#import <DoricCore/Doric.h>
|
||||||
#import "DoricAnimatePlugin.h"
|
#import "DoricAnimatePlugin.h"
|
||||||
#import "DoricRootNode.h"
|
#import "DoricRootNode.h"
|
||||||
|
#import "DoricExtensions.h"
|
||||||
|
|
||||||
@implementation DoricAnimatePlugin
|
@implementation DoricAnimatePlugin
|
||||||
|
|
||||||
@ -27,20 +29,21 @@ - (void)submit:(NSDictionary *)args withPromise:(DoricPromise *)promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)animateRender:(NSDictionary *)args withPromise:(DoricPromise *)promise {
|
- (void)animateRender:(NSDictionary *)args withPromise:(DoricPromise *)promise {
|
||||||
NSNumber *duration = args[@"duration"];
|
NSNumber *duration = [args optNumber:@"duration"];
|
||||||
|
NSString *viewId = [args optString:@"id"];
|
||||||
|
NSDictionary *props = [args optObject:@"props"];
|
||||||
__weak typeof(self) _self = self;
|
__weak typeof(self) _self = self;
|
||||||
[self.doricContext dispatchToMainQueue:^{
|
[self.doricContext dispatchToMainQueue:^{
|
||||||
__strong typeof(_self) self = _self;
|
__strong typeof(_self) self = _self;
|
||||||
NSString *viewId = args[@"id"];
|
|
||||||
[UIView animateWithDuration:[duration floatValue] / 1000
|
[UIView animateWithDuration:[duration floatValue] / 1000
|
||||||
animations:^{
|
animations:^{
|
||||||
if (self.doricContext.rootNode.viewId == nil) {
|
if (self.doricContext.rootNode.viewId == nil) {
|
||||||
self.doricContext.rootNode.viewId = viewId;
|
self.doricContext.rootNode.viewId = viewId;
|
||||||
[self.doricContext.rootNode blend:args[@"props"]];
|
[self.doricContext.rootNode blend:props];
|
||||||
[self.doricContext.rootNode requestLayout];
|
[self.doricContext.rootNode requestLayout];
|
||||||
} else {
|
} else {
|
||||||
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
|
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
|
||||||
[viewNode blend:args[@"props"]];
|
[viewNode blend:props];
|
||||||
[viewNode requestLayout];
|
[viewNode requestLayout];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,11 +17,13 @@
|
|||||||
// Created by pengfei.zhou on 2020/2/13.
|
// Created by pengfei.zhou on 2020/2/13.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#import <DoricCore/Doric.h>
|
||||||
#import "DoricCoordinatorPlugin.h"
|
#import "DoricCoordinatorPlugin.h"
|
||||||
#import "DoricSuperNode.h"
|
#import "DoricSuperNode.h"
|
||||||
#import "DoricScrollableProtocol.h"
|
#import "DoricScrollableProtocol.h"
|
||||||
#import "DoricUtil.h"
|
#import "DoricUtil.h"
|
||||||
#import "DoricRootNode.h"
|
#import "DoricRootNode.h"
|
||||||
|
#import "DoricExtensions.h"
|
||||||
|
|
||||||
@implementation DoricCoordinatorPlugin
|
@implementation DoricCoordinatorPlugin
|
||||||
|
|
||||||
@ -29,7 +31,7 @@ - (void)verticalScrolling:(NSDictionary *)params withPromise:(DoricPromise *)pro
|
|||||||
__weak typeof(self) _self = self;
|
__weak typeof(self) _self = self;
|
||||||
[self.doricContext dispatchToMainQueue:^{
|
[self.doricContext dispatchToMainQueue:^{
|
||||||
__strong typeof(_self) self = _self;
|
__strong typeof(_self) self = _self;
|
||||||
NSArray <NSString *> *scrollableIds = params[@"scrollable"];
|
NSArray <NSString *> *scrollableIds = [params optArray:@"scrollable"];
|
||||||
DoricViewNode *scrollNode = nil;
|
DoricViewNode *scrollNode = nil;
|
||||||
for (NSString *value in scrollableIds) {
|
for (NSString *value in scrollableIds) {
|
||||||
if (!scrollNode) {
|
if (!scrollNode) {
|
||||||
@ -44,9 +46,9 @@ - (void)verticalScrolling:(NSDictionary *)params withPromise:(DoricPromise *)pro
|
|||||||
[promise reject:@"Cannot find scrollable view"];
|
[promise reject:@"Cannot find scrollable view"];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
NSDictionary *scrollRange = params[@"scrollRange"];
|
NSDictionary *scrollRange = [params optObject:@"scrollRange"];
|
||||||
CGFloat startAnchor = [scrollRange[@"start"] floatValue];
|
CGFloat startAnchor = [[scrollRange optNumber:@"start"] floatValue];
|
||||||
CGFloat endAnchor = [scrollRange[@"end"] floatValue];
|
CGFloat endAnchor = [[scrollRange optNumber:@"end"] floatValue];
|
||||||
id target = params[@"target"];
|
id target = params[@"target"];
|
||||||
BOOL isNavBar = false;
|
BOOL isNavBar = false;
|
||||||
DoricViewNode *targetNode = nil;
|
DoricViewNode *targetNode = nil;
|
||||||
@ -66,10 +68,10 @@ - (void)verticalScrolling:(NSDictionary *)params withPromise:(DoricPromise *)pro
|
|||||||
[promise reject:@"Cannot find target view"];
|
[promise reject:@"Cannot find target view"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NSDictionary *changing = params[@"changing"];
|
NSDictionary *changing = [params optObject:@"changing"];
|
||||||
NSString *name = changing[@"name"];
|
NSString *name = [changing optString:@"name"];
|
||||||
NSNumber *changingStart = changing[@"start"];
|
NSNumber *changingStart = [changing optNumber:@"start"];
|
||||||
NSNumber *changingEnd = changing[@"end"];
|
NSNumber *changingEnd = [changing optNumber:@"end"];
|
||||||
if ([scrollNode conformsToProtocol:@protocol(DoricScrollableProtocol)]) {
|
if ([scrollNode conformsToProtocol:@protocol(DoricScrollableProtocol)]) {
|
||||||
__weak typeof(self) __self = self;
|
__weak typeof(self) __self = self;
|
||||||
[(id <DoricScrollableProtocol>) scrollNode addDidScrollBlock:^(UIScrollView *scrollView) {
|
[(id <DoricScrollableProtocol>) scrollNode addDidScrollBlock:^(UIScrollView *scrollView) {
|
||||||
|
@ -31,13 +31,13 @@ - (void)toast:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
|
|||||||
[self.doricContext dispatchToMainQueue:^{
|
[self.doricContext dispatchToMainQueue:^{
|
||||||
__strong typeof(_self) self = _self;
|
__strong typeof(_self) self = _self;
|
||||||
__block DoricGravity gravity = DoricGravityBottom;
|
__block DoricGravity gravity = DoricGravityBottom;
|
||||||
[dic[@"gravity"] also:^(NSNumber *it) {
|
[[dic optNumber:@"gravity"] also:^(NSNumber *it) {
|
||||||
gravity = (DoricGravity) [it integerValue];
|
gravity = (DoricGravity) [it integerValue];
|
||||||
}];
|
}];
|
||||||
if (self.doricContext.vc) {
|
if (self.doricContext.vc) {
|
||||||
ShowToastInVC(self.doricContext.vc, dic[@"msg"], gravity);
|
ShowToastInVC(self.doricContext.vc, [dic optString:@"msg"], gravity);
|
||||||
} else {
|
} else {
|
||||||
ShowToast(dic[@"msg"], gravity);
|
ShowToast([dic optString:@"msg"], gravity);
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
@ -46,10 +46,10 @@ - (void)alert:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
|
|||||||
__weak typeof(self) _self = self;
|
__weak typeof(self) _self = self;
|
||||||
[self.doricContext dispatchToMainQueue:^{
|
[self.doricContext dispatchToMainQueue:^{
|
||||||
__strong typeof(_self) self = _self;
|
__strong typeof(_self) self = _self;
|
||||||
UIAlertController *alert = [UIAlertController alertControllerWithTitle:dic[@"title"]
|
UIAlertController *alert = [UIAlertController alertControllerWithTitle:[dic optString:@"title"]
|
||||||
message:dic[@"msg"]
|
message:[dic optString:@"msg"]
|
||||||
preferredStyle:UIAlertControllerStyleAlert];
|
preferredStyle:UIAlertControllerStyleAlert];
|
||||||
UIAlertAction *action = [UIAlertAction actionWithTitle:dic[@"okLabel"] ?: NSLocalizedString(@"OK", nil)
|
UIAlertAction *action = [UIAlertAction actionWithTitle:[dic optString:@"okLabel"] ?: NSLocalizedString(@"OK", nil)
|
||||||
style:UIAlertActionStyleDefault
|
style:UIAlertActionStyleDefault
|
||||||
handler:^(UIAlertAction *action) {
|
handler:^(UIAlertAction *action) {
|
||||||
[promise resolve:nil];
|
[promise resolve:nil];
|
||||||
@ -63,18 +63,18 @@ - (void)confirm:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
|
|||||||
__weak typeof(self) _self = self;
|
__weak typeof(self) _self = self;
|
||||||
[self.doricContext dispatchToMainQueue:^{
|
[self.doricContext dispatchToMainQueue:^{
|
||||||
__strong typeof(_self) self = _self;
|
__strong typeof(_self) self = _self;
|
||||||
UIAlertController *alert = [UIAlertController alertControllerWithTitle:dic[@"title"]
|
UIAlertController *alert = [UIAlertController alertControllerWithTitle:[dic optString:@"title"]
|
||||||
message:dic[@"msg"]
|
message:[dic optString:@"msg"]
|
||||||
preferredStyle:UIAlertControllerStyleAlert];
|
preferredStyle:UIAlertControllerStyleAlert];
|
||||||
|
|
||||||
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:dic[@"cancelLabel"] ?: NSLocalizedString(@"Cancel", nil)
|
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:[dic optString:@"cancelLabel"] ?: NSLocalizedString(@"Cancel", nil)
|
||||||
style:UIAlertActionStyleDefault
|
style:UIAlertActionStyleDefault
|
||||||
handler:^(UIAlertAction *action) {
|
handler:^(UIAlertAction *action) {
|
||||||
[promise reject:nil];
|
[promise reject:nil];
|
||||||
}];
|
}];
|
||||||
[alert addAction:cancelAction];
|
[alert addAction:cancelAction];
|
||||||
|
|
||||||
UIAlertAction *okAction = [UIAlertAction actionWithTitle:dic[@"okLabel"] ?: NSLocalizedString(@"Ok", nil)
|
UIAlertAction *okAction = [UIAlertAction actionWithTitle:[dic optString:@"okLabel"] ?: NSLocalizedString(@"Ok", nil)
|
||||||
style:UIAlertActionStyleDefault
|
style:UIAlertActionStyleDefault
|
||||||
handler:^(UIAlertAction *action) {
|
handler:^(UIAlertAction *action) {
|
||||||
[promise resolve:nil];
|
[promise resolve:nil];
|
||||||
@ -89,11 +89,11 @@ - (void)prompt:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
|
|||||||
__weak typeof(self) _self = self;
|
__weak typeof(self) _self = self;
|
||||||
[self.doricContext dispatchToMainQueue:^{
|
[self.doricContext dispatchToMainQueue:^{
|
||||||
__strong typeof(_self) self = _self;
|
__strong typeof(_self) self = _self;
|
||||||
UIAlertController *alert = [UIAlertController alertControllerWithTitle:dic[@"title"]
|
UIAlertController *alert = [UIAlertController alertControllerWithTitle:[dic optString:@"title"]
|
||||||
message:dic[@"msg"]
|
message:[dic optString:@"msg"]
|
||||||
preferredStyle:UIAlertControllerStyleAlert];
|
preferredStyle:UIAlertControllerStyleAlert];
|
||||||
NSString *placeholder = dic[@"defaultText"];
|
NSString *placeholder = [dic optString:@"defaultText"];
|
||||||
NSString *preText = dic[@"text"];
|
NSString *preText = [dic optString:@"text"];
|
||||||
[alert addTextFieldWithConfigurationHandler:^(UITextField *_Nonnull textField) {
|
[alert addTextFieldWithConfigurationHandler:^(UITextField *_Nonnull textField) {
|
||||||
if (placeholder.length > 0) {
|
if (placeholder.length > 0) {
|
||||||
textField.placeholder = placeholder;
|
textField.placeholder = placeholder;
|
||||||
@ -104,7 +104,7 @@ - (void)prompt:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
|
|||||||
}];
|
}];
|
||||||
__weak typeof(alert) _alert = alert;
|
__weak typeof(alert) _alert = alert;
|
||||||
|
|
||||||
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:dic[@"cancelLabel"] ?: NSLocalizedString(@"Cancel", nil)
|
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:[dic optString:@"cancelLabel"] ?: NSLocalizedString(@"Cancel", nil)
|
||||||
style:UIAlertActionStyleDefault
|
style:UIAlertActionStyleDefault
|
||||||
handler:^(UIAlertAction *action) {
|
handler:^(UIAlertAction *action) {
|
||||||
__strong typeof(_alert) alert = _alert;
|
__strong typeof(_alert) alert = _alert;
|
||||||
@ -112,7 +112,7 @@ - (void)prompt:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
|
|||||||
}];
|
}];
|
||||||
[alert addAction:cancelAction];
|
[alert addAction:cancelAction];
|
||||||
|
|
||||||
UIAlertAction *okAction = [UIAlertAction actionWithTitle:dic[@"okLabel"] ?: NSLocalizedString(@"Ok", nil)
|
UIAlertAction *okAction = [UIAlertAction actionWithTitle:[dic optString:@"okLabel"] ?: NSLocalizedString(@"Ok", nil)
|
||||||
style:UIAlertActionStyleDefault
|
style:UIAlertActionStyleDefault
|
||||||
handler:^(UIAlertAction *action) {
|
handler:^(UIAlertAction *action) {
|
||||||
__strong typeof(_alert) alert = _alert;
|
__strong typeof(_alert) alert = _alert;
|
||||||
|
@ -45,7 +45,7 @@ - (void)setHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise {
|
|||||||
__weak typeof(self) _self = self;
|
__weak typeof(self) _self = self;
|
||||||
[self.doricContext dispatchToMainQueue:^{
|
[self.doricContext dispatchToMainQueue:^{
|
||||||
__strong typeof(_self) self = _self;
|
__strong typeof(_self) self = _self;
|
||||||
[self.doricContext.navBar doric_navBar_setHidden:[param[@"hidden"] boolValue]];
|
[self.doricContext.navBar doric_navBar_setHidden:[param optBool:@"hidden"]];
|
||||||
[promise resolve:nil];
|
[promise resolve:nil];
|
||||||
}];
|
}];
|
||||||
} else {
|
} else {
|
||||||
@ -58,7 +58,7 @@ - (void)setTitle:(NSDictionary *)param withPromise:(DoricPromise *)promise {
|
|||||||
__weak typeof(self) _self = self;
|
__weak typeof(self) _self = self;
|
||||||
[self.doricContext dispatchToMainQueue:^{
|
[self.doricContext dispatchToMainQueue:^{
|
||||||
__strong typeof(_self) self = _self;
|
__strong typeof(_self) self = _self;
|
||||||
[self.doricContext.navBar doric_navBar_setTitle:param[@"title"]];
|
[self.doricContext.navBar doric_navBar_setTitle:[param optString:@"title"]];
|
||||||
[promise resolve:nil];
|
[promise resolve:nil];
|
||||||
}];
|
}];
|
||||||
} else {
|
} else {
|
||||||
@ -71,7 +71,7 @@ - (void)setBgColor:(NSDictionary *)param withPromise:(DoricPromise *)promise {
|
|||||||
__weak typeof(self) _self = self;
|
__weak typeof(self) _self = self;
|
||||||
[self.doricContext dispatchToMainQueue:^{
|
[self.doricContext dispatchToMainQueue:^{
|
||||||
__strong typeof(_self) self = _self;
|
__strong typeof(_self) self = _self;
|
||||||
UIColor *color = DoricColor(param[@"color"]);
|
UIColor *color = DoricColor([param optNumber:@"color"]);
|
||||||
[self.doricContext.navBar doric_navBar_setBackgroundColor:color];
|
[self.doricContext.navBar doric_navBar_setBackgroundColor:color];
|
||||||
[promise resolve:nil];
|
[promise resolve:nil];
|
||||||
}];
|
}];
|
||||||
@ -85,8 +85,8 @@ - (void)setLeft:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
|||||||
__weak typeof(self) _self = self;
|
__weak typeof(self) _self = self;
|
||||||
[self.doricContext dispatchToMainQueue:^{
|
[self.doricContext dispatchToMainQueue:^{
|
||||||
__strong typeof(_self) self = _self;
|
__strong typeof(_self) self = _self;
|
||||||
NSString *viewId = params[@"id"];
|
NSString *viewId = [params optString:@"id"];
|
||||||
NSString *type = params[@"type"];
|
NSString *type = [params optString:@"type"];
|
||||||
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
|
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
|
||||||
if (!viewNode) {
|
if (!viewNode) {
|
||||||
viewNode = [[DoricViewNode create:self.doricContext withType:type] also:^(DoricViewNode *it) {
|
viewNode = [[DoricViewNode create:self.doricContext withType:type] also:^(DoricViewNode *it) {
|
||||||
@ -103,7 +103,7 @@ - (void)setLeft:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
|||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
[viewNode blend:params[@"props"]];
|
[viewNode blend:[params optObject:@"props"]];
|
||||||
[self.doricContext.navBar doric_navBar_setLeft:viewNode.view];
|
[self.doricContext.navBar doric_navBar_setLeft:viewNode.view];
|
||||||
[promise resolve:nil];
|
[promise resolve:nil];
|
||||||
}];
|
}];
|
||||||
@ -117,8 +117,8 @@ - (void)setRight:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
|||||||
__weak typeof(self) _self = self;
|
__weak typeof(self) _self = self;
|
||||||
[self.doricContext dispatchToMainQueue:^{
|
[self.doricContext dispatchToMainQueue:^{
|
||||||
__strong typeof(_self) self = _self;
|
__strong typeof(_self) self = _self;
|
||||||
NSString *viewId = params[@"id"];
|
NSString *viewId = [params optString:@"id"];
|
||||||
NSString *type = params[@"type"];
|
NSString *type = [params optString:@"type"];
|
||||||
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
|
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
|
||||||
if (!viewNode) {
|
if (!viewNode) {
|
||||||
viewNode = [[DoricViewNode create:self.doricContext withType:type] also:^(DoricViewNode *it) {
|
viewNode = [[DoricViewNode create:self.doricContext withType:type] also:^(DoricViewNode *it) {
|
||||||
@ -135,7 +135,7 @@ - (void)setRight:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
|||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
[viewNode blend:params[@"props"]];
|
[viewNode blend:[params optObject:@"props"]];
|
||||||
[self.doricContext.navBar doric_navBar_setRight:viewNode.view];
|
[self.doricContext.navBar doric_navBar_setRight:viewNode.view];
|
||||||
[promise resolve:nil];
|
[promise resolve:nil];
|
||||||
}];
|
}];
|
||||||
@ -149,8 +149,8 @@ - (void)setCenter:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
|||||||
__weak typeof(self) _self = self;
|
__weak typeof(self) _self = self;
|
||||||
[self.doricContext dispatchToMainQueue:^{
|
[self.doricContext dispatchToMainQueue:^{
|
||||||
__strong typeof(_self) self = _self;
|
__strong typeof(_self) self = _self;
|
||||||
NSString *viewId = params[@"id"];
|
NSString *viewId = [params optString:@"id"];
|
||||||
NSString *type = params[@"type"];
|
NSString *type = [params optString:@"type"];
|
||||||
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
|
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
|
||||||
if (!viewNode) {
|
if (!viewNode) {
|
||||||
viewNode = [[DoricViewNode create:self.doricContext withType:type] also:^(DoricViewNode *it) {
|
viewNode = [[DoricViewNode create:self.doricContext withType:type] also:^(DoricViewNode *it) {
|
||||||
@ -167,7 +167,7 @@ - (void)setCenter:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
|||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
[viewNode blend:params[@"props"]];
|
[viewNode blend:[params optObject:@"props"]];
|
||||||
[self.doricContext.navBar doric_navBar_setCenter:viewNode.view];
|
[self.doricContext.navBar doric_navBar_setCenter:viewNode.view];
|
||||||
[promise resolve:nil];
|
[promise resolve:nil];
|
||||||
}];
|
}];
|
||||||
|
@ -17,8 +17,9 @@
|
|||||||
// Created by pengfei.zhou on 2019/11/23.
|
// Created by pengfei.zhou on 2019/11/23.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#import <DoricCore/Doric.h>
|
||||||
#import "DoricNavigatorPlugin.h"
|
#import "DoricNavigatorPlugin.h"
|
||||||
|
#import "DoricExtensions.h"
|
||||||
|
|
||||||
@implementation DoricNavigatorPlugin
|
@implementation DoricNavigatorPlugin
|
||||||
- (void)push:(NSDictionary *)params {
|
- (void)push:(NSDictionary *)params {
|
||||||
@ -26,17 +27,12 @@ - (void)push:(NSDictionary *)params {
|
|||||||
[self.doricContext dispatchToMainQueue:^{
|
[self.doricContext dispatchToMainQueue:^{
|
||||||
__strong typeof(_self) self = _self;
|
__strong typeof(_self) self = _self;
|
||||||
BOOL animated = YES;
|
BOOL animated = YES;
|
||||||
NSString *source = params[@"source"];
|
NSString *source = [params optString:@"source"];
|
||||||
NSString *alias = source;
|
NSString *alias = source;
|
||||||
NSDictionary *config = params[@"config"];
|
NSDictionary *config = [params optObject:@"config"];
|
||||||
if (config) {
|
if (config) {
|
||||||
if (config[@"animated"]) {
|
animated = [config optBool:@"animated" defaultValue:animated];
|
||||||
animated = [config[@"animated"] boolValue];
|
alias = [config optString:@"alias" defaultValue:source];
|
||||||
}
|
|
||||||
|
|
||||||
if (config[@"alias"]) {
|
|
||||||
alias = config[@"alias"];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
[self.doricContext.navigator doric_navigator_push:source alias:alias animated:animated extra:config[@"extra"]];
|
[self.doricContext.navigator doric_navigator_push:source alias:alias animated:animated extra:config[@"extra"]];
|
||||||
}];
|
}];
|
||||||
@ -46,10 +42,7 @@ - (void)pop:(NSDictionary *)params {
|
|||||||
__weak typeof(self) _self = self;
|
__weak typeof(self) _self = self;
|
||||||
[self.doricContext dispatchToMainQueue:^{
|
[self.doricContext dispatchToMainQueue:^{
|
||||||
__strong typeof(_self) self = _self;
|
__strong typeof(_self) self = _self;
|
||||||
BOOL animated = YES;
|
BOOL animated = [params optBool:@"animated" defaultValue:YES];
|
||||||
if (params[@"animated"]) {
|
|
||||||
animated = [params[@"animated"] boolValue];
|
|
||||||
}
|
|
||||||
[self.doricContext.navigator doric_navigator_pop:animated];
|
[self.doricContext.navigator doric_navigator_pop:animated];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
@ -17,16 +17,17 @@
|
|||||||
// Created by pengfei.zhou on 2019/11/21.
|
// Created by pengfei.zhou on 2019/11/21.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#import <DoricCore/Doric.h>
|
||||||
#import "DoricNetworkPlugin.h"
|
#import "DoricNetworkPlugin.h"
|
||||||
|
#import "DoricExtensions.h"
|
||||||
|
|
||||||
@implementation DoricNetworkPlugin
|
@implementation DoricNetworkPlugin
|
||||||
- (void)request:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
|
- (void)request:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
|
||||||
NSString *url = dic[@"url"];
|
NSString *url = [dic optString:@"url"];
|
||||||
NSString *method = dic[@"method"];
|
NSString *method = [dic optString:@"method"];
|
||||||
NSDictionary <NSString *, NSString *> *headers = dic[@"headers"];
|
NSDictionary <NSString *, NSString *> *headers = [dic optObject:@"headers"];
|
||||||
NSNumber *timeout = dic[@"timeout"];
|
NSNumber *timeout = [dic optNumber:@"timeout"];
|
||||||
NSString *data = dic[@"data"];
|
NSString *data = [dic optString:@"data"];
|
||||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
|
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
|
||||||
request.HTTPMethod = method.uppercaseString;
|
request.HTTPMethod = method.uppercaseString;
|
||||||
if (timeout) {
|
if (timeout) {
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
// Created by pengfei.zhou on 2020/1/8.
|
// Created by pengfei.zhou on 2020/1/8.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#import <DoricCore/Doric.h>
|
||||||
|
#import <DoricCore/DoricCore-umbrella.h>
|
||||||
#import "DoricNotificationPlugin.h"
|
#import "DoricNotificationPlugin.h"
|
||||||
|
|
||||||
@interface DoricNotificationPlugin ()
|
@interface DoricNotificationPlugin ()
|
||||||
@ -34,12 +36,12 @@ - (NSDictionary *)observers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)publish:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
|
- (void)publish:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
|
||||||
NSString *biz = dic[@"biz"];
|
NSString *biz = [dic optString:@"biz"];
|
||||||
NSString *name = dic[@"name"];
|
NSString *name = [dic optString:@"name"];
|
||||||
if (biz) {
|
if (biz) {
|
||||||
name = [NSString stringWithFormat:@"__doric__%@#%@", biz, name];
|
name = [NSString stringWithFormat:@"__doric__%@#%@", biz, name];
|
||||||
}
|
}
|
||||||
NSString *data = dic[@"data"];
|
NSString *data = [dic optString:@"data"];
|
||||||
NSDictionary *dataDic = nil;
|
NSDictionary *dataDic = nil;
|
||||||
if (data) {
|
if (data) {
|
||||||
NSData *jsonData = [data dataUsingEncoding:NSUTF8StringEncoding];
|
NSData *jsonData = [data dataUsingEncoding:NSUTF8StringEncoding];
|
||||||
@ -53,12 +55,12 @@ - (void)publish:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)subscribe:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
|
- (void)subscribe:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
|
||||||
NSString *biz = dic[@"biz"];
|
NSString *biz = [dic optString:@"biz"];
|
||||||
NSString *name = dic[@"name"];
|
NSString *name = [dic optString:@"name"];
|
||||||
if (biz) {
|
if (biz) {
|
||||||
name = [NSString stringWithFormat:@"__doric__%@#%@", biz, name];
|
name = [NSString stringWithFormat:@"__doric__%@#%@", biz, name];
|
||||||
}
|
}
|
||||||
NSString *callbackId = dic[@"callback"];
|
NSString *callbackId = [dic optString:@"callback"];
|
||||||
__weak typeof(self) _self = self;
|
__weak typeof(self) _self = self;
|
||||||
id observer = [[NSNotificationCenter defaultCenter]
|
id observer = [[NSNotificationCenter defaultCenter]
|
||||||
addObserverForName:name
|
addObserverForName:name
|
||||||
|
@ -32,8 +32,8 @@ - (void)show:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
|||||||
}
|
}
|
||||||
[superView bringSubviewToFront:self.fullScreenView];
|
[superView bringSubviewToFront:self.fullScreenView];
|
||||||
self.fullScreenView.hidden = NO;
|
self.fullScreenView.hidden = NO;
|
||||||
NSString *viewId = params[@"id"];
|
NSString *viewId = [params optString:@"id"];
|
||||||
NSString *type = params[@"type"];
|
NSString *type = [params optString:@"type"];
|
||||||
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
|
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
|
||||||
if (!viewNode) {
|
if (!viewNode) {
|
||||||
viewNode = [[DoricViewNode create:self.doricContext withType:type] also:^(DoricViewNode *it) {
|
viewNode = [[DoricViewNode create:self.doricContext withType:type] also:^(DoricViewNode *it) {
|
||||||
@ -51,14 +51,14 @@ - (void)show:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
|||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
[viewNode blend:params[@"props"]];
|
[viewNode blend:[params optObject:@"props"]];
|
||||||
[self.fullScreenView.doricLayout apply];
|
[self.fullScreenView.doricLayout apply];
|
||||||
[promise resolve:nil];
|
[promise resolve:nil];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dismiss:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
- (void)dismiss:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
||||||
NSString *viewId = params[@"id"];
|
NSString *viewId = [params optString:@"id"];
|
||||||
__weak typeof(self) _self = self;
|
__weak typeof(self) _self = self;
|
||||||
[self.doricContext dispatchToMainQueue:^{
|
[self.doricContext dispatchToMainQueue:^{
|
||||||
__strong typeof(_self) self = _self;
|
__strong typeof(_self) self = _self;
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#import "DoricShaderPlugin.h"
|
#import "DoricShaderPlugin.h"
|
||||||
#import "DoricRootNode.h"
|
#import "DoricRootNode.h"
|
||||||
#import "DoricUtil.h"
|
#import "DoricUtil.h"
|
||||||
|
#import "DoricExtensions.h"
|
||||||
|
|
||||||
#import <objc/runtime.h>
|
#import <objc/runtime.h>
|
||||||
|
|
||||||
@ -38,15 +39,15 @@ - (void)render:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
|||||||
if (self.doricContext == nil) {
|
if (self.doricContext == nil) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
NSString *viewId = argument[@"id"];
|
NSString *viewId = [argument optString:@"id"];
|
||||||
|
|
||||||
if (self.doricContext.rootNode.viewId == nil && [@"Root" isEqualToString:argument[@"type"]]) {
|
if (self.doricContext.rootNode.viewId == nil && [@"Root" isEqualToString:[argument optString:@"type"]]) {
|
||||||
self.doricContext.rootNode.viewId = viewId;
|
self.doricContext.rootNode.viewId = viewId;
|
||||||
[self.doricContext.rootNode blend:argument[@"props"]];
|
[self.doricContext.rootNode blend:[argument optObject:@"props"]];
|
||||||
[self.doricContext.rootNode requestLayout];
|
[self.doricContext.rootNode requestLayout];
|
||||||
} else {
|
} else {
|
||||||
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
|
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
|
||||||
[viewNode blend:argument[@"props"]];
|
[viewNode blend:[argument optObject:@"props"]];
|
||||||
[viewNode requestLayout];
|
[viewNode requestLayout];
|
||||||
}
|
}
|
||||||
[promise resolve:nil];
|
[promise resolve:nil];
|
||||||
@ -60,9 +61,9 @@ - (void)command:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
|||||||
if (self.doricContext == nil) {
|
if (self.doricContext == nil) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
NSArray *viewIds = argument[@"viewIds"];
|
NSArray *viewIds = [argument optArray:@"viewIds"];
|
||||||
id args = argument[@"args"];
|
id args = argument[@"args"];
|
||||||
NSString *name = argument[@"name"];
|
NSString *name = [argument optString:@"name"];
|
||||||
DoricViewNode *viewNode = nil;
|
DoricViewNode *viewNode = nil;
|
||||||
for (NSString *viewId in viewIds) {
|
for (NSString *viewId in viewIds) {
|
||||||
if (!viewNode) {
|
if (!viewNode) {
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
#import "DoricStatusBarPlugin.h"
|
#import "DoricStatusBarPlugin.h"
|
||||||
#import "DoricUtil.h"
|
#import "DoricUtil.h"
|
||||||
#import "DoricViewNode.h"
|
|
||||||
#import "DoricExtensions.h"
|
#import "DoricExtensions.h"
|
||||||
#import "DoricViewController.h"
|
#import "DoricViewController.h"
|
||||||
|
|
||||||
@ -32,7 +31,7 @@ - (void)setHidden:(NSDictionary *)param withPromise:(DoricPromise *)promise {
|
|||||||
if (self.doricContext.navBar) {
|
if (self.doricContext.navBar) {
|
||||||
if ([self.doricContext.navBar isKindOfClass:DoricViewController.class]) {
|
if ([self.doricContext.navBar isKindOfClass:DoricViewController.class]) {
|
||||||
DoricViewController *target = ((DoricViewController *) self.doricContext.navBar);
|
DoricViewController *target = ((DoricViewController *) self.doricContext.navBar);
|
||||||
target.statusBarHidden = [param[@"hidden"] boolValue];
|
target.statusBarHidden = [param optBool:@"hidden"];
|
||||||
[target setNeedsStatusBarAppearanceUpdate];
|
[target setNeedsStatusBarAppearanceUpdate];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,7 +45,7 @@ - (void)setMode:(NSDictionary *)param withPromise:(DoricPromise *)promise {
|
|||||||
if (self.doricContext.navBar) {
|
if (self.doricContext.navBar) {
|
||||||
if ([self.doricContext.navBar isKindOfClass:DoricViewController.class]) {
|
if ([self.doricContext.navBar isKindOfClass:DoricViewController.class]) {
|
||||||
DoricViewController *target = ((DoricViewController *) self.doricContext.navBar);
|
DoricViewController *target = ((DoricViewController *) self.doricContext.navBar);
|
||||||
target.statusBarMode = [param[@"mode"] intValue];
|
target.statusBarMode = [[param optNumber:@"mode"] intValue];
|
||||||
[target setNeedsStatusBarAppearanceUpdate];
|
[target setNeedsStatusBarAppearanceUpdate];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,7 +57,7 @@ - (void)setColor:(NSDictionary *)param withPromise:(DoricPromise *)promise {
|
|||||||
[self.doricContext dispatchToMainQueue:^{
|
[self.doricContext dispatchToMainQueue:^{
|
||||||
__strong typeof(_self) self = _self;
|
__strong typeof(_self) self = _self;
|
||||||
if (self.doricContext.navBar) {
|
if (self.doricContext.navBar) {
|
||||||
UIColor *color = DoricColor(param[@"color"]);
|
UIColor *color = DoricColor([param optNumber:@"color"]);
|
||||||
[self.doricContext.navBar doric_navBar_setBackgroundColor:color];
|
[self.doricContext.navBar doric_navBar_setBackgroundColor:color];
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
#if __has_include(<PINCache/PINCache.h>)
|
#if __has_include(<PINCache/PINCache.h>)
|
||||||
|
|
||||||
#import <PINCache/PINCache.h>
|
#import <PINCache/PINCache.h>
|
||||||
|
#import <DoricCore/Doric.h>
|
||||||
|
#import <DoricCore/DoricCore-umbrella.h>
|
||||||
|
|
||||||
#define DoricCache PINCache
|
#define DoricCache PINCache
|
||||||
|
|
||||||
@ -161,9 +163,9 @@ - (DoricCache *)getDiskCache:(NSString *)zone {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)setItem:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
- (void)setItem:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
||||||
NSString *zone = argument[@"zone"];
|
NSString *zone = [argument optString:@"zone"];
|
||||||
NSString *key = argument[@"key"];
|
NSString *key = [argument optString:@"key"];
|
||||||
NSString *value = argument[@"value"];
|
NSString *value = [argument optString:@"value"];
|
||||||
DoricCache *diskCache = [self getDiskCache:zone];
|
DoricCache *diskCache = [self getDiskCache:zone];
|
||||||
[diskCache setObject:value forKey:key withBlock:^{
|
[diskCache setObject:value forKey:key withBlock:^{
|
||||||
[promise resolve:nil];
|
[promise resolve:nil];
|
||||||
@ -171,8 +173,8 @@ - (void)setItem:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)getItem:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
- (void)getItem:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
||||||
NSString *zone = argument[@"zone"];
|
NSString *zone = [argument optString:@"zone"];
|
||||||
NSString *key = argument[@"key"];
|
NSString *key = [argument optString:@"key"];
|
||||||
DoricCache *diskCache = [self getDiskCache:zone];
|
DoricCache *diskCache = [self getDiskCache:zone];
|
||||||
[diskCache objectForKey:key withBlock:^(NSString *_Nonnull key, id <NSCoding> _Nullable object) {
|
[diskCache objectForKey:key withBlock:^(NSString *_Nonnull key, id <NSCoding> _Nullable object) {
|
||||||
[promise resolve:object];
|
[promise resolve:object];
|
||||||
@ -180,8 +182,8 @@ - (void)getItem:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)remove:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
- (void)remove:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
||||||
NSString *zone = argument[@"zone"];
|
NSString *zone = [argument optString:@"zone"];
|
||||||
NSString *key = argument[@"key"];
|
NSString *key = [argument optString:@"key"];
|
||||||
DoricCache *diskCache = [self getDiskCache:zone];
|
DoricCache *diskCache = [self getDiskCache:zone];
|
||||||
[diskCache removeObjectForKey:key withBlock:^(NSString *key) {
|
[diskCache removeObjectForKey:key withBlock:^(NSString *key) {
|
||||||
[promise resolve:nil];
|
[promise resolve:nil];
|
||||||
@ -189,7 +191,7 @@ - (void)remove:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)clear:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
- (void)clear:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
||||||
NSString *zone = argument[@"zone"];
|
NSString *zone = [argument optString:@"zone"];
|
||||||
DoricCache *diskCache = [self getDiskCache:zone];
|
DoricCache *diskCache = [self getDiskCache:zone];
|
||||||
[diskCache removeAllObjectsWithBlock:^{
|
[diskCache removeAllObjectsWithBlock:^{
|
||||||
[promise resolve:nil];
|
[promise resolve:nil];
|
||||||
|
Reference in New Issue
Block a user