Skip to content

Commit

Permalink
fix: 🐛 [bcp: 0] fix DataTable's sizeThatFits() for dynamic type
Browse files Browse the repository at this point in the history
  • Loading branch information
shengxu7 committed Sep 21, 2023
1 parent ba9bd4b commit 12759ee
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
7 changes: 4 additions & 3 deletions Sources/FioriSwiftUICore/DataTable/DataTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public struct DataTable: View {
/// Data table's data model
@ObservedObject public var model: TableModel
@ObservedObject var layoutManager: TableLayoutManager
@Environment(\.sizeCategory) var sizeCategory
@Environment(\.dynamicTypeSize) var dynamicTypeSize

/// Public initializer for DataTable
/// - Parameter model: TableModel Object.
Expand Down Expand Up @@ -98,8 +98,9 @@ public struct DataTable: View {
self.layoutManager.currentCell = nil
}
}
.onChange(of: self.sizeCategory) { newValue in
self.layoutManager.sizeCategory = newValue
.onChange(of: self.dynamicTypeSize) { newValue in
self.layoutManager.dynamicTypeSize = newValue
self.layoutManager.cacheLayoutDataForMeasurement = nil
self.layoutManager.layoutData = nil
}
.clipped()
Expand Down
2 changes: 2 additions & 0 deletions Sources/FioriSwiftUICore/DataTable/LayoutData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class LayoutData {

var sizeClass: UserInterfaceSizeClass = .compact

var dynamicTypeSize: DynamicTypeSize?

var editMode: TableModel.EditMode = .none

var hasHeader: Bool = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TableLayoutManager: ObservableObject {

var sizeClass: UserInterfaceSizeClass = .compact

var sizeCategory: ContentSizeCategory? {
var dynamicTypeSize: DynamicTypeSize? {
didSet {
self.needsCalculateLayout = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extension TableLayoutManager {
newWorkItem = DispatchWorkItem {
tmpLayoutData.editMode = self.model.editMode
tmpLayoutData.sizeClass = self.sizeClass
tmpLayoutData.dynamicTypeSize = self.dynamicTypeSize
tmpLayoutData.size = size
tmpLayoutData.headerCellPadding = self.model.headerCellPadding
tmpLayoutData.dataCellPadding = self.model.dataCellPadding
Expand Down Expand Up @@ -172,9 +173,9 @@ extension TableLayoutManager {
return CGSize(width: strSize.width + 32, height: strSize.height + 71)
}

if let cachedLD = cacheLayoutDataForMeasurement, cachedLD.size.width == size.width, cachedLD.sizeClass == self.sizeClass {
if let cachedLD = cacheLayoutDataForMeasurement, cachedLD.size.width == size.width, cachedLD.sizeClass == self.sizeClass, cachedLD.dynamicTypeSize == self.dynamicTypeSize {
let width = self.totalContentWidth(cachedLD, false)
let height = self.self.totalContentHeight(cachedLD, false)
let height = self.totalContentHeight(cachedLD, false)

return CGSize(width: width, height: height)
}
Expand All @@ -190,6 +191,7 @@ extension TableLayoutManager {

tmpLayoutData.editMode = model.editMode
tmpLayoutData.sizeClass = self.sizeClass
tmpLayoutData.dynamicTypeSize = self.dynamicTypeSize
tmpLayoutData.size = size
tmpLayoutData.headerCellPadding = model.headerCellPadding
tmpLayoutData.dataCellPadding = model.dataCellPadding
Expand Down

0 comments on commit 12759ee

Please sign in to comment.