Skip to content

Commit

Permalink
* [ios] fix input component width calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
acton393 committed Jun 22, 2016
1 parent d31e8b6 commit ba9a3b7
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions ios/sdk/WeexSDK/Sources/Component/WXTextInputComponent.m
Expand Up @@ -285,6 +285,37 @@ - (void)updateStyles:(NSDictionary *)styles
}
}

- (CGSize (^)(CGSize))measureBlock
{
__weak typeof(self) weakSelf = self;
return ^CGSize (CGSize constrainedSize) {

CGSize computedSize = [[[NSString alloc] init]sizeWithAttributes:nil];
//TODO:more elegant way to use max and min constrained size
if (!isnan(weakSelf.cssNode->style.minDimensions[CSS_WIDTH])) {
computedSize.width = MAX(computedSize.width, weakSelf.cssNode->style.minDimensions[CSS_WIDTH]);
}

if (!isnan(weakSelf.cssNode->style.maxDimensions[CSS_WIDTH])) {
computedSize.width = MIN(computedSize.width, weakSelf.cssNode->style.maxDimensions[CSS_WIDTH]);
}

if (!isnan(weakSelf.cssNode->style.minDimensions[CSS_HEIGHT])) {
computedSize.width = MAX(computedSize.height, weakSelf.cssNode->style.minDimensions[CSS_HEIGHT]);
}

if (!isnan(weakSelf.cssNode->style.maxDimensions[CSS_HEIGHT])) {
computedSize.width = MIN(computedSize.height, weakSelf.cssNode->style.maxDimensions[CSS_HEIGHT]);
}

return (CGSize) {
WXCeilPixelValue(computedSize.width),
WXCeilPixelValue(computedSize.height)
};
};
}


#pragma mark -
#pragma mark UITextFieldDelegate

Expand Down

0 comments on commit ba9a3b7

Please sign in to comment.