Skip to content

Commit 5356a59

Browse files
jwoo-msftpaulcam206
authored andcommitted
[iOS] Table Horizontal Alignment Update (microsoft#6401)
* [iOS] Fixed microsoft#6219 * [iOS] adding padding support to toggle visibility * [Padding] Update * [iOS] work in progress * mostly done need to refactor and update padding management code * [iOS] refactored * [iOS] added padding test * refactored the padding configuration in FactSet to Padding Handler * [iOS] Updated VerticalContentAlignment and Height * Reverts samples card changes * [iOS] code clean-up * [iOS] Table Update * [iOS] Updated Table with better Horizontal Alignment Co-authored-by: Paul Campbell <[email protected]>
1 parent 94c4e2d commit 5356a59

File tree

11 files changed

+154
-120
lines changed

11 files changed

+154
-120
lines changed

source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@
11211121
name = ImageSet;
11221122
sourceTree = "<group>";
11231123
};
1124-
6BFCA139264F548600195CA7 /* TableView */ = {
1124+
6BFCA139264F548600195CA7 /* Table */ = {
11251125
isa = PBXGroup;
11261126
children = (
11271127
6BFCA14A265452E000195CA7 /* ACRTableRenderer.h */,
@@ -1135,7 +1135,7 @@
11351135
6BFCA13B264F54B100195CA7 /* ACRTableView.h */,
11361136
6BFCA13D264F54B300195CA7 /* ACRTableView.mm */,
11371137
);
1138-
name = TableView;
1138+
name = Table;
11391139
sourceTree = "<group>";
11401140
};
11411141
6BFF99DC2600121A0028069F /* Action.Execute */ = {
@@ -1198,7 +1198,6 @@
11981198
F42979341F3007C500E89914 /* ReadOnlyObjects */,
11991199
6B8C766826461F1A009548FA /* Resources */,
12001200
F423C0D71EE1FF2F00905679 /* SharedLib */,
1201-
6BFCA139264F548600195CA7 /* TableView */,
12021201
6B92A71B266FE84F00CAE3BF /* Utilities */,
12031202
);
12041203
path = AdaptiveCards;
@@ -1477,6 +1476,7 @@
14771476
6B7B1A9520BE2CBB00260731 /* ACRUIImageView.mm */,
14781477
F4F44B6A203FA8EF00A2F24C /* ACRUILabel.h */,
14791478
F4F44B6D203FAF9300A2F24C /* ACRUILabel.mm */,
1479+
6BFCA139264F548600195CA7 /* Table */,
14801480
6B124C9626B9F519007E9641 /* Columns */,
14811481
6BE6C7C626E7E2A6009E9171 /* ImageSet */,
14821482
6BB2120621000024009EA1BA /* Media */,

source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACORenderContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
@property (readonly) BOOL isFirstRowAsHeaders;
2222
@property (readonly) ACRVerticalContentAlignment verticalContentAlignment;
2323
@property (readonly) ACRHorizontalAlignment horizontalContentAlignment;
24+
@property (readonly) ACRContainerStyle style;
2425

2526
@property (weak) ACOHostConfig* _Nullable hostConfig;
2627

source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACORenderContext.mm

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ @interface ACOContextProperties : NSObject
2828
@property NSNumber *iconPlacement;
2929
@property BOOL hasSelectAction;
3030
@property BOOL isFirstRowAsHeaders;
31+
@property ContainerStyle style;
3132
@end
3233

3334
@implementation ACOContextProperties
@@ -41,6 +42,7 @@ @implementation ACORenderContext {
4142
NSMutableArray<NSNumber *> *_firstRowsAsheadersContext;
4243
NSMutableArray<NSNumber *> *_verticalAlignmentContext;
4344
NSMutableArray<NSNumber *> *_horizontalAlignmentContext;
45+
NSMutableArray<NSNumber *> *_styleContext;
4446
NSMapTable<NSNumber *, NSObject<ACOIVisibilityManagerFacade> *> *_visibilityMap;
4547
}
4648

@@ -56,6 +58,7 @@ - (instancetype)init
5658
_firstRowsAsheadersContext = [[NSMutableArray alloc] init];
5759
_verticalAlignmentContext = [[NSMutableArray alloc] init];
5860
_horizontalAlignmentContext = [[NSMutableArray alloc] init];
61+
_styleContext = [[NSMutableArray alloc] init];
5962
_visibilityMap = [NSMapTable mapTableWithKeyOptions:NSMapTableStrongMemory valueOptions:NSMapTableWeakMemory];
6063
}
6164

