iOS:Change DoricGravity enum name

This commit is contained in:
pengfei.zhou 2020-03-27 10:07:53 +08:00 committed by osborn
parent 0abf8533db
commit 438f729ec6
10 changed files with 55 additions and 55 deletions

View File

@ -95,20 +95,20 @@ - (void)sendDevCommand:(NSString *)command {
} }
- (void)onOpenEvent { - (void)onOpenEvent {
ShowToast(@"dev kit connected", BOTTOM); ShowToast(@"dev kit connected", DoricBottom);
} }
- (void)onEOFEvent { - (void)onEOFEvent {
ShowToast(@"dev kit eof exception", BOTTOM); ShowToast(@"dev kit eof exception", DoricBottom);
} }
- (void)onConnectExceptionEvent { - (void)onConnectExceptionEvent {
ShowToast(@"dev kit connection exception", BOTTOM); ShowToast(@"dev kit connection exception", DoricBottom);
} }
- (void)onStartDebugEvent:(NSNotification *)notification { - (void)onStartDebugEvent:(NSNotification *)notification {
NSString *contextId = notification.object; NSString *contextId = notification.object;
ShowToast(contextId, BOTTOM); ShowToast(contextId, DoricBottom);
for (NSValue *value in [[DoricContextManager instance] aliveContexts]) { for (NSValue *value in [[DoricContextManager instance] aliveContexts]) {
DoricContext *context = value.nonretainedObjectValue; DoricContext *context = value.nonretainedObjectValue;
BOOL result = [context.contextId compare:contextId] == NSOrderedSame; BOOL result = [context.contextId compare:contextId] == NSOrderedSame;

View File

@ -53,7 +53,7 @@ - (void)viewDidLoad {
NSString *result = @"127.0.0.1"; NSString *result = @"127.0.0.1";
[DoricJSRemoteExecutor configIp:result]; [DoricJSRemoteExecutor configIp:result];
[[DoricDev instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]]; [[DoricDev instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]];
ShowToast([NSString stringWithFormat:@"Connected to %@", result], BOTTOM); ShowToast([NSString stringWithFormat:@"Connected to %@", result], DoricBottom);
} else { } else {
[self.navigationController pushViewController:[QRScanViewController new] animated:NO]; [self.navigationController pushViewController:[QRScanViewController new] animated:NO];
} }

View File

@ -106,7 +106,7 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:
NSLog(@"Scan result is %@", result); NSLog(@"Scan result is %@", result);
[[DoricDev instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]]; [[DoricDev instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]];
[DoricJSRemoteExecutor configIp:result]; [DoricJSRemoteExecutor configIp:result];
ShowToast([NSString stringWithFormat:@"Connected to %@", result], BOTTOM); ShowToast([NSString stringWithFormat:@"Connected to %@", result], DoricBottom);
[self.navigationController popViewControllerAnimated:NO]; [self.navigationController popViewControllerAnimated:NO];
} }
} }

View File

@ -12,7 +12,7 @@ @interface DoricDemoPlugin : DoricNativePlugin
@implementation DoricDemoPlugin @implementation DoricDemoPlugin
- (void)test { - (void)test {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
ShowToast(@"Test called", CENTER); ShowToast(@"Test called", DoricCenter);
}); });
} }
@end @end

View File

