iOS:Fix onFrameChangedCallback not functional right
This commit is contained in:
parent
2f0f0494df
commit
050dfc46ae
@ -29,10 +29,21 @@ @implementation DoricPanel
|
||||
|
||||
- (void)config:(NSString *)script alias:(NSString *)alias extra:(NSString *)extra {
|
||||
self.doricContext = [[[DoricContext alloc] initWithScript:script source:alias extra:extra] also:^(DoricContext *it) {
|
||||
[it.rootNode setupRootView:[[DoricStackView new] also:^(DoricStackView *it) {
|
||||
[it.rootNode setupRootView:[[DoricRootView new] also:^(DoricRootView *it) {
|
||||
it.width = self.view.width;
|
||||
it.height = self.view.height;
|
||||
it.clipsToBounds = YES;
|
||||
__weak typeof(self) __self = self;
|
||||
it.frameChangedBlock = ^(CGSize oldSize, CGSize newSize) {
|
||||
__strong typeof(__self) self = __self;
|
||||
self.renderedWidth = newSize.width;
|
||||
self.renderedHeight = newSize.height;
|
||||
self.view.width = newSize.width;
|
||||
self.view.height = newSize.height;
|
||||
if (self.frameChangedBlock) {
|
||||
self.frameChangedBlock(newSize);
|
||||
}
|
||||
};
|
||||
[self.view addSubview:it];
|
||||
}]];
|
||||
}];
|
||||
@ -41,21 +52,10 @@ - (void)config:(NSString *)script alias:(NSString *)alias extra:(NSString *)extr
|
||||
|
||||
- (void)viewWillLayoutSubviews {
|
||||
[super viewWillLayoutSubviews];
|
||||
if (self.doricContext && self.renderedWidth != self.view.width && self.renderedHeight != self.view.height) {
|
||||
if (self.doricContext && (self.renderedWidth != self.view.width || self.renderedHeight != self.view.height)) {
|
||||
self.renderedWidth = self.view.width;
|
||||
self.renderedHeight = self.view.height;
|
||||
[self.doricContext build:CGSizeMake(self.renderedWidth, self.renderedHeight)];
|
||||
} else {
|
||||
[self.doricContext.rootNode.view also:^(DoricStackView *it) {
|
||||
if (it.width != self.renderedWidth || it.height != self.renderedHeight) {
|
||||
// Frame changed
|
||||
self.renderedWidth = self.view.width = it.width;
|
||||
self.renderedHeight = self.view.height = it.height;
|
||||
if (self.frameChangedBlock) {
|
||||
self.frameChangedBlock(CGSizeMake(it.width, it.height));
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,9 +48,9 @@ - (instancetype)initWithSource:(NSString *)source alias:(NSString *)alias extra:
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
self.view.backgroundColor = [UIColor whiteColor];
|
||||
self.doricPanel = [[DoricPanel new] also:^(DoricPanel *it) {
|
||||
[it.view also:^(UIView *it) {
|
||||
it.backgroundColor = [UIColor whiteColor];
|
||||
it.width = self.view.width;
|
||||
it.height = self.view.height;
|
||||
}];
|
||||
@ -99,12 +99,6 @@ - (void)viewWillDisappear:(BOOL)animated {
|
||||
}
|
||||
}
|
||||
|
||||
- (void)viewWillLayoutSubviews {
|
||||
[super viewWillLayoutSubviews];
|
||||
self.doricPanel.view.width = self.view.width;
|
||||
self.doricPanel.view.height = self.view.height;
|
||||
}
|
||||
|
||||
- (void)doric_navigator_push:(NSString *)source alias:(NSString *)alias animated:(BOOL)animated extra:(NSString *)extra {
|
||||
DoricViewController *viewController = [[DoricViewController alloc] initWithSource:source alias:alias extra:extra];
|
||||
[self.navigationController pushViewController:viewController animated:animated];
|
||||
|
@ -22,12 +22,12 @@
|
||||
|
||||
#import "DoricStackNode.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
@interface DoricRootView : DoricStackView
|
||||
@property(nonatomic, strong) void (^frameChangedBlock)(CGSize oldSize, CGSize newSize);
|
||||
@end
|
||||
|
||||
@interface DoricRootNode : DoricStackNode
|
||||
|
||||
- (void)setupRootView:(DoricStackView *)view;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@ -22,6 +22,37 @@
|
||||
|
||||
#import "DoricRootNode.h"
|
||||
|
||||
@interface DoricRootView ()
|
||||
@property(nonatomic, assign) CGSize currentSize;
|
||||
@end
|
||||
|
||||
@implementation DoricRootView
|
||||
|
||||
- (instancetype)init {
|
||||
if (self = [super init]) {
|
||||
_currentSize = self.frame.size;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)layoutSelf:(CGSize)targetSize {
|
||||
[super layoutSelf:targetSize];
|
||||
if (!CGSizeEqualToSize(self.currentSize, targetSize) && self.frameChangedBlock) {
|
||||
self.frameChangedBlock(self.currentSize, targetSize);
|
||||
}
|
||||
self.currentSize = targetSize;
|
||||
}
|
||||
|
||||
- (void)setX:(CGFloat)x {
|
||||
self.superview.x = x;
|
||||
}
|
||||
|
||||
- (void)setY:(CGFloat)y {
|
||||
self.superview.y = y;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation DoricRootNode
|
||||
- (void)setupRootView:(DoricStackView *)view {
|
||||
self.view = view;
|
||||
|
Reference in New Issue
Block a user