Skip to content

Commit

Permalink
[CherryPick] iOS Fix for #3159 (#3283)
Browse files Browse the repository at this point in the history
* "Fixes issue #3159 (#3195)""

Revert of the earlier revert in a user branch first. (This reverts commit d01f725.)

* fixes merge issue

* fixes unit test failure
  • Loading branch information
shalinijoshi19 authored and paulcam206 committed Jul 31, 2019
1 parent 4f210fa commit d482f18
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
6B268FE520CEF89100D99C1B /* (null) in Resources */ = {isa = PBXBuildFile; };
6B2D8605211143BD008DD972 /* AdaptiveCards.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B2D8604211143BD008DD972 /* AdaptiveCards.framework */; };
6B45008D22CFD63C00BC341C /* TextBlockStrechInColumnSet.json in Resources */ = {isa = PBXBuildFile; fileRef = 6B45008C22CFD63C00BC341C /* TextBlockStrechInColumnSet.json */; };
6B45008F22CFD77A00BC341C /* CustomerCard1.json in Resources */ = {isa = PBXBuildFile; fileRef = 6B45008E22CFD77900BC341C /* CustomerCard1.json */; };
6B45009122CFDF6A00BC341C /* ImageAutoInColumnSet.json in Resources */ = {isa = PBXBuildFile; fileRef = 6B45009022CFDF6A00BC341C /* ImageAutoInColumnSet.json */; };
6B45009322D3F20C00BC341C /* TextBlock.Issue.json in Resources */ = {isa = PBXBuildFile; fileRef = 6B45009222D3F20B00BC341C /* TextBlock.Issue.json */; };
6B5D23FB2124ADAC0010EB07 /* Image.ImageBaseUrl.json in Resources */ = {isa = PBXBuildFile; fileRef = 6B5D23FA2124ADAB0010EB07 /* Image.ImageBaseUrl.json */; };
Expand Down Expand Up @@ -60,7 +61,7 @@
6BC30F6721DFE8EA00B9FAAE /* Media.Sources.json in Resources */ = {isa = PBXBuildFile; fileRef = 6BC30F6521DFE8E900B9FAAE /* Media.Sources.json */; };
6BC30F6821DFE8EA00B9FAAE /* Media.json in Resources */ = {isa = PBXBuildFile; fileRef = 6BC30F6621DFE8E900B9FAAE /* Media.json */; };
6BC30F6A21DFECB400B9FAAE /* ProductVideo.json in Resources */ = {isa = PBXBuildFile; fileRef = 6BC30F6921DFECB400B9FAAE /* ProductVideo.json */; };
6BD9CD3B22F0FA3F00D800A6 /* Feedback.json in Resources */ = {isa = PBXBuildFile; fileRef = 6BD9CD3A22F0FA3F00D800A6 /* Feedback.json */; };
6BD9CD3D22F21AAD00D800A6 /* Feedback.json in Resources */ = {isa = PBXBuildFile; fileRef = 6BD9CD3C22F21AAC00D800A6 /* Feedback.json */; };
6BF339D620A665E600DA5973 /* CustomTextBlockRenderer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6BF339D420A665E600DA5973 /* CustomTextBlockRenderer.mm */; };
6BF339E320A66A3F00DA5973 /* AdaptiveCards.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6BF339E220A66A3F00DA5973 /* AdaptiveCards.framework */; };
6BF339E420A66A4D00DA5973 /* AdaptiveCards.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 6BF339E220A66A3F00DA5973 /* AdaptiveCards.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand Down Expand Up @@ -183,6 +184,7 @@
6B2630E22152CF1500ED9207 /* ColumnSet.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = ColumnSet.json; path = ../../../../samples/v1.0/Elements/ColumnSet.json; sourceTree = "<group>"; };
6B2D8604211143BD008DD972 /* AdaptiveCards.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = AdaptiveCards.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6B45008C22CFD63C00BC341C /* TextBlockStrechInColumnSet.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = TextBlockStrechInColumnSet.json; path = ../AdaptiveCards/AdaptiveCards/testcards/TextBlockStrechInColumnSet.json; sourceTree = "<group>"; };
6B45008E22CFD77900BC341C /* CustomerCard1.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = CustomerCard1.json; path = ../AdaptiveCards/AdaptiveCards/testcards/CustomerCard1.json; sourceTree = "<group>"; };
6B45009022CFDF6A00BC341C /* ImageAutoInColumnSet.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = ImageAutoInColumnSet.json; path = ../AdaptiveCards/AdaptiveCards/testcards/ImageAutoInColumnSet.json; sourceTree = "<group>"; };
6B45009222D3F20B00BC341C /* TextBlock.Issue.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = TextBlock.Issue.json; path = ../AdaptiveCards/AdaptiveCards/testcards/TextBlock.Issue.json; sourceTree = "<group>"; };
6B5D23FA2124ADAB0010EB07 /* Image.ImageBaseUrl.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = Image.ImageBaseUrl.json; path = ../../../../samples/v1.0/Elements/Image.ImageBaseUrl.json; sourceTree = "<group>"; };
Expand Down Expand Up @@ -213,7 +215,7 @@
6BC30F6521DFE8E900B9FAAE /* Media.Sources.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = Media.Sources.json; path = ../../../../samples/v1.1/Elements/Media.Sources.json; sourceTree = "<group>"; };
6BC30F6621DFE8E900B9FAAE /* Media.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = Media.json; path = ../../../../samples/v1.1/Elements/Media.json; sourceTree = "<group>"; };
6BC30F6921DFECB400B9FAAE /* ProductVideo.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = ProductVideo.json; path = ../../../../samples/v1.1/Scenarios/ProductVideo.json; sourceTree = "<group>"; };
6BD9CD3A22F0FA3F00D800A6 /* Feedback.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = Feedback.json; path = ../../../../samples/Tests/Feedback.json; sourceTree = "<group>"; };
6BD9CD3C22F21AAC00D800A6 /* Feedback.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = Feedback.json; path = ../../../../samples/Tests/Feedback.json; sourceTree = "<group>"; };
6BF339D420A665E600DA5973 /* CustomTextBlockRenderer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CustomTextBlockRenderer.mm; sourceTree = "<group>"; };
6BF339D520A665E600DA5973 /* CustomTextBlockRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomTextBlockRenderer.h; sourceTree = "<group>"; };
6BF339E220A66A3F00DA5973 /* AdaptiveCards.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = AdaptiveCards.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -436,9 +438,10 @@
F4D33E341F045B6E00941E44 /* Jsons */ = {
isa = PBXGroup;
children = (
6BD9CD3A22F0FA3F00D800A6 /* Feedback.json */,
6BD9CD3C22F21AAC00D800A6 /* Feedback.json */,
6B45009222D3F20B00BC341C /* TextBlock.Issue.json */,
6B45009022CFDF6A00BC341C /* ImageAutoInColumnSet.json */,
6B45008E22CFD77900BC341C /* CustomerCard1.json */,
6B45008C22CFD63C00BC341C /* TextBlockStrechInColumnSet.json */,
6B096D572257DA0B006CC034 /* Action.IconUrl.TwoActions.json */,
6B980944216573EF0024B79B /* Action.OpenUrl.IconUrl.json */,
Expand Down Expand Up @@ -695,7 +698,6 @@
30164559225E602A0032E11C /* AdaptiveCard.MinHeight.json in Resources */,
6BAC0F282284D52B00E42DEB /* AdaptiveCard.BackgroundImage.FillMode.RepeatHorizontally.json in Resources */,
F4933CC71F79852C00F6EBFD /* Column.Spacing.json in Resources */,
6BD9CD3B22F0FA3F00D800A6 /* Feedback.json in Resources */,
F4933CC31F79852C00F6EBFD /* Action.ShowCard.json in Resources */,
F4933CD31F79852C00F6EBFD /* FactSet.json in Resources */,
6B98094D216573F00024B79B /* VerticalContentAlignment.json in Resources */,
Expand All @@ -713,6 +715,7 @@
F4933CE61F79852C00F6EBFD /* TextBlock.HorizontalAlignment.json in Resources */,
F4933CEA1F79852C00F6EBFD /* TextBlock.Size.json in Resources */,
6B096D7822601A5A006CC034 /* ActionFallback.json in Resources */,
6B45008F22CFD77A00BC341C /* CustomerCard1.json in Resources */,
7EF887CD21FBCEF900BAFF02 /* Container.Style.json in Resources */,
F4933CEE1F79852C00F6EBFD /* TextBlock.Wrap.json in Resources */,
6B096D582257DA0C006CC034 /* Action.IconUrl.TwoActions.json in Resources */,
Expand All @@ -734,6 +737,7 @@
6BAC0F272284D52B00E42DEB /* AdaptiveCard.BackgroundImage.FillVerticalAlignment.json in Resources */,
6BAC0F262284D52B00E42DEB /* AdaptiveCard.BackgroundImage.FillMode.RepeatVertically.json in Resources */,
30860BC420C9B5C9009F9D99 /* (null) in Resources */,
6BD9CD3D22F21AAD00D800A6 /* Feedback.json in Resources */,
F4933CDF1F79852C00F6EBFD /* Input.Text.json in Resources */,
F4933CD11F79852C00F6EBFD /* Container.Spacing.json in Resources */,
F4933CCF1F79852C00F6EBFD /* Container.SelectAction.json in Resources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ - (UIView* )render:(UIView<ACRIContentHoldingView> *)viewGroup
ACOBaseCardElement *acoColumn = [[ACOBaseCardElement alloc] init];
auto firstColumn = columns.begin();
auto prevColumn = columns.empty() ? nullptr : *firstColumn;
auto lastColumn { columns.back() };
ACOFeatureRegistration *featureReg = [ACOFeatureRegistration getInstance];
ACRSeparator *separator = nil;

Expand All @@ -99,6 +100,10 @@ - (UIView* )render:(UIView<ACRIContentHoldingView> *)viewGroup
if ([acoElem meetsRequirements:featureReg] == NO) {
@throw [ACOFallbackException fallbackException];
}

if (lastColumn == column) {
columnSetView.isLastColumn = YES;
}

curView = (ACRColumnView *)[columnRenderer render:columnSetView rootView:rootView inputs:inputs baseCardElement:acoColumn hostConfig:acoConfig];
} @catch (ACOFallbackException *e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ - (void)config:(nullable NSDictionary<NSString *, id> *)attributes
- (void)addArrangedSubview:(UIView *)view
{
// if auto, maintain content size whenever possible
if([self.columnWidth isEqualToString:@"auto"]){
if([self.columnWidth isEqualToString:@"auto"]){

NSInteger priority = ACRColumnWidthPriorityAuto;
if (self.isLastColumn) {
priority = ACRColumnWidthPriorityStretchAuto;
Expand All @@ -28,6 +29,9 @@ - (void)addArrangedSubview:(UIView *)view
[view setContentHuggingPriority:priority forAxis:UILayoutConstraintAxisHorizontal];
[view setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
// if columnWidth is set to stretch or number, allow column to fill the available space
} else if([self.columnWidth isEqualToString:@"stretch"]){
[view setContentHuggingPriority:ACRColumnWidthPriorityStretch forAxis:UILayoutConstraintAxisHorizontal];
[view setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
} else {
[view setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
[view setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,7 @@ - (UIView *)render:(UIView<ACRIContentHoldingView> *)viewGroup
if (!view) {
return wrappingview;
}

if (!isAspectRatioNeeded){
view.contentMode = UIViewContentModeScaleToFill;
} else {
view.contentMode = UIViewContentModeScaleAspectFit;
}


view.clipsToBounds = YES;

std::string backgroundColor = imgElem->GetBackgroundColor();
Expand All @@ -101,33 +95,51 @@ - (UIView *)render:(UIView<ACRIContentHoldingView> *)viewGroup

[viewGroup addArrangedSubview:wrappingview];

[NSLayoutConstraint activateConstraints:
[ACOHostConfig getConstraintsForImageAlignment:imgElem->GetHorizontalAlignment()
withSuperview:wrappingview
toView:view]];

NSArray<NSString *> *visualFormats = [NSArray arrayWithObjects:@"H:[view(<=wrappingview)]", @"V:|[view(<=wrappingview)]|", nil];
NSDictionary *viewMap = NSDictionaryOfVariableBindings(view, wrappingview);
UILayoutGuide *leftGuide = nil;
UILayoutGuide *rightGuide = nil;
HorizontalAlignment adaptiveAlignment = imgElem->GetHorizontalAlignment();
if (adaptiveAlignment == HorizontalAlignment::Left) {
leftGuide = [[UILayoutGuide alloc] init];
leftGuide.identifier = @"img-left-guide";
[wrappingview addLayoutGuide:leftGuide];
[leftGuide.leadingAnchor constraintEqualToAnchor:wrappingview.leadingAnchor].active = YES;
[leftGuide.trailingAnchor constraintEqualToAnchor:view.leadingAnchor].active = YES;
[leftGuide.heightAnchor constraintEqualToAnchor:view.heightAnchor].active = YES;
[view.leadingAnchor constraintEqualToAnchor:wrappingview.leadingAnchor].active = YES;
}

for (NSString *constraint in visualFormats){
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:constraint options:0 metrics:nil views:viewMap]];
if (adaptiveAlignment == HorizontalAlignment::Right) {
rightGuide = [[UILayoutGuide alloc] init];
rightGuide.identifier = @"img-right-guide";
[wrappingview addLayoutGuide:rightGuide];
NSLayoutConstraint *constraint = [rightGuide.leadingAnchor constraintEqualToAnchor:view.trailingAnchor];
constraint.priority = 998;
constraint.active = YES;
[rightGuide.heightAnchor constraintEqualToAnchor:view.heightAnchor].active = YES;
[rightGuide.trailingAnchor constraintEqualToAnchor:wrappingview.trailingAnchor].active = YES;
[view.trailingAnchor constraintEqualToAnchor:wrappingview.trailingAnchor].active = YES;
}

if (!(size == ImageSize::Auto || size == ImageSize::Stretch)) {
[wrappingview setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[wrappingview setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
if (adaptiveAlignment == HorizontalAlignment::Center) {
[view.centerXAnchor constraintEqualToAnchor:wrappingview.centerXAnchor].active = YES;
}

[wrappingview.heightAnchor constraintGreaterThanOrEqualToAnchor:view.heightAnchor].active = YES;
[wrappingview.widthAnchor constraintGreaterThanOrEqualToAnchor:view.widthAnchor].active = YES;

[view.centerYAnchor constraintEqualToAnchor:wrappingview.centerYAnchor].active = YES;

if (!isAspectRatioNeeded){
view.contentMode = UIViewContentModeScaleToFill;
} else {
view.contentMode = UIViewContentModeScaleAspectFit;
}

if (size != ImageSize::Stretch) {
[view setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[view setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
[view setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
[view setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisVertical];
[view setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[view setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
[wrappingview setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[wrappingview setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
[wrappingview setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[wrappingview setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];

if (imgElem->GetHeight() == HeightType::Stretch) {
UIView *blankTrailingSpace = [[UIView alloc] init];
[blankTrailingSpace setContentHuggingPriority:(UILayoutPriorityDefaultLow) forAxis:UILayoutConstraintAxisVertical];
Expand Down Expand Up @@ -213,8 +225,8 @@ - (void)configUpdateForUIImageView:(ACOBaseCardElement *)acoElem config:(ACOHost
multiplier:1.0
constant:cgsize.height]];
constraints[0].priority = 1000;
constraints[1].priority = 999;

constraints[1].priority = 1000;
[NSLayoutConstraint activateConstraints:constraints];

if ([imageView class] == [ACRUIImageView class]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,6 @@ - (UIView *)render:(UIView<ACRIContentHoldingView> *)viewGroup
[viewGroup addArrangedSubview:wrappingview];
[wrappingview addSubview:lab];

NSLayoutAttribute horizontalAlignment = NSLayoutAttributeLeading;
if(txtBlck->GetHorizontalAlignment() == HorizontalAlignment::Right) {
horizontalAlignment = NSLayoutAttributeTrailing;
} else if (txtBlck->GetHorizontalAlignment() == HorizontalAlignment::Center) {
horizontalAlignment = NSLayoutAttributeCenterX;
}

[NSLayoutConstraint constraintWithItem:lab attribute:horizontalAlignment relatedBy:NSLayoutRelationEqual toItem:wrappingview attribute:horizontalAlignment multiplier:1.0 constant:0].active = YES;
[NSLayoutConstraint constraintWithItem:lab attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:wrappingview attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0].active = YES;
[NSLayoutConstraint constraintWithItem:lab attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:wrappingview attribute:NSLayoutAttributeTop multiplier:1.0 constant:0].active = YES;

lab.textContainer.maximumNumberOfLines = int(txtBlck->GetMaxLines());
if(!lab.textContainer.maximumNumberOfLines && !txtBlck->GetWrap()){
lab.textContainer.maximumNumberOfLines = 1;
Expand All @@ -122,9 +111,41 @@ - (UIView *)render:(UIView<ACRIContentHoldingView> *)viewGroup
[wrappingview setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
}

[NSLayoutConstraint constraintWithItem:wrappingview attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:lab attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0].active = YES;
[lab setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[wrappingview setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[lab setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];

UILayoutGuide *leftGuide = nil;
UILayoutGuide *rightGuide = nil;
HorizontalAlignment adaptiveAlignment = txtBlck->GetHorizontalAlignment();

if (adaptiveAlignment == HorizontalAlignment::Right) {
leftGuide = [[UILayoutGuide alloc] init];
leftGuide.identifier = @"text-left-guide";
[wrappingview addLayoutGuide:leftGuide];
[leftGuide.leadingAnchor constraintEqualToAnchor:wrappingview.leadingAnchor].active = YES;
[leftGuide.trailingAnchor constraintEqualToAnchor:lab.leadingAnchor].active = YES;
[leftGuide.heightAnchor constraintEqualToAnchor:lab.heightAnchor].active = YES;
[lab.trailingAnchor constraintEqualToAnchor:wrappingview.trailingAnchor].active = YES;
}

if (adaptiveAlignment == HorizontalAlignment::Left) {
rightGuide = [[UILayoutGuide alloc] init];
rightGuide.identifier = @"text-right-guide";
[wrappingview addLayoutGuide:rightGuide];
NSLayoutConstraint *constraint = [rightGuide.leadingAnchor constraintEqualToAnchor:lab.trailingAnchor];
constraint.active = YES;
[rightGuide.heightAnchor constraintEqualToAnchor:lab.heightAnchor].active = YES;
[rightGuide.trailingAnchor constraintEqualToAnchor:wrappingview.trailingAnchor].active = YES;
[lab.leadingAnchor constraintEqualToAnchor:wrappingview.leadingAnchor].active = YES;
}

if (adaptiveAlignment == HorizontalAlignment::Center) {
[lab.centerXAnchor constraintEqualToAnchor:wrappingview.centerXAnchor].active = YES;
}

[wrappingview.heightAnchor constraintEqualToAnchor:lab.heightAnchor].active = YES;
[wrappingview.widthAnchor constraintGreaterThanOrEqualToAnchor:lab.widthAnchor].active = YES;

[lab.centerYAnchor constraintEqualToAnchor:wrappingview.centerYAnchor].active = YES;

configVisibility(wrappingview, elem);

Expand Down

0 comments on commit d482f18

Please sign in to comment.