Skip to content

Commit 013b139

Browse files
authored
Fixed #6220 (#6234)
* [iOS] Fixed #6219 * Updated sample card * [iOS] Fixes 6222 * [iOS] Fixed #6220 * [iOS] added accessors
1 parent 3383b81 commit 013b139

File tree

10 files changed

+59
-28
lines changed

10 files changed

+59
-28
lines changed

samples/v1.2/Scenarios/FlightDetails.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"altText": "Departing airplane"
1919
}
2020
],
21-
"bleed": true
21+
"bleed": true,
22+
"style": "emphasis"
2223
},
2324
{
2425
"type": "Container",

source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRColumnRenderer.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ - (UIView *)render:(UIView<ACRIContentHoldingView> *)viewGroup
4646

4747
column.rtl = rootView.context.rtl;
4848

49-
renderBackgroundImage(columnElem->GetBackgroundImage(), column, rootView);
50-
5149
column.pixelWidth = columnElem->GetPixelWidth();
5250
auto width = columnElem->GetWidth();
5351
if (width.empty() || width == "stretch") {
@@ -136,6 +134,8 @@ - (UIView *)render:(UIView<ACRIContentHoldingView> *)viewGroup
136134
// viewGroup and column has to be in view hierarchy before configBleed is called
137135
configBleed(rootView, elem, column, acoConfig, viewGroup);
138136

137+
renderBackgroundImage(columnElem->GetBackgroundImage(), column, rootView);
138+
139139
[rootView.context popBaseCardElementContext:acoElem];
140140

141141
column.accessibilityElements = [column getArrangedSubviews];

source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRContentHoldingUIView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const extern NSInteger eACRUIImageTag;
1919
@property BOOL isPersonStyle;
2020
@property BOOL hidePlayIcon;
2121
@property BOOL isMediaType;
22+
@property (weak, readonly) UIView *contentView;
2223

2324
- (instancetype)initWithImageProperties:(ACRImageProperties *)imageProperties imageView:(UIImageView *)imageView viewGroup:(ACRContentStackView *)viewGroup;
2425
- (void)update:(ACRImageProperties *)imageProperties;

source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRContentHoldingUIView.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ - (instancetype)initWithImageProperties:(ACRImageProperties *)imageProperties im
4141
_imageView = imageView;
4242
_viewGroup = viewGroup;
4343
[self addSubview:imageView];
44+
_contentView = imageView;
4445
}
4546

4647
return self;

source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRContentStackView.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ - (void)layoutSubviews
477477
if ([self.subviews count]) {
478478
// configures background when this view contains a background image, and does only once
479479
NSMutableArray<NSLayoutConstraint *> *constraints = [[NSMutableArray alloc] init];
480-
renderBackgroundCoverMode(self.subviews[0], self, constraints);
480+
renderBackgroundCoverMode(self.subviews[0], self.backgroundView, constraints, self);
481481
[NSLayoutConstraint activateConstraints:constraints];
482482
}
483483

source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRShowCardTarget.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ - (IBAction)toggleVisibilityOfShowCard
119119
if (hidden) {
120120
if ([_adcView.subviews count] > 1) {
121121
NSMutableArray<NSLayoutConstraint *> *constraints = [[NSMutableArray alloc] init];
122-
renderBackgroundCoverMode(_adcView.subviews[1], _adcView, constraints);
122+
renderBackgroundCoverMode(_adcView.subviews[1], _adcView.backgroundView, constraints, _adcView);
123123
[NSLayoutConstraint activateConstraints:constraints];
124124
}
125125
}

source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/UtiliOS.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void renderBackgroundImage(ACRView *rootView, const BackgroundImage *backgroundI
5050
void applyBackgroundImageConstraints(const BackgroundImage *backgroundImageProperties,
5151
UIImageView *imageView, UIImage *img);
5252

53-
void renderBackgroundCoverMode(UIView *backgroundView, ACRContentStackView *targetView, NSMutableArray<NSLayoutConstraint *> *constraints);
53+
void renderBackgroundCoverMode(UIView *backgroundView, UIView *targetView, NSMutableArray<NSLayoutConstraint *> *constraints, ACRContentStackView *parentView);
5454

5555
void configHorizontalAlignmentConstraintsForBackgroundImageView(const BackgroundImage *backgroundImageProperties, UIView *superView, UIImageView *imageView, NSMutableArray<NSLayoutConstraint *> *constraints);
5656

source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/UtiliOS.mm

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,13 @@ void renderBackgroundImage(ACRView *rootView, const BackgroundImage *backgroundI
163163

164164
// apply contraints for 'Cover' fill mode
165165
// the backgroundView is set on the targetView
166-
void renderBackgroundCoverMode(UIView *backgroundView, ACRContentStackView *targetView, NSMutableArray<NSLayoutConstraint *> *constraints)
166+
void renderBackgroundCoverMode(UIView *backgroundView, UIView *targetView, NSMutableArray<NSLayoutConstraint *> *constraints, ACRContentStackView *parentView)
167167
{
168-
if (!backgroundView || !targetView || ![backgroundView isKindOfClass:[UIImageView class]] || targetView.isBackgroundImageSet) {
168+
if (!targetView) {
169+
targetView = parentView;
170+
}
171+
172+
if (!backgroundView || !targetView || ![backgroundView isKindOfClass:[UIImageView class]] || parentView.isBackgroundImageSet) {
169173
return;
170174
}
171175

@@ -176,7 +180,7 @@ void renderBackgroundCoverMode(UIView *backgroundView, ACRContentStackView *targ
176180
return;
177181
}
178182

179-
targetView.isBackgroundImageSet = YES;
183+
parentView.isBackgroundImageSet = YES;
180184

181185
imageView.contentMode = UIViewContentModeScaleAspectFill;
182186
// Fill Mode Description
@@ -227,35 +231,46 @@ void applyBackgroundImageConstraints(const BackgroundImage *backgroundImagePrope
227231
return;
228232
}
229233

234+
UIView *backgroundView = nil;
235+
if ([superView isKindOfClass:[ACRContentStackView class]]) {
236+
backgroundView = ((ACRContentStackView *)superView).backgroundView;
237+
if (backgroundView) {
238+
[imageView removeFromSuperview];
239+
[backgroundView addSubview:imageView];
240+
}
241+
}
242+
243+
UIView *targetView = backgroundView ? backgroundView : superView;
244+
230245
NSMutableArray<NSLayoutConstraint *> *constraints = [[NSMutableArray alloc] init];
231246
switch (backgroundImageProperties->GetFillMode()) {
232247
case ImageFillMode::Repeat: {
233248
[constraints addObjectsFromArray:@[
234249
[NSLayoutConstraint constraintWithItem:imageView
235250
attribute:NSLayoutAttributeTop
236251
relatedBy:NSLayoutRelationEqual
237-
toItem:superView
252+
toItem:targetView
238253
attribute:NSLayoutAttributeTop
239254
multiplier:1.0
240255
constant:0],
241256
[NSLayoutConstraint constraintWithItem:imageView
242257
attribute:NSLayoutAttributeBottom
243258
relatedBy:NSLayoutRelationEqual
244-
toItem:superView
259+
toItem:targetView
245260
attribute:NSLayoutAttributeBottom
246261
multiplier:1.0
247262
constant:0],
248263
[NSLayoutConstraint constraintWithItem:imageView
249264
attribute:NSLayoutAttributeLeading
250265
relatedBy:NSLayoutRelationEqual
251-
toItem:superView
266+
toItem:targetView
252267
attribute:NSLayoutAttributeLeading
253268
multiplier:1.0
254269
constant:0],
255270
[NSLayoutConstraint constraintWithItem:imageView
256271
attribute:NSLayoutAttributeTrailing
257272
relatedBy:NSLayoutRelationEqual
258-
toItem:superView
273+
toItem:targetView
259274
attribute:NSLayoutAttributeTrailing
260275
multiplier:1.0
261276
constant:0]
@@ -276,14 +291,14 @@ void applyBackgroundImageConstraints(const BackgroundImage *backgroundImagePrope
276291
[NSLayoutConstraint constraintWithItem:imageView
277292
attribute:NSLayoutAttributeLeading
278293
relatedBy:NSLayoutRelationEqual
279-
toItem:superView
294+
toItem:targetView
280295
attribute:NSLayoutAttributeLeading
281296
multiplier:1.0
282297
constant:0],
283298
[NSLayoutConstraint constraintWithItem:imageView
284299
attribute:NSLayoutAttributeTrailing
285300
relatedBy:NSLayoutRelationEqual
286-
toItem:superView
301+
toItem:targetView
287302
attribute:NSLayoutAttributeTrailing
288303
multiplier:1.0
289304
constant:0]
@@ -304,35 +319,34 @@ void applyBackgroundImageConstraints(const BackgroundImage *backgroundImagePrope
304319
[NSLayoutConstraint constraintWithItem:imageView
305320
attribute:NSLayoutAttributeTop
306321
relatedBy:NSLayoutRelationEqual
307-
toItem:superView
322+
toItem:targetView
308323
attribute:NSLayoutAttributeTop
309324
multiplier:1.0
310325
constant:0],
311326
[NSLayoutConstraint constraintWithItem:imageView
312327
attribute:NSLayoutAttributeBottom
313328
relatedBy:NSLayoutRelationEqual
314-
toItem:superView
329+
toItem:targetView
315330
attribute:NSLayoutAttributeBottom
316331
multiplier:1.0
317332
constant:0]
318333
]];
319-
configHorizontalAlignmentConstraintsForBackgroundImageView(backgroundImageProperties, superView, imageView, constraints);
334+
configHorizontalAlignmentConstraintsForBackgroundImageView(backgroundImageProperties, targetView, imageView, constraints);
320335
break;
321336
}
322337
case ImageFillMode::Cover:
323338
default: {
324339
// we should not apply the constraints if the superView's frame is not ready
325340
// check layoutSubview of ACRContentStackView to see the alternate case
326341
if (superView.frame.size.width != 0 && superView.frame.size.height != 0) {
327-
renderBackgroundCoverMode(imageView, (ACRContentStackView *)superView, constraints);
342+
renderBackgroundCoverMode(imageView, targetView, constraints, (ACRContentStackView *)superView);
328343
}
329344

330-
configVerticalAlignmentConstraintsForBackgroundImageView(backgroundImageProperties, superView, imageView, constraints);
331-
332-
configHorizontalAlignmentConstraintsForBackgroundImageView(backgroundImageProperties, superView, imageView, constraints);
345+
configVerticalAlignmentConstraintsForBackgroundImageView(backgroundImageProperties, targetView, imageView, constraints);
333346

334-
superView.clipsToBounds = YES;
347+
configHorizontalAlignmentConstraintsForBackgroundImageView(backgroundImageProperties, targetView, imageView, constraints);
335348

349+
targetView.clipsToBounds = YES;
336350
break;
337351
}
338352
}

source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCardsTests/AdaptiveCardsTests.mm

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// Copyright © 2021 Microsoft. All rights reserved.
77
//
88

9+
#import "ACRContentHoldingUIView.h"
910
#import "TextBlock.h"
1011
#import <UIKit/UIKit.h>
1112
#import <XCTest/XCTest.h>
@@ -16,23 +17,35 @@ @interface AdaptiveCardsTests : XCTestCase
1617

1718
@implementation AdaptiveCardsTests
1819

19-
- (void)setUp {
20+
- (void)setUp
21+
{
2022
// Put setup code here. This method is called before the invocation of each test method in the class.
2123
}
2224

23-
- (void)tearDown {
25+
- (void)tearDown
26+
{
2427
// Put teardown code here. This method is called after the invocation of each test method in the class.
2528
}
2629

27-
- (void)testTextBlockTextProperty2 {
30+
- (void)testTextBlockTextProperty2
31+
{
2832
std::shared_ptr<AdaptiveCards::TextBlock> textblock = std::make_shared<AdaptiveCards::TextBlock>();
2933
textblock->SetText("Text test");
30-
34+
3135
XCTAssert(textblock->GetText() == "Text test");
32-
36+
3337
std::string serializedTextBlock = textblock->Serialize();
3438
XCTAssert(serializedTextBlock == "{\"text\":\"Text test\",\"type\":\"TextBlock\"}\n");
3539
}
3640

41+
- (void)testContentHoldingUIViewWithImage
42+
{
43+
UIImageView *imageView = [[UIImageView alloc] init];
44+
ACRContentStackView *viewGroup = [[ACRContentStackView alloc] init];
45+
ACRContentHoldingUIView *wrapperView = [[ACRContentHoldingUIView alloc] initWithImageProperties:[[ACRImageProperties alloc] init] imageView:imageView viewGroup:viewGroup];
46+
XCTAssertNotNil(wrapperView);
47+
XCTAssertEqualObjects(wrapperView.contentView, imageView);
48+
}
49+
3750
@end
3851

source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCardsTests/AdaptiveCardsUtiliOSTest.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ - (void)testFindTheClosestCGRect1
4545
XCTAssertTrue(abs(rrect.size.height - 150) / rect2.size.height <= kACRScalerTolerance);
4646
}
4747

48+
4849
@end
4950

0 commit comments

Comments
 (0)