@ -28,7 +28,7 @@ @implementation DoricModalPlugin
- (void)toast:(NSDictionary *)dic withPromise:(DoricPromise *)promise { - (void)toast:(NSDictionary *)dic withPromise:(DoricPromise *)promise {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
__block DoricGravity gravity = BOTTOM; __block DoricGravity gravity = DoricBottom;
[dic[@"gravity"] also:^(NSNumber *it) { [dic[@"gravity"] also:^(NSNumber *it) {
gravity = (DoricGravity) [it integerValue]; gravity = (DoricGravity) [it integerValue];
}]; }];

View File

@ -51,9 +51,9 @@ - (void)blendView:(UITextView *)view forPropName:(NSString *)name propValue:(id)
} else if ([name isEqualToString:@"textAlignment"]) { } else if ([name isEqualToString:@"textAlignment"]) {
DoricGravity gravity = (DoricGravity) [(NSNumber *) prop integerValue]; DoricGravity gravity = (DoricGravity) [(NSNumber *) prop integerValue];
NSTextAlignment alignment = NSTextAlignmentCenter; NSTextAlignment alignment = NSTextAlignmentCenter;
if ((gravity & LEFT) == LEFT) { if ((gravity & DoricGravityLeft) == DoricGravityLeft) {
alignment = NSTextAlignmentLeft; alignment = NSTextAlignmentLeft;
} else if ((gravity & RIGHT) == RIGHT) { } else if ((gravity & DoricGravityRight) == DoricGravityRight) {
alignment = NSTextAlignmentRight; alignment = NSTextAlignmentRight;
} }
view.textAlignment = alignment; view.textAlignment = alignment;

View File

@ -33,18 +33,18 @@ typedef NS_ENUM(NSInteger, DoricLayoutSpec) {
}; };
typedef NS_ENUM(NSInteger, DoricGravity) { typedef NS_ENUM(NSInteger, DoricGravity) {
SPECIFIED = 1, DoricGravitySpecified = 1,
START = 1 << 1, DoricGravityStart = 1 << 1,
END = 1 << 2, DoricGravityEnd = 1 << 2,
SHIFT_X = 0, DoricGravityShiftX = 0,
SHIFT_Y = 4, DoricGravityShiftY = 4,
LEFT = (START | SPECIFIED) << SHIFT_X, DoricGravityLeft = (DoricGravityStart | DoricGravitySpecified) << DoricGravityShiftX,
RIGHT = (END | SPECIFIED) << SHIFT_X, DoricGravityRight = (DoricGravityEnd | DoricGravitySpecified) << DoricGravityShiftX,
TOP = (START | SPECIFIED) << SHIFT_Y, DoricTOP = (DoricGravityStart | DoricGravitySpecified) << DoricGravityShiftY,
BOTTOM = (END | SPECIFIED) << SHIFT_Y, DoricBottom = (DoricGravityEnd | DoricGravitySpecified) << DoricGravityShiftY,
CENTER_X = SPECIFIED << SHIFT_X, DoricCenterX = DoricGravitySpecified << DoricGravityShiftX,
CENTER_Y = SPECIFIED << SHIFT_Y, DoricCenterY = DoricGravitySpecified << DoricGravityShiftY,
CENTER = CENTER_X | CENTER_Y, DoricCenter = DoricCenterX | DoricCenterY,
}; };
@interface DoricLayoutConfig : NSObject @interface DoricLayoutConfig : NSObject

View File

@ -255,22 +255,22 @@ - (void)layoutSelf:(CGSize)targetSize {
DoricGravity gravity = childConfig.alignment; DoricGravity gravity = childConfig.alignment;
CGPoint point = child.frame.origin; CGPoint point = child.frame.origin;
if ((gravity & LEFT) == LEFT) { if ((gravity & DoricGravityLeft) == DoricGravityLeft) {
point.x = padding.left; point.x = padding.left;
} else if ((gravity & RIGHT) == RIGHT) { } else if ((gravity & DoricGravityRight) == DoricGravityRight) {
point.x = targetSize.width - padding.right - child.width; point.x = targetSize.width - padding.right - child.width;
} else if ((gravity & CENTER_X) == CENTER_X) { } else if ((gravity & DoricCenterX) == DoricCenterX) {
point.x = targetSize.width / 2 - child.width / 2; point.x = targetSize.width / 2 - child.width / 2;
} else { } else {
if (childConfig.margin.left || childConfig.margin.right) { if (childConfig.margin.left || childConfig.margin.right) {
point.x = padding.left; point.x = padding.left;
} }
} }
if ((gravity & TOP) == TOP) { if ((gravity & DoricTOP) == DoricTOP) {
point.y = padding.top; point.y = padding.top;
} else if ((gravity & BOTTOM) == BOTTOM) { } else if ((gravity & DoricBottom) == DoricBottom) {
point.y = targetSize.height - padding.bottom - child.height; point.y = targetSize.height - padding.bottom - child.height;
} else if ((gravity & CENTER_Y) == CENTER_Y) { } else if ((gravity & DoricCenterY) == DoricCenterY) {
point.y = targetSize.height / 2 - child.height / 2; point.y = targetSize.height / 2 - child.height / 2;
} else { } else {
if (childConfig.margin.top || childConfig.margin.bottom) { if (childConfig.margin.top || childConfig.margin.bottom) {
@ -279,18 +279,18 @@ - (void)layoutSelf:(CGSize)targetSize {
} }
if (!gravity) { if (!gravity) {
gravity = LEFT | TOP; gravity = DoricGravityLeft | DoricTOP;
} }
if (childConfig.margin.left && !((gravity & RIGHT) == RIGHT)) { if (childConfig.margin.left && !((gravity & DoricGravityRight) == DoricGravityRight)) {
point.x += childConfig.margin.left; point.x += childConfig.margin.left;
} }
if (childConfig.margin.right && !((gravity & LEFT) == LEFT)) { if (childConfig.margin.right && !((gravity & DoricGravityLeft) == DoricGravityLeft)) {
point.x -= childConfig.margin.right; point.x -= childConfig.margin.right;
} }
if (childConfig.margin.top && !((gravity & BOTTOM) == BOTTOM)) { if (childConfig.margin.top && !((gravity & DoricBottom) == DoricBottom)) {
point.y += childConfig.margin.top; point.y += childConfig.margin.top;
} }
if (childConfig.margin.bottom && !((gravity & TOP) == TOP)) { if (childConfig.margin.bottom && !((gravity & DoricTOP) == DoricTOP)) {
point.y -= childConfig.margin.bottom; point.y -= childConfig.margin.bottom;
} }
if (point.x != child.x) { if (point.x != child.x) {
@ -345,11 +345,11 @@ - (void)layoutSelf:(CGSize)targetSize {
self.height = targetSize.height; self.height = targetSize.height;
DoricPadding padding = self.padding; DoricPadding padding = self.padding;
CGFloat yStart = padding.top; CGFloat yStart = padding.top;
if ((self.gravity & TOP) == TOP) { if ((self.gravity & DoricTOP) == DoricTOP) {
yStart = padding.top; yStart = padding.top;
} else if ((self.gravity & BOTTOM) == BOTTOM) { } else if ((self.gravity & DoricBottom) == DoricBottom) {
yStart = targetSize.height - self.contentHeight - padding.bottom; yStart = targetSize.height - self.contentHeight - padding.bottom;
} else if ((self.gravity & CENTER_Y) == CENTER_Y) { } else if ((self.gravity & DoricCenterY) == DoricCenterY) {
yStart = (targetSize.height - self.contentHeight - padding.top - padding.bottom) / 2 + padding.top; yStart = (targetSize.height - self.contentHeight - padding.top - padding.bottom) / 2 + padding.top;
} }
CGFloat remain = targetSize.height - self.contentHeight - padding.top - padding.bottom; CGFloat remain = targetSize.height - self.contentHeight - padding.top - padding.bottom;
@ -374,22 +374,22 @@ - (void)layoutSelf:(CGSize)targetSize {
[child layoutSelf:size]; [child layoutSelf:size];
DoricGravity gravity = childConfig.alignment | self.gravity; DoricGravity gravity = childConfig.alignment | self.gravity;
CGPoint point = child.frame.origin; CGPoint point = child.frame.origin;
if ((gravity & LEFT) == LEFT) { if ((gravity & DoricGravityLeft) == DoricGravityLeft) {
point.x = padding.left; point.x = padding.left;
} else if ((gravity & RIGHT) == RIGHT) { } else if ((gravity & DoricGravityRight) == DoricGravityRight) {
point.x = targetSize.width - padding.right - child.width; point.x = targetSize.width - padding.right - child.width;
} else if ((gravity & CENTER_X) == CENTER_X) { } else if ((gravity & DoricCenterX) == DoricCenterX) {
point.x = targetSize.width / 2 - child.width / 2; point.x = targetSize.width / 2 - child.width / 2;
} else { } else {
point.x = padding.left; point.x = padding.left;
} }
if (!gravity) { if (!gravity) {
gravity = LEFT; gravity = DoricGravityLeft;
} }
if (childConfig.margin.left && !((gravity & RIGHT) == RIGHT)) { if (childConfig.margin.left && !((gravity & DoricGravityRight) == DoricGravityRight)) {
point.x += childConfig.margin.left; point.x += childConfig.margin.left;
} }
if (childConfig.margin.right && !((gravity & LEFT) == LEFT)) { if (childConfig.margin.right && !((gravity & DoricGravityLeft) == DoricGravityLeft)) {
point.x -= childConfig.margin.right; point.x -= childConfig.margin.right;
} }
if (point.x != child.x) { if (point.x != child.x) {
@ -447,11 +447,11 @@ - (void)layoutSelf:(CGSize)targetSize {
self.height = targetSize.height; self.height = targetSize.height;
DoricPadding padding = self.padding; DoricPadding padding = self.padding;
CGFloat xStart = padding.left; CGFloat xStart = padding.left;
if ((self.gravity & LEFT) == LEFT) { if ((self.gravity & DoricGravityLeft) == DoricGravityLeft) {
xStart = padding.left; xStart = padding.left;
} else if ((self.gravity & RIGHT) == RIGHT) { } else if ((self.gravity & DoricGravityRight) == DoricGravityRight) {
xStart = targetSize.width - self.contentWidth - padding.right; xStart = targetSize.width - self.contentWidth - padding.right;
} else if ((self.gravity & CENTER_X) == CENTER_X) { } else if ((self.gravity & DoricCenterX) == DoricCenterX) {
xStart = (targetSize.width - self.contentWidth - padding.left - padding.right) / 2 + padding.left; xStart = (targetSize.width - self.contentWidth - padding.left - padding.right) / 2 + padding.left;
} }
CGFloat remain = targetSize.width - self.contentWidth - padding.left - padding.right; CGFloat remain = targetSize.width - self.contentWidth - padding.left - padding.right;
@ -479,22 +479,22 @@ - (void)layoutSelf:(CGSize)targetSize {
DoricGravity gravity = childConfig.alignment | self.gravity; DoricGravity gravity = childConfig.alignment | self.gravity;
CGPoint point = child.frame.origin; CGPoint point = child.frame.origin;
if ((gravity & TOP) == TOP) { if ((gravity & DoricTOP) == DoricTOP) {
point.y = padding.top; point.y = padding.top;
} else if ((gravity & BOTTOM) == BOTTOM) { } else if ((gravity & DoricBottom) == DoricBottom) {
point.y = targetSize.height - padding.bottom - child.height; point.y = targetSize.height - padding.bottom - child.height;
} else if ((gravity & CENTER_Y) == CENTER_Y) { } else if ((gravity & DoricCenterY) == DoricCenterY) {
point.y = targetSize.height / 2 - child.height / 2; point.y = targetSize.height / 2 - child.height / 2;
} else { } else {
point.y = padding.top; point.y = padding.top;
} }
if (!gravity) { if (!gravity) {
gravity = TOP; gravity = DoricTOP;
} }
if (childConfig.margin.top && !((gravity & BOTTOM) == BOTTOM)) { if (childConfig.margin.top && !((gravity & DoricBottom) == DoricBottom)) {
point.y += childConfig.margin.top; point.y += childConfig.margin.top;
} }
if (childConfig.margin.bottom && !((gravity & TOP) == TOP)) { if (childConfig.margin.bottom && !((gravity & DoricTOP) == DoricTOP)) {
point.y -= childConfig.margin.bottom; point.y -= childConfig.margin.bottom;
} }
if (point.y != child.y) { if (point.y != child.y) {

View File

@ -83,9 +83,9 @@ - (void)blendView:(UILabel *)view forPropName:(NSString *)name propValue:(id)pro
} else if ([name isEqualToString:@"textAlignment"]) { } else if ([name isEqualToString:@"textAlignment"]) {
DoricGravity gravity = (DoricGravity) [(NSNumber *) prop integerValue]; DoricGravity gravity = (DoricGravity) [(NSNumber *) prop integerValue];
NSTextAlignment alignment = NSTextAlignmentCenter; NSTextAlignment alignment = NSTextAlignmentCenter;
if ((gravity & LEFT) == LEFT) { if ((gravity & DoricGravityLeft) == DoricGravityLeft) {
alignment = NSTextAlignmentLeft; alignment = NSTextAlignmentLeft;
} else if ((gravity & RIGHT) == RIGHT) { } else if ((gravity & DoricGravityRight) == DoricGravityRight) {
alignment = NSTextAlignmentRight; alignment = NSTextAlignmentRight;
} }
if (self.paragraphStyle) { if (self.paragraphStyle) {

View File

@ -71,9 +71,9 @@ void ShowToast(NSString *text, DoricGravity gravity) {
label.height += 10; label.height += 10;
label.layer.cornerRadius = label.height / 2; label.layer.cornerRadius = label.height / 2;
label.centerX = superView.width / 2; label.centerX = superView.width / 2;
if ((gravity & BOTTOM) == BOTTOM) { if ((gravity & DoricBottom) == DoricBottom) {
label.bottom = superView.height - 20; label.bottom = superView.height - 20;
} else if ((gravity & TOP) == TOP) { } else if ((gravity & DoricTOP) == DoricTOP) {
label.top = 108; label.top = 108;
} else { } else {
label.centerY = (superView.height - 88) / 2; label.centerY = (superView.height - 88) / 2;