Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
// Copyright © 2018 Microsoft. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "ACOBaseCardElement.h"
#import "ACRIBaseInputHandler.h"
#import "ChoiceInput.h"
#import "ChoiceSetInput.h"
#import "ACRIBaseInputHandler.h"
#import "HostConfig.h"
#import <UIKit/UIKit.h>

extern NSString *checkedCheckboxReuseID;
extern NSString *uncheckedCheckboxReuseID;
Expand All @@ -22,8 +23,10 @@ extern NSString *uncheckedRadioButtonReuseID;
@interface ACRChoiceSetViewDataSource:NSObject<UITableViewDataSource, UITableViewDelegate, ACRIBaseInputHandler>
@property NSString *id;
@property BOOL isMultiChoicesAllowed;
@property ACRContainerStyle parentStyle;

- (instancetype)initWithInputChoiceSet:(std::shared_ptr<AdaptiveCards::ChoiceSetInput> const &)choiceSet WithHostConfig:(std::shared_ptr<AdaptiveCards::HostConfig> const &)hostConfig;

- (instancetype)initWithInputChoiceSet:(std::shared_ptr<AdaptiveCards::ChoiceSetInput> const&)choiceSet;

- (void)getDefaultInput:(NSMutableDictionary *)dictionary;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
// Copyright © 2018 Microsoft. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ACRChoiceSetViewDataSource.h"
#import "UtiliOS.h"
#import <Foundation/Foundation.h>

using namespace AdaptiveCards;

