Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ios): support for html in AttributedStrings #13569

Merged
merged 15 commits into from
Oct 12, 2023
9 changes: 9 additions & 0 deletions apidoc/Titanium/UI/AttributedString.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ properties:
description: |
The `text` property must be set in the constructor and cannot be changed.
type: String

- name: html
summary: |
HTML string which will be transformed in attributed string. You can apply other attributes too.
description: |
The `html` property must be set in the constructor and cannot be changed. For Android you can use html attribute in Label [html](Titanium.UI.Label.html)
platforms: [iphone, ipad, macos]
since: 12.0.0
type: String

- name: attributes
summary: |
Expand Down
2 changes: 2 additions & 0 deletions apidoc/Titanium/UI/Label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ properties:

- name: html
summary: Simple HTML formatting.
description: |
For iOS parity you can use Attributed String [html](Titanium.UI.AttributedString.html)
platforms: [android]
type: String

Expand Down
17 changes: 13 additions & 4 deletions iphone/Classes/TiUIAttributedStringProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@ - (void)_destroy

- (void)_initWithProperties:(NSDictionary *)properties
{
NSString *text = [properties valueForKey:@"text"];
if (!text) {
DebugLog(@"[WARN] Ti.UI.AttributedString.text not set");
NSString *html = [properties valueForKey:@"html"];
if (html) {
_attributedString = [[NSAttributedString alloc] initWithData:[html dataUsingEncoding:NSUTF8StringEncoding]
options:@{ NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute : @(NSUTF8StringEncoding) }
documentAttributes:nil
error:nil];
} else {
NSString *text = [properties valueForKey:@"text"];
if (!text) {
DebugLog(@"[WARN] Ti.UI.AttributedString.text not set");
}
_attributedString = [[NSMutableAttributedString alloc] initWithString:text];
}
_attributedString = [[NSMutableAttributedString alloc] initWithString:text];
attributes = [[NSMutableArray alloc] init];
[super _initWithProperties:properties];
Brianggalvez marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down