iOS:fix cannot change rootView's layoutconfig or size
This commit is contained in:
		| @@ -20,11 +20,19 @@ | |||||||
| #import "DoricPanel.h" | #import "DoricPanel.h" | ||||||
| #import "Doric.h" | #import "Doric.h" | ||||||
| 
 | 
 | ||||||
|  | @interface DoricPanel() | ||||||
|  | @property(nonatomic,assign) CGFloat renderedWidth; | ||||||
|  | @property(nonatomic,assign) CGFloat renderedHeight; | ||||||
|  | @end | ||||||
|  | 
 | ||||||
| @implementation DoricPanel | @implementation DoricPanel | ||||||
| 
 | 
 | ||||||
| - (void)config:(NSString *)script alias:(NSString *)alias extra:(NSString *)extra { | - (void)config:(NSString *)script alias:(NSString *)alias extra:(NSString *)extra { | ||||||
|     self.doricContext = [[[DoricContext alloc] initWithScript:script source:alias extra:extra] also:^(DoricContext *it) { |     self.doricContext = [[[DoricContext alloc] initWithScript:script source:alias extra:extra] also:^(DoricContext *it) { | ||||||
|         [it.rootNode setupRootView:[[DoricStackView new] also:^(DoricStackView *it) { |         [it.rootNode setupRootView:[[DoricStackView new] also:^(DoricStackView *it) { | ||||||
|  |             it.width = self.view.width; | ||||||
|  |             it.height = self.view.height; | ||||||
|  |             it.clipsToBounds = YES; | ||||||
|             [self.view addSubview:it]; |             [self.view addSubview:it]; | ||||||
|         }]]; |         }]]; | ||||||
|     }]; |     }]; | ||||||
| @@ -34,10 +42,10 @@ - (void)config:(NSString *)script alias:(NSString *)alias extra:(NSString *)extr | |||||||
| - (void)viewWillLayoutSubviews { | - (void)viewWillLayoutSubviews { | ||||||
|     [super viewWillLayoutSubviews]; |     [super viewWillLayoutSubviews]; | ||||||
|     [self.doricContext.rootNode.view also:^(DoricStackView *it) { |     [self.doricContext.rootNode.view also:^(DoricStackView *it) { | ||||||
|         if (it.width != self.view.width || it.height != self.view.height) { |         if (it.width != self.renderedWidth || it.height != self.renderedHeight) { | ||||||
|             it.width = self.view.width; |  | ||||||
|             it.height = self.view.height; |  | ||||||
|             [self.doricContext initContextWithWidth:it.width height:it.height]; |             [self.doricContext initContextWithWidth:it.width height:it.height]; | ||||||
|  |             self.renderedWidth = it.width; | ||||||
|  |             self.renderedHeight = it.height; | ||||||
|         } |         } | ||||||
|     }]; |     }]; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -125,7 +125,8 @@ - (void)doricLayoutSubviews { | |||||||
|     if ([self.superview requestFromSubview:self]) { |     if ([self.superview requestFromSubview:self]) { | ||||||
|         [self.superview doricLayoutSubviews]; |         [self.superview doricLayoutSubviews]; | ||||||
|     } else { |     } else { | ||||||
|         [self layoutSelf:CGSizeMake(self.width, self.height)]; |         CGSize size = [self measureSize:CGSizeMake(self.superview.width, self.superview.height)]; | ||||||
|  |         [self layoutSelf:size]; | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|   | |||||||
| @@ -378,6 +378,9 @@ - (NSDictionary *)getLocationOnScreen { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| - (void)blendLayoutConfig:(NSDictionary *)params { | - (void)blendLayoutConfig:(NSDictionary *)params { | ||||||
|  |     if (!self.layoutConfig) { | ||||||
|  |         self.view.layoutConfig = [DoricLayoutConfig new]; | ||||||
|  |     } | ||||||
|     [params[@"widthSpec"] also:^(NSNumber *it) { |     [params[@"widthSpec"] also:^(NSNumber *it) { | ||||||
|         if (it) { |         if (it) { | ||||||
|             self.layoutConfig.widthSpec = (DoricLayoutSpec) [it integerValue]; |             self.layoutConfig.widthSpec = (DoricLayoutSpec) [it integerValue]; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user