Expand All @@ -23,13 +24,13 @@ @implementation ACRChoiceSetCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(nullable NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if(self) {
if (self) {
UIImage *iconImage = nil;
if([reuseIdentifier isEqualToString:@"checked-checkbox"]){
if ([reuseIdentifier isEqualToString:@"checked-checkbox"]) {
iconImage = [UIImage imageNamed:@"checked-checkbox-24.png" inBundle:[NSBundle bundleWithIdentifier:@"MSFT.AdaptiveCards"] compatibleWithTraitCollection:nil];
} else if([reuseIdentifier isEqualToString:@"checked-radiobutton"]){
} else if ([reuseIdentifier isEqualToString:@"checked-radiobutton"]) {
iconImage = [UIImage imageNamed:@"checked.png" inBundle:[NSBundle bundleWithIdentifier:@"MSFT.AdaptiveCards"] compatibleWithTraitCollection:nil];
} else if([reuseIdentifier isEqualToString:@"unchecked-checkbox"]){
} else if ([reuseIdentifier isEqualToString:@"unchecked-checkbox"]) {
iconImage = [UIImage imageNamed:@"unchecked-checkbox-24.png" inBundle:[NSBundle bundleWithIdentifier:@"MSFT.AdaptiveCards"] compatibleWithTraitCollection:nil];
} else {
iconImage = [UIImage imageNamed:@"unchecked.png" inBundle:[NSBundle bundleWithIdentifier:@"MSFT.AdaptiveCards"] compatibleWithTraitCollection:nil];
Expand All @@ -45,44 +46,46 @@ - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(nulla

@end

@implementation ACRChoiceSetViewDataSource
{
@implementation ACRChoiceSetViewDataSource {
std::shared_ptr<ChoiceSetInput> _choiceSetDataSource;
NSMutableDictionary *_userSelections;
// used for radio button; keep tracking of the current choice
NSIndexPath *_currentSelectedIndexPath;
NSMutableSet *_defaultValuesSet;
NSArray *_defaultValuesArray;
BOOL _shouldWrap;
std::shared_ptr<HostConfig> _config;
}

- (instancetype)initWithInputChoiceSet:(std::shared_ptr<AdaptiveCards::ChoiceSetInput> const&)choiceSet
- (instancetype)initWithInputChoiceSet:(std::shared_ptr<AdaptiveCards::ChoiceSetInput> const &)choiceSet WithHostConfig:(std::shared_ptr<AdaptiveCards::HostConfig> const &)hostConfig;
{
self = [super init];
if(self)
{
self.id = [[NSString alloc]initWithCString:choiceSet->GetId().c_str()
if (self) {
self.id = [[NSString alloc] initWithCString:choiceSet->GetId().c_str()
encoding:NSUTF8StringEncoding];
_isMultiChoicesAllowed = choiceSet->GetIsMultiSelect();
_choiceSetDataSource = choiceSet;
_shouldWrap = choiceSet->GetWrap();
_userSelections = [[NSMutableDictionary alloc] init];
_currentSelectedIndexPath = nil;
_config = hostConfig;
_parentStyle = ACRContainerStyle::ACRNone;

NSString *defaultValues = [NSString stringWithCString:_choiceSetDataSource->GetValue().c_str()
encoding:NSUTF8StringEncoding];
_defaultValuesArray = [defaultValues componentsSeparatedByCharactersInSet:
[NSCharacterSet characterSetWithCharactersInString:@","]];
[NSCharacterSet characterSetWithCharactersInString:@","]];

if (_isMultiChoicesAllowed || [_defaultValuesArray count] == 1){
if (_isMultiChoicesAllowed || [_defaultValuesArray count] == 1) {
_defaultValuesSet = [NSMutableSet setWithArray:_defaultValuesArray];
}

NSUInteger index = 0;
for(const auto& choice : _choiceSetDataSource->GetChoices()) {
for (const auto &choice : _choiceSetDataSource->GetChoices()) {
NSString *keyForDefaultValue = [NSString stringWithCString:choice->GetValue().c_str()
encoding:NSUTF8StringEncoding];

if([_defaultValuesSet containsObject:keyForDefaultValue]){
if ([_defaultValuesSet containsObject:keyForDefaultValue]) {
_userSelections[[NSNumber numberWithInteger:index]] = [NSNumber numberWithBool:YES];
}
++index;
Expand All @@ -107,23 +110,24 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
{
UITableViewCell *cell = nil;

if(_userSelections[[NSNumber numberWithInteger:indexPath.row]] == [NSNumber numberWithBool:YES]){
if(_isMultiChoicesAllowed) {
if (_userSelections[[NSNumber numberWithInteger:indexPath.row]] == [NSNumber numberWithBool:YES]) {
if (_isMultiChoicesAllowed) {
cell = [tableView dequeueReusableCellWithIdentifier:checkedCheckboxReuseID];
} else {
cell = [tableView dequeueReusableCellWithIdentifier:checkedRadioButtonReuseID];
}
} else {
if(_isMultiChoicesAllowed) {
if (_isMultiChoicesAllowed) {
cell = [tableView dequeueReusableCellWithIdentifier:uncheckedCheckboxReuseID];
} else {
cell = [tableView dequeueReusableCellWithIdentifier:uncheckedRadioButtonReuseID];
}
}

NSString *title = [NSString stringWithCString:_choiceSetDataSource->GetChoices()[indexPath.row]->GetTitle().c_str()
encoding:NSUTF8StringEncoding];
encoding:NSUTF8StringEncoding];
cell.textLabel.text = title;
cell.textLabel.textColor = getForegroundUIColorFromAdaptiveAttribute(_config, _parentStyle);
cell.textLabel.lineBreakMode = NSLineBreakByTruncatingTail;
cell.selectionStyle = UITableViewCellSelectionStyleNone;

Expand All @@ -133,9 +137,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
// update the current selection
if([_userSelections count] &&
[_userSelections objectForKey:[NSNumber numberWithInteger:indexPath.row]] &&
[[_userSelections objectForKey:[NSNumber numberWithInteger:indexPath.row]] boolValue] == YES) {
if ([_userSelections count] &&
[_userSelections objectForKey:[NSNumber numberWithInteger:indexPath.row]] &&
[[_userSelections objectForKey:[NSNumber numberWithInteger:indexPath.row]] boolValue] == YES) {
_currentSelectedIndexPath = indexPath;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ - (UIView *)render:(UIView<ACRIContentHoldingView> *)viewGroup
dataSource = [[ACRChoiceSetViewDataSourceCompactStyle alloc] initWithInputChoiceSet:choiceSet rootView:rootView];
[choiceSetView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
} else {
dataSource = [[ACRChoiceSetViewDataSource alloc] initWithInputChoiceSet:choiceSet];
dataSource = [[ACRChoiceSetViewDataSource alloc] initWithInputChoiceSet:choiceSet WithHostConfig:config];
[choiceSetView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ - (UIView *)render:(UIView<ACRIContentHoldingView> *)viewGroup
inputTableView.frame = CGRectMake(0, 0, viewGroup.frame.size.width, viewGroup.frame.size.height);
[inputTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
ACRToggleInputDataSource *dataSource = [[ACRToggleInputDataSource alloc] initWithInputToggle:toggleBlck WithHostConfig:config];
dataSource.parentStyle = viewGroup.style;
inputTableView.delegate = dataSource;
inputTableView.dataSource = dataSource;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="15400" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15404"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -14,8 +12,6 @@
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" clearButtonMode="always" id="Lb5-az-8Wv" customClass="ACRTextField">
<rect key="frame" x="0.0" y="0.0" width="97" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" cocoaTouchSystemColor="lightTextColor"/>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
<point key="canvasLocation" x="-371" y="-262"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
// Copyright © 2018 Microsoft. All rights reserved.
//

#import "ToggleInput.h"
#import "ACRIBaseInputHandler.h"
#import "ACOBaseCardElement.h"
#import "ACRColumnSetView.h"
#import "ACRIBaseCardElementRenderer.h"
#import "ACRIBaseInputHandler.h"
#import "HostConfig.h"
#import "ACRColumnSetView.h"
#import "ToggleInput.h"

@interface ACRToggleInputDataSource:NSObject<UITableViewDataSource, UITableViewDelegate, ACRIBaseInputHandler>
@interface ACRToggleInputDataSource : NSObject <UITableViewDataSource, UITableViewDelegate, ACRIBaseInputHandler>

@property ACRContainerStyle parentStyle;
@property NSString *id;
@property NSString *valueOn;
@property NSString *valueOff;
@property UISwitch *toggleSwitch;

- (instancetype)initWithInputToggle:(std::shared_ptr<AdaptiveCards::ToggleInput> const&)toggleInput
WithHostConfig:(std::shared_ptr<AdaptiveCards::HostConfig> const&)hostConfig;
- (instancetype)initWithInputToggle:(std::shared_ptr<AdaptiveCards::ToggleInput> const &)toggleInput
WithHostConfig:(std::shared_ptr<AdaptiveCards::HostConfig> const &)hostConfig;
@end
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,47 @@
// Copyright © 2018 Microsoft. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ACRToggleInputDataSource.h"
#import "ACRColumnSetView.h"
#import "ACRIBaseCardElementRenderer.h"
#import "HostConfig.h"
#import "ACRUILabel.h"
#import "ACRColumnSetView.h"
#import "HostConfig.h"
#import "UtiliOS.h"
#import <Foundation/Foundation.h>

using namespace AdaptiveCards;
const CGFloat padding = 16.0f;

@implementation ACRToggleInputDataSource
{
@implementation ACRToggleInputDataSource {
std::shared_ptr<ToggleInput> _toggleInputDataSource;
std::shared_ptr<HostConfig> _config;
NSString *_title;
BOOL _shouldWrap;
}

- (instancetype)initWithInputToggle:(std::shared_ptr<ToggleInput> const&)toggleInput
WithHostConfig:(std::shared_ptr<HostConfig> const&)hostConfig
- (instancetype)initWithInputToggle:(std::shared_ptr<ToggleInput> const &)toggleInput
WithHostConfig:(std::shared_ptr<HostConfig> const &)hostConfig
{
self = [super init];

if(self) {
if (self) {
_title = [NSString stringWithCString:toggleInput->GetTitle().c_str()
encoding:NSUTF8StringEncoding];
_toggleSwitch = [[UISwitch alloc] init];
_toggleInputDataSource = toggleInput;
_config = hostConfig;
self.id = [[NSString alloc]initWithCString:_toggleInputDataSource->GetId().c_str()
encoding:NSUTF8StringEncoding];
_parentStyle = ACRContainerStyle::ACRNone;
self.id = [[NSString alloc] initWithCString:_toggleInputDataSource->GetId().c_str()
encoding:NSUTF8StringEncoding];
_shouldWrap = toggleInput->GetWrap();
if(_toggleInputDataSource->GetValue() == _toggleInputDataSource->GetValueOn()) {
if (_toggleInputDataSource->GetValue() == _toggleInputDataSource->GetValueOn()) {
_toggleSwitch.on = YES;
}

self.valueOn = [[NSString alloc]initWithCString:_toggleInputDataSource->GetValueOn().c_str()
encoding:NSUTF8StringEncoding];
self.valueOff = [[NSString alloc]initWithCString:_toggleInputDataSource->GetValueOff().c_str()
encoding:NSUTF8StringEncoding];
self.valueOn = [[NSString alloc] initWithCString:_toggleInputDataSource->GetValueOn().c_str()
encoding:NSUTF8StringEncoding];
self.valueOff = [[NSString alloc] initWithCString:_toggleInputDataSource->GetValueOff().c_str()
encoding:NSUTF8StringEncoding];
}
return self;
}
Expand All @@ -63,11 +64,12 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
{
static NSString *identifier = @"cellForCompactMode";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if(!cell) {
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:identifier];
}
cell.textLabel.text = _title;
cell.textLabel.textColor = getForegroundUIColorFromAdaptiveAttribute(_config, _parentStyle);
cell.textLabel.adjustsFontSizeToFitWidth = NO;
cell.textLabel.numberOfLines = 0;
cell.textLabel.lineBreakMode = NSLineBreakByTruncatingTail;
Expand Down Expand Up @@ -95,24 +97,25 @@ - (BOOL)validate:(NSError **)error

- (void)getInput:(NSMutableDictionary *)dictionary
{
dictionary[self.id] = _toggleSwitch.on? self.valueOn : self.valueOff;
dictionary[self.id] = _toggleSwitch.on ? self.valueOn : self.valueOff;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView.dataSource tableView:tableView cellForRowAtIndexPath:indexPath];
CGSize toggleSize = [_toggleSwitch intrinsicContentSize];
NSString *labelString = nil;
if(!_shouldWrap) {
if (!_shouldWrap) {
labelString = @"A";
} else {
labelString = cell.textLabel.text;
}
CGSize labelStringSize =
[labelString boundingRectWithSize:CGSizeMake(cell.contentView.frame.size.width - toggleSize.width, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
attributes:@{NSFontAttributeName:cell.textLabel.font}
context:nil].size;
[labelString boundingRectWithSize:CGSizeMake(cell.contentView.frame.size.width - toggleSize.width, CGFLOAT_MAX)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
attributes:@{NSFontAttributeName : cell.textLabel.font}
context:nil]
.size;
CGFloat height = MAX(labelStringSize.height, toggleSize.height);
return height + padding;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ void TextRunToRichTextElementProperties(const std::shared_ptr<TextRun> &textRun,
void buildIntermediateResultForText(ACRView *rootView, ACOHostConfig *hostConfig, RichTextElementProperties const &textProperties, NSString *elementId);

ACOBaseActionElement *deserializeUnknownActionToCustomAction(const std::shared_ptr<UnknownAction> action);

UIColor *getForegroundUIColorFromAdaptiveAttribute(std::shared_ptr<HostConfig> const &config, ACRContainerStyle style, ForegroundColor textColor = ForegroundColor::Default, bool isSubtle = false);
Original file line number Diff line number Diff line change
Expand Up @@ -678,3 +678,9 @@ void TextRunToRichTextElementProperties(const std::shared_ptr<TextRun> &textRun,
}
return customAction;
}

UIColor *getForegroundUIColorFromAdaptiveAttribute(std::shared_ptr<HostConfig> const &config, ACRContainerStyle style, ForegroundColor textColor, bool isSubtle)
{
const std::string str = config->GetForegroundColor([ACOHostConfig getSharedContainerStyle:style], textColor, isSubtle);
return [ACOHostConfig convertHexColorCodeToUIColor:str];
}