Skip to content

Commit

Permalink
fix: Data table ios15 crash (#328)
Browse files Browse the repository at this point in the history
* feat: 🎸 Data Table for new design

* Revert "feat: 🎸 Data Table for new design"

This reverts commit f4cc19d.

* fix: 🐛 fixed crash on iOS 15
  • Loading branch information
ShawnMa16 authored Sep 24, 2021
1 parent 86058d5 commit a23964d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,28 @@ public struct DataTableExample: View {
func makeBody() -> some View {
var view = DataTable(model: self.model)
return
NavigationView {
view
.navigationBarTitle("Data Table", displayMode: .inline)
.navigationBarItems(leading:
Button(action: {
showingSheet.toggle()
}) {
Image(systemName: "plus")
}.sheet(isPresented: $showingSheet) {
SheetView(model: self.model)
},
trailing:
Button(self.isEditing ? "Delete" : "Edit") {
DispatchQueue.main.async {
self.isEditing = !self.isEditing
view.isEditing = self.isEditing
if !self.isEditing {
let indexSet = IndexSet(self.model.selectedIndexes)
self.model.rowData.remove(atOffsets: indexSet)
self.model.selectedIndexes = []
}
view
.navigationBarTitle("Data Table", displayMode: .inline)
.navigationBarItems(leading:
Button(action: {
showingSheet.toggle()
}) {
Image(systemName: "plus")
}.sheet(isPresented: $showingSheet) {
SheetView(model: self.model)
},
trailing:
Button(self.isEditing ? "Delete" : "Edit") {
DispatchQueue.main.async {
self.isEditing = !self.isEditing
view.isEditing = self.isEditing
if !self.isEditing {
let indexSet = IndexSet(self.model.selectedIndexes)
self.model.rowData.remove(atOffsets: indexSet)
self.model.selectedIndexes = []
}
})
}
.navigationViewStyle(StackNavigationViewStyle())
}
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/FioriSwiftUICore/DataTable/DataTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public struct DataTable: View {
let dataManager = TableDataManager(selectedIndexes: self.model.selectedIndexes)
layoutManager.sizeClass = self.horizontalSizeClass ?? .compact
layoutManager.rect = rect

layoutManager.setupMargins(rect: layoutManager.rect)
return Group {
if self.horizontalSizeClass == .compact, self.verticalSizeClass == .regular, self.model.showListView {
let listView = TableListView(layoutManager: layoutManager)
Expand Down
1 change: 0 additions & 1 deletion Sources/FioriSwiftUICore/DataTable/GridTableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ struct GridTableView: View {
self.lastScaleX = self.layoutManager.scaleX
self.lastScaleY = self.layoutManager.scaleY
}

let items: [[DataTableItem]] = self.layoutManager.dataItemsForTable(rect: rect)

return
Expand Down
49 changes: 28 additions & 21 deletions Sources/FioriSwiftUICore/DataTable/LeadingAccessoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,40 @@ struct LeadingAccessoryView: View {

var body: some View {
Group {
let totalWidth = self.layoutManager.leadingItemsWidths[self.layoutIndex]
let offset = totalWidth / 2
makeBody(items: self.items)
.offset(x: offset * self.layoutManager.scaleX)
}
}

func makeBody(items: [AccessoryItem]) -> some View {
HStack(alignment: .center, spacing: 4) {
makeSectionButton()
ForEach(0 ..< items.count, id: \.self) { index in
switch items[index] {
case .button(let button):
makeButton(button: button)
case .icon(let image):
image
.resizable()
.aspectRatio(contentMode: .fit)
.foregroundColor(TableViewLayout.defaultForegroundColor)
.frame(width: 16 * self.layoutManager.scaleX, height: 16 * self.layoutManager.scaleY, alignment: .center)
case .text(let string):
Text(string)
func makeBody(items: [AccessoryItem]) -> AnyView {
guard self.layoutIndex < self.layoutManager.rowHeights.count else {
return AnyView(EmptyView())
}

let totalWidth = self.layoutManager.leadingItemsWidths[self.layoutIndex]
let offset = totalWidth / 2

return AnyView(
HStack(alignment: .center, spacing: 4) {
makeSectionButton()
ForEach(0 ..< items.count, id: \.self) { index in
switch items[index] {
case .button(let button):
makeButton(button: button)
case .icon(let image):
image
.resizable()
.aspectRatio(contentMode: .fit)
.foregroundColor(TableViewLayout.defaultForegroundColor)
.frame(width: 16 * self.layoutManager.scaleX, height: 16 * self.layoutManager.scaleY, alignment: .center)
case .text(let string):
Text(string)
}
}
}
}
.frame(height: self.layoutManager.rowHeights[self.layoutIndex] * self.layoutManager.scaleY)
.background(self.backgroundColor)
.frame(height: self.layoutManager.rowHeights[self.layoutIndex] * self.layoutManager.scaleY)
.offset(x: offset * self.layoutManager.scaleX)
.background(self.backgroundColor)
)
}

func makeButton(button: AccessoryButton) -> some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ extension TableLayoutManager {

var width: CGFloat = 0
var height: CGFloat = 0

self.setupMargins(rect: rect)


width = self.getColumnWidths(rect).reduce(0, +)
width += self.tableLeadingLayoutMargin
width += self.tableTrailingLayoutMargin
Expand Down Expand Up @@ -223,7 +221,7 @@ extension TableLayoutManager {
var heights: [CGFloat] = []
for (index, row) in rows.enumerated() {
var itemHeight: CGFloat = 0
let isHeader = self.model.headerData != nil && index == 0
let isHeader = self.model.hasHeader && index == 0
let topAndBottom = isHeader ? TableViewLayout.topAndBottomPaddingsForHeader : TableViewLayout.topAndBottomPaddings
for item in row {
itemHeight = max(item.size.height, itemHeight)
Expand Down

0 comments on commit a23964d

Please sign in to comment.