@@ -133,6 +136,17 @@ - (ACRHorizontalAlignment)horizontalContentAlignment
133136
return ACRLeft;
134137
}
135138

139+
- (ACRContainerStyle)style
140+
{
141+
if (_styleContext && [_styleContext count]) {
142+
NSNumber *number = [_styleContext lastObject];
143+
if (number) {
144+
return (ACRContainerStyle)[number intValue];
145+
}
146+
}
147+
return ACRNone;
148+
}
149+
136150
- (void)pushBaseActionElementContext:(ACOBaseActionElement *)element
137151
{
138152
return;
@@ -184,6 +198,12 @@ - (void)addToANewContext:(ACOContextProperties *)properties key:(NSNumber *)key
184198
[_verticalAlignmentContext addObject:[NSNumber numberWithInt:(int)(*properties.verticalAlignment)]];
185199
[contexts addObject:_verticalAlignmentContext];
186200
}
201+
202+
if (properties.style != ContainerStyle::None) {
203+
shouldPush = YES;
204+
[_styleContext addObject:[NSNumber numberWithInt:(int)(properties.style)]];
205+
[contexts addObject:_styleContext];
206+
}
187207

188208
if (shouldPush) {
189209
_internalIdContext[key] = contexts;
@@ -210,6 +230,7 @@ - (void)pushBaseCardElementContext:(ACOBaseCardElement *)acoElement additionalPr
210230
if (table) {
211231
properties.horizontalAlignment = table->GetHorizontalCellContentAlignment();
212232
properties.verticalAlignment = table->GetVerticalCellContentAlignment();
233+
properties.style = table->GetGridStyle();
213234
}
214235
}
215236

@@ -228,14 +249,20 @@ - (void)pushBaseCardElementContext:(ACOBaseCardElement *)acoElement additionalPr
228249
if (row) {
229250
properties.horizontalAlignment = row->GetHorizontalCellContentAlignment();
230251
properties.verticalAlignment = row->GetVerticalCellContentAlignment();
252+
properties.style = row->GetStyle();
231253
}
232254
}
233255

