From 12759ee4547360e8eb968f678e280078e91422d0 Mon Sep 17 00:00:00 2001 From: Sheng Xu Date: Wed, 20 Sep 2023 14:03:33 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20[bcp:=200]=20fix=20DataTa?= =?UTF-8?q?ble's=20sizeThatFits()=20for=20dynamic=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/FioriSwiftUICore/DataTable/DataTable.swift | 7 ++++--- Sources/FioriSwiftUICore/DataTable/LayoutData.swift | 2 ++ .../FioriSwiftUICore/DataTable/TableLayoutManager.swift | 2 +- .../DataTable/TableLayoutMangerExtension.swift | 6 ++++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Sources/FioriSwiftUICore/DataTable/DataTable.swift b/Sources/FioriSwiftUICore/DataTable/DataTable.swift index e8b7c4403..da19a060f 100644 --- a/Sources/FioriSwiftUICore/DataTable/DataTable.swift +++ b/Sources/FioriSwiftUICore/DataTable/DataTable.swift @@ -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. @@ -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() diff --git a/Sources/FioriSwiftUICore/DataTable/LayoutData.swift b/Sources/FioriSwiftUICore/DataTable/LayoutData.swift index 3478244df..1f3eb37da 100644 --- a/Sources/FioriSwiftUICore/DataTable/LayoutData.swift +++ b/Sources/FioriSwiftUICore/DataTable/LayoutData.swift @@ -7,6 +7,8 @@ class LayoutData { var sizeClass: UserInterfaceSizeClass = .compact + var dynamicTypeSize: DynamicTypeSize? + var editMode: TableModel.EditMode = .none var hasHeader: Bool = false diff --git a/Sources/FioriSwiftUICore/DataTable/TableLayoutManager.swift b/Sources/FioriSwiftUICore/DataTable/TableLayoutManager.swift index 3ce190cdf..d51fd2d00 100644 --- a/Sources/FioriSwiftUICore/DataTable/TableLayoutManager.swift +++ b/Sources/FioriSwiftUICore/DataTable/TableLayoutManager.swift @@ -15,7 +15,7 @@ class TableLayoutManager: ObservableObject { var sizeClass: UserInterfaceSizeClass = .compact - var sizeCategory: ContentSizeCategory? { + var dynamicTypeSize: DynamicTypeSize? { didSet { self.needsCalculateLayout = true } diff --git a/Sources/FioriSwiftUICore/DataTable/TableLayoutMangerExtension.swift b/Sources/FioriSwiftUICore/DataTable/TableLayoutMangerExtension.swift index 459c0817f..628f84a68 100644 --- a/Sources/FioriSwiftUICore/DataTable/TableLayoutMangerExtension.swift +++ b/Sources/FioriSwiftUICore/DataTable/TableLayoutMangerExtension.swift @@ -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 @@ -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) } @@ -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