-
Notifications
You must be signed in to change notification settings - Fork 541
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
share shared model's c++ header (#1445)
* phase 1: share all header complete * updated xcode project files * dev complete * CR fix * fixed CR update
- Loading branch information
Showing
12 changed files
with
386 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
source/ios/AdaptiveCards/ADCIOSVisualizer/ADCIOSVisualizer/CustomTextBlockRenderer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// CustomTextBlockRenderer.h | ||
// ADCIOSVisualizer | ||
// | ||
// Copyright © 2018 Microsoft. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import <AdaptiveCards/ACFramework.h> | ||
|
||
@interface CustomTextBlockRenderer:ACRBaseCardElementRenderer | ||
|
||
+ (CustomTextBlockRenderer *)getInstance; | ||
|
||
@end |
105 changes: 105 additions & 0 deletions
105
source/ios/AdaptiveCards/ADCIOSVisualizer/ADCIOSVisualizer/CustomTextBlockRenderer.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// | ||
// CustomTextBlockRenderer | ||
// CustomTextBlockRenderer.mm | ||
// | ||
// Copyright © 2018 Microsoft. All rights reserved. | ||
// | ||
|
||
#import "CustomTextBlockRenderer.h" | ||
#import <AdaptiveCards/ACFramework.h> | ||
#import <AdaptiveCards/SharedAdaptiveCard.h> | ||
#import <AdaptiveCards/TextBlock.h> | ||
#import <AdaptiveCards/ACRTextBlockRenderer.h> | ||
#import <AdaptiveCards/ACOBaseCardElementPrivate.h> | ||
#import <AdaptiveCards/ACRContentHoldingUIView.h> | ||
#import <AdaptiveCards/MarkDownParser.h> | ||
#import <AdaptiveCards/HostConfig.h> | ||
#import <AdaptiveCards/ACOHostConfigPrivate.h> | ||
|
||
@implementation CustomTextBlockRenderer | ||
|
||
+ (CustomTextBlockRenderer *)getInstance | ||
{ | ||
static CustomTextBlockRenderer *singletonInstance = [[self alloc] init]; | ||
return singletonInstance; | ||
} | ||
|
||
- (UIView *)render:(UIView<ACRIContentHoldingView> *)viewGroup | ||
rootView:(ACRView *)rootView | ||
inputs:(NSArray *)inputs | ||
baseCardElement:(ACOBaseCardElement *)acoElem | ||
hostConfig:(ACOHostConfig *)acoConfig | ||
{ | ||
|
||
std::shared_ptr<BaseCardElement> elem = [acoElem element]; | ||
std::shared_ptr<TextBlock> textBlockElement = std::static_pointer_cast<TextBlock>(elem); | ||
|
||
struct TextConfig textConfigForBlock = | ||
{ | ||
.weight = textBlockElement->GetTextWeight(), | ||
.size = textBlockElement->GetTextSize(), | ||
.color = textBlockElement->GetTextColor(), | ||
.isSubtle = textBlockElement->GetIsSubtle(), | ||
.wrap = textBlockElement->GetWrap() | ||
}; | ||
|
||
std::string textForBlock = textBlockElement->GetText(); | ||
|
||
NSString* parsedString = nil; | ||
// MarkDownParser transforms text with MarkDown to a html string | ||
std::shared_ptr<MarkDownParser> markDownParser = std::make_shared<MarkDownParser>([ACOHostConfig getLocalizedDate:textBlockElement]); | ||
parsedString = [NSString stringWithCString:markDownParser->TransformToHtml().c_str() encoding:NSUTF8StringEncoding]; | ||
|
||
// if correctly initialized, fonFamilyNames array is bigger than zero | ||
NSMutableString *fontFamilyName = [[NSMutableString alloc] initWithString:@"'"]; | ||
[fontFamilyName appendString:[acoConfig.fontFamilyNames componentsJoinedByString:@"', '"]]; | ||
[fontFamilyName appendString:@"'"]; | ||
|
||
// Font and text size are applied as CSS style by appending it to the html string | ||
parsedString = [parsedString stringByAppendingString:[NSString stringWithFormat:@"<style>body{font-family: %@; font-size:%dpx; font-weight: %d;}</style>", | ||
fontFamilyName, | ||
[acoConfig getTextBlockTextSize:textConfigForBlock.size], | ||
[acoConfig getTextBlockFontWeight:textConfigForBlock.weight]]]; | ||
// Convert html string to NSMutableAttributedString, NSAttributedString knows how to apply html tags | ||
NSData *htmlData = [parsedString dataUsingEncoding:NSUTF16StringEncoding]; | ||
NSDictionary *options = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType}; | ||
|
||
// Initializing NSMutableAttributedString for HTML rendering is very slow | ||
NSMutableAttributedString *content = [[NSMutableAttributedString alloc] initWithData:htmlData options:options documentAttributes:nil error:nil]; | ||
|
||
UILabel *lab = [[UILabel alloc] init]; // generate key for text map from TextBlock element's id | ||
// Set paragraph style such as line break mode and alignment | ||
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; | ||
paragraphStyle.lineBreakMode = textConfigForBlock.wrap ? NSLineBreakByWordWrapping:NSLineBreakByTruncatingTail; | ||
paragraphStyle.alignment = [ACOHostConfig getTextBlockAlignment:textBlockElement->GetHorizontalAlignment()]; | ||
|
||
// Obtain text color to apply to the attributed string | ||
ACRContainerStyle style = viewGroup.style; | ||
ColorsConfig &colorConfig = (style == ACREmphasis)? [acoConfig getHostConfig]->containerStyles.emphasisPalette.foregroundColors: | ||
[acoConfig getHostConfig]->containerStyles.defaultPalette.foregroundColors; | ||
// Add paragraph style, text color, text weight as attributes to a NSMutableAttributedString, content. | ||
[content addAttributes:@{NSParagraphStyleAttributeName:paragraphStyle, NSForegroundColorAttributeName:[ACOHostConfig getTextBlockColor:textConfigForBlock.color colorsConfig:colorConfig subtleOption:textConfigForBlock.isSubtle],} range:NSMakeRange(0, content.length)]; | ||
lab.attributedText = content; | ||
|
||
lab.numberOfLines = int(textBlockElement->GetMaxLines()); | ||
if(!lab.numberOfLines && !textBlockElement->GetWrap()){ | ||
lab.numberOfLines = 1; | ||
} | ||
|
||
ACRContentHoldingUIView *wrappingview = [[ACRContentHoldingUIView alloc] init]; | ||
|
||
[wrappingview addSubview:lab]; | ||
|
||
[wrappingview setAlignmentForSubview:textBlockElement->GetHorizontalAlignment()]; | ||
|
||
[viewGroup addArrangedSubview:wrappingview]; | ||
|
||
wrappingview.translatesAutoresizingMaskIntoConstraints = false; | ||
|
||
wrappingview.backgroundColor = UIColor.lightGrayColor; | ||
|
||
lab.translatesAutoresizingMaskIntoConstraints = false; | ||
|
||
return wrappingview; | ||
} | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.