234256
if (acoElement.type == ACRTableCell) {
235257
const std::shared_ptr<TableCell> &cell = std::dynamic_pointer_cast<TableCell>(element);
236258
properties.crtl = cell->GetRtl();
237-
if (cell->GetSelectAction()) {
238-
properties.hasSelectAction = YES;
259+
if (cell) {
260+
if (cell->GetSelectAction()) {
261+
properties.hasSelectAction = YES;
262+
}
263+
264+
properties.verticalAlignment = cell->GetVerticalContentAlignment();
265+
properties.style = cell->GetStyle();
239266
}
240267
}
241268

source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRContainerRenderer.mm

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,7 @@ - (UIView *)render:(UIView<ACRIContentHoldingView> *)viewGroup
4747

4848
[viewGroup addArrangedSubview:container];
4949

50-
if (acoElem.type == ACRTableCell) {
51-
CGFloat top, left, bottom, right;
52-
top = left = bottom = right = [acoConfig getHostConfig]->GetSpacing().paddingSpacing;
53-
[container removeConstraints:container.constraints];
54-
[container applyPaddingToTop:top
55-
left:left
56-
bottom:bottom
57-
right:right
58-
priority:1000
59-
location:ACRBleedToAll];
60-
} else {
61-
configBleed(rootView, elem, container, acoConfig);
62-
}
50+
configBleed(rootView, elem, container, acoConfig);
6351

6452
renderBackgroundImage(containerElem->GetBackgroundImage(), container, rootView);
6553

source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRContentStackView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
@interface ACRContentStackView : UIView <ACRIContentHoldingView, ACOIVisibilityManagerFacade> {
1414
@protected
15+
UIStackView *_stackView;
1516
ACOFillerSpaceManager *_paddingHandler;
1617
NSMutableArray<UIView *> *_paddings;
1718
ACOVisibilityManager *_visibilityManager;

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

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ @implementation ACRContentStackView {
1818
NSMutableArray *_targets;
1919
NSMutableArray<ACRShowCardTarget *> *_showcardTargets;
2020
ACRContainerStyle _style;
21-
UIStackView *_stackView;
2221
NSMutableDictionary<NSString *, NSValue *> *_subviewIntrinsicContentSizeCollection;
2322
ACRRtl _rtl;
2423
NSMutableSet *_invisibleViews;
2524
ACRVerticalContentAlignment _verticalContentAlignment;
25+
ACRHorizontalAlignment _horizontalAlignment;
2626
}
2727

2828
- (instancetype)initWithStyle:(ACRContainerStyle)style
@@ -211,6 +211,11 @@ - (void)config:(nullable NSDictionary<NSString *, id> *)attributes
211211
if ([topPaddingAttrib boolValue]) {
212212
top = [topPaddingAttrib floatValue];
213213
}
214+
215+
NSNumber *horizontalAlignment = attributes[@"horizontal-alignment"];
216+
if ([horizontalAlignment intValue]) {
217+
_horizontalAlignment = (ACRHorizontalAlignment)[horizontalAlignment intValue];
218+
}
214219
}
215220

216221
[self applyPaddingToTop:top
@@ -352,13 +357,40 @@ - (void)applyPaddingToTop:(CGFloat)top
352357
CGFloat topPadding = (location & ACRBleedToTopEdge) ? top : 0;
353358
CGFloat bottomPadding = (location & ACRBleedToBottomEdge) ? bottom : 0;
354359

355-
NSString *horString = [[NSString alloc] initWithFormat:@"H:|-(%f@%u)-[_stackView]-(%f@%u)-|",
356-
leadingPadding, priority, trailingPadding, priority];
360+
NSMutableArray<NSLayoutConstraint *> *constraints = [[NSMutableArray alloc] init];
361+
NSDictionary *dictionary = nil;
362+
363+
if (_horizontalAlignment == ACRRight || _horizontalAlignment == ACRCenter) {
364+
UILayoutGuide *leftSpacer = [[UILayoutGuide alloc] init];
365+
[self addLayoutGuide:leftSpacer];
366+
[constraints addObject:[self.centerYAnchor constraintEqualToAnchor:leftSpacer.centerYAnchor]];
367+
NSLayoutConstraint *leftSpacerWidthConstraint = [leftSpacer.widthAnchor constraintEqualToConstant:0];
368+
leftSpacerWidthConstraint.priority = UILayoutPriorityDefaultLow;
369+
[constraints addObject:leftSpacerWidthConstraint];
370+
if (_horizontalAlignment == ACRCenter) {
371+
UILayoutGuide *rightSpacer = [[UILayoutGuide alloc] init];
372+
[self addLayoutGuide:rightSpacer];
373+
[constraints addObject:[self.centerYAnchor constraintEqualToAnchor:rightSpacer.centerYAnchor]];
374+
NSLayoutConstraint *rightSpacerWidthConstraint = [rightSpacer.widthAnchor constraintEqualToConstant:0];
375+
rightSpacerWidthConstraint.priority = UILayoutPriorityDefaultLow;
376+
[constraints addObject:rightSpacerWidthConstraint];
377+
[constraints addObject:[rightSpacer.widthAnchor constraintEqualToAnchor:leftSpacer.widthAnchor]];
378+
dictionary = NSDictionaryOfVariableBindings(_stackView, rightSpacer, leftSpacer);
379+
} else {
380+
dictionary = NSDictionaryOfVariableBindings(_stackView, leftSpacer);
381+
}
382+
} else {
383+
dictionary = NSDictionaryOfVariableBindings(_stackView);
384+
}
385+
386+
NSString *leftSpacerStr = (_horizontalAlignment == ACRRight || _horizontalAlignment == ACRCenter) ? @"[leftSpacer]-" : @"";
387+
NSString *rightSpacerStr = (_horizontalAlignment == ACRCenter) ? @"[rightSpacer]-" : @"";
388+
389+
NSString *horString = [[NSString alloc] initWithFormat:@"H:|-(%f@%u)-%@[_stackView]-%@(%f@%u)-|",
390+
leadingPadding, priority, leftSpacerStr, rightSpacerStr, trailingPadding, priority];
357391
NSString *verString = [[NSString alloc] initWithFormat:@"V:|-(%f@%u)-[_stackView]-(%f@%u)-|",
358392
topPadding, priority, bottomPadding, priority];
359393

360-
NSDictionary *dictionary = NSDictionaryOfVariableBindings(_stackView);
361-
362394
_widthconstraint = [NSLayoutConstraint constraintsWithVisualFormat:horString
363395
options:0
364396
metrics:nil
@@ -368,8 +400,10 @@ - (void)applyPaddingToTop:(CGFloat)top
368400
metrics:nil
369401
views:dictionary];
370402

371-
[self addConstraints:_widthconstraint];
372-
[self addConstraints:_heightconstraint];
403+
[constraints addObjectsFromArray:_widthconstraint];
404+
[constraints addObjectsFromArray:_heightconstraint];
405+
406+
[NSLayoutConstraint activateConstraints:constraints];
373407
}
374408

375409
// target is the background view, it will be pinned to parent according to the direction set by bleed,

source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRTableCellRenderer.mm

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
//
77

88
#import "ACRTableCellRenderer.h"
9+
#import "ACOBaseCardElementPrivate.h"
10+
#import "ACOHostConfigPrivate.h"
11+
#import "ACRRendererPrivate.h"
12+
#import "ACRTableCellView.h"
13+
#import "TableCell.h"
14+
#import "UtiliOS.h"
915

1016
@implementation ACRTableCellRenderer
1117

@@ -20,4 +26,41 @@ + (ACRCardElementType)elemType
2026
return ACRTableCell;
2127
}
2228

