Skip to content

Commit

Permalink
fix: [HCPSDKFIORIUIKIT-2043] resolve UIFont instance from Swift pass …
Browse files Browse the repository at this point in the history
…to SwiftUI can't be resized and empty text disable accessibility. (#418)

Co-authored-by: Bill Zhou <bill.zhou01@sap.com>
  • Loading branch information
AllenCao001 and billzhou0223 authored Apr 25, 2022
1 parent d2dd280 commit 530f3d1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/FioriSwiftUICore/DataTable/GridTableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct GridTableView: View {
}

// trigger the layout if it has been changed
if self.sizeCategory != self.sizeCategory {
if self.layoutManager.sizeCategory != self.sizeCategory {
self.layoutManager.sizeCategory = self.sizeCategory
}

Expand Down
2 changes: 2 additions & 0 deletions Sources/FioriSwiftUICore/DataTable/ItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct ItemView: View {
.lineLimit(dataItem.lineLimit)
.multilineTextAlignment(dataItem.textAlignment)
.frame(width: contentWidth, alignment: dataItem.textAlignment.toTextFrameAlignment())
.accessibility(hidden: value.isEmpty)
}

Spacer(minLength: 0)
Expand All @@ -65,6 +66,7 @@ struct ItemView: View {
.lineLimit(dataItem.lineLimit)
.multilineTextAlignment(dataItem.textAlignment)
.frame(width: contentWidth, alignment: dataItem.textAlignment.toTextFrameAlignment())
.accessibility(hidden: value.isEmpty)
}

Spacer(minLength: 0)
Expand Down
10 changes: 8 additions & 2 deletions Sources/FioriSwiftUICore/DataTable/LayoutData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,13 @@ class LayoutData {
let title = item.text
var uifont: UIFont
if let tmpUIFont = item.uifont {
uifont = tmpUIFont
// `item.uifont` is passed by developer, although is a preferred font but can't resize according to system in SwiftUI. So need to redefine the UIFont instance.
if let styleName = tmpUIFont.fontDescriptor.fontAttributes[.textStyle] as? String {
let textStyle = UIFont.TextStyle(rawValue: styleName)
uifont = UIFont.preferredFont(forTextStyle: textStyle)
}else {
uifont = tmpUIFont
}
} else if let _font = item.font {
uifont = UIFont.preferredFont(from: _font)
} else {
Expand All @@ -164,7 +170,7 @@ class LayoutData {
firstBaselineHeight: firstBaselineHeight,
pos: .zero,
font: font,
uifont: item.uifont,
uifont: uifont,
foregroundColor: textColor,
size: size,
textAlignment: textAlignment,
Expand Down

0 comments on commit 530f3d1

Please sign in to comment.