iOS view render

This commit is contained in:
pengfei.zhou
2019-07-30 19:07:46 +08:00
parent c1fde16bee
commit 5d710b5b97
6 changed files with 440 additions and 314 deletions

View File

@@ -63,7 +63,7 @@ - (void)initJSExecutor {
__strong typeof(_self) self = _self;
NSString *timerId_str = [timerId stringValue];
BOOL repeat = [isInterval boolValue];
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:[interval doubleValue]/1000 target:self selector:@selector(callbackTimer:) userInfo:@{@"timerId":timerId,@"repeat":isInterval} repeats:repeat];
NSTimer *timer = [NSTimer timerWithTimeInterval:[interval doubleValue]/1000 target:self selector:@selector(callbackTimer:) userInfo:@{@"timerId":timerId,@"repeat":isInterval} repeats:repeat];
[self.timers setValue:timer forKey:timerId_str];
dispatch_async(dispatch_get_main_queue(), ^(){
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
@@ -149,7 +149,7 @@ - (void)callbackTimer:(NSTimer *)timer {
dispatch_async(self.jsQueue, ^(){
__strong typeof(_self) self = _self;
@try {
[self invokeDoricMethod:DORIC_TIMER_CALLBACK, [timerId longValue], nil];
[self invokeDoricMethod:DORIC_TIMER_CALLBACK, timerId, nil];
} @catch (NSException *exception) {
DoricLog(@"Timer Callback error:%@", exception.reason);
}

View File

@@ -0,0 +1,67 @@
//
// DoricViewContainer.h
// Doric
//
// Created by pengfei.zhou on 2019/7/30.
//
#import "UIView+Doric.h"
#define LAYOUT_MATCH_PARENT -1
#define LAYOUT_WRAP_CONTENT -2
typedef NS_ENUM(NSInteger,DoricGravity) {
SPECIFIED = 1,
START = 1 << 1,
END = 1 << 2,
SHIFT_X = 0,
SHIFT_Y = 4,
LEFT = (START | SPECIFIED) << SHIFT_X,
RIGHT = (END | SPECIFIED) << SHIFT_X,
TOP = (START | SPECIFIED) << SHIFT_Y,
BOTTOM = (END | SPECIFIED) << SHIFT_Y,
CENTER_X = SPECIFIED << SHIFT_X,
CENTER_Y = SPECIFIED << SHIFT_Y,
CENTER = CENTER_X | CENTER_Y,
};
NS_ASSUME_NONNULL_BEGIN
@interface DoricRect :NSObject
@property (nonatomic) CGFloat left;
@property (nonatomic) CGFloat right;
@property (nonatomic) CGFloat top;
@property (nonatomic) CGFloat bottom;
@end
@interface LayoutParams : NSObject
@property (nonatomic) DoricGravity alignment;
@property (nonatomic,strong) DoricRect *margin;
@end
@interface UIView(DoricContainer)
@property (nonatomic,strong) LayoutParams *layoutParams;
- (void) layout;
- (void) measure;
@end
@interface Stack : UIView
@property (nonatomic) DoricGravity gravity;
@end
@interface VLayout : UIView
@property (nonatomic) DoricGravity gravity;
@property (nonatomic) CGFloat space;
@end
@interface HLayout : UIView
@property (nonatomic) DoricGravity gravity;
@property (nonatomic) CGFloat space;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,49 @@
//
// DoricViewContainer.m
// Doric
//
// Created by pengfei.zhou on 2019/7/30.
//
#import "DoricViewContainer.h"
#import <objc/runtime.h>
@implementation DoricRect
@end
@implementation LayoutParams
@end
@implementation UIView(DoricContainer)
- (LayoutParams *)layoutParams {
return objc_getAssociatedObject(self, _cmd);
}
- (void)setLayoutParams:(LayoutParams *)layoutParams {
objc_setAssociatedObject(self, @selector(layoutParams), layoutParams, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (void)layout {
}
- (void)measure {
if(self.layoutParams) {
}
}
@end
@implementation Stack
@end
@implementation VLayout
@end
@implementation HLayout
@end