29+
30+
- (UIView *)render:(UIView<ACRIContentHoldingView> *)viewGroup
31+
rootView:(ACRView *)rootView
32+
inputs:(NSMutableArray *)inputs
33+
baseCardElement:(ACOBaseCardElement *)acoElem
34+
hostConfig:(ACOHostConfig *)acoConfig;
35+
{
36+
std::shared_ptr<BaseCardElement> elem = [acoElem element];
37+
auto cellElement = std::dynamic_pointer_cast<TableCell>(elem);
38+
39+
ACRColumnView *cell = (ACRColumnView *)viewGroup;
40+
41+
cell.rtl = rootView.context.rtl;
42+
43+
renderBackgroundImage(cellElement->GetBackgroundImage(), cell, rootView);
44+
45+
[ACRRenderer render:cell
46+
rootView:rootView
47+
inputs:inputs
48+
withCardElems:cellElement->GetItems()
49+
andHostConfig:acoConfig];
50+
51+
[cell setClipsToBounds:NO];
52+
53+
std::shared_ptr<BaseActionElement> selectAction = cellElement->GetSelectAction();
54+
ACOBaseActionElement *acoSelectAction = [ACOBaseActionElement getACOActionElementFromAdaptiveElement:selectAction];
55+
[cell configureForSelectAction:acoSelectAction rootView:rootView];
56+
57+
[cell configureLayoutAndVisibility:rootView.context.verticalContentAlignment
58+
minHeight:cellElement->GetMinHeight()
59+
heightType:GetACRHeight(cellElement->GetHeight())
60+
type:ACRContainer];
61+
62+
return cell;
63+
}
64+
65+
2366
@end

source/ios/AdaptiveCards/AdaptiveCards/AdaptiveCards/ACRTableCellView.h

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

8-
#import <UIKit/UIKit.h>
9-
#import <Foundation/Foundation.h>
10-
#import "AdaptiveCards.h"
118
#import "ACRContentStackView.h"
9+
#import "AdaptiveCards.h"
10+
#import <Foundation/Foundation.h>
11+
#import <UIKit/UIKit.h>
1212

1313
NS_ASSUME_NONNULL_BEGIN
1414

@@ -17,17 +17,17 @@ NS_ASSUME_NONNULL_BEGIN
1717
@property ACRContainerStyle style;
1818
@property ACRVerticalContentAlignment verticalAlignment;
1919
@property ACRHorizontalAlignment horizontalAlignment;
20+
@property CGFloat cellSpacing;
2021

2122
@end
2223

23-
@interface ACRTableCellView : ACRContentStackView
24+
@interface ACRTableCellView : ACRColumnView
2425

2526
- (instancetype)init:(ACOBaseCardElement *)baseCardElement
26-
cellDefinition:(ACRTableCellDefinition *)definition
27+
cellDefinition:(ACRTableCellDefinition *)definition
2728
rootView:(ACRView *)rootView
2829
inputs:(NSMutableArray *)inputs
2930
hostConfig:(ACOHostConfig *)acoConfig;
30-
3131
@end
3232

3333
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)