forked from SAP/cloud-sdk-ios-fiori
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,907 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
Apps/Examples/Examples/FioriSwiftUICore/DataTable/DataTableExample.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import FioriSwiftUICore | ||
import Foundation | ||
import SwiftUI | ||
|
||
public enum TestRowData { | ||
static func generateRowData(count: Int, for row: Int) -> TableRowItem { | ||
var data: [DataItem] = [] | ||
for i in 0 ..< count { | ||
let textItem = DataTextItem("\(row), \(i)") | ||
let imageItem = DataImageItem(Image(systemName: "checkmark.circle.fill")) | ||
data.append(i == 0 ? imageItem : textItem) | ||
} | ||
let lAccessories: [AccessoryItem] = [.icon(Image(systemName: "arrow.triangle.2.circlepath"))] | ||
|
||
let tAccessory: AccessoryItem = .button(.init(image: Image(systemName: "chevron.forward"), title: "", action: { | ||
print("trailing accessory tapped: \(row) tapped") | ||
})) | ||
|
||
let output = TableRowItem(leadingAccessories: lAccessories, trailingAccessory: tAccessory, data: data) | ||
|
||
return output | ||
} | ||
|
||
static func generateNewRow(column: Int) -> TableRowItem { | ||
var data: [DataItem] = [] | ||
for _ in 0 ..< column { | ||
let textItem = DataTextItem("new item new item new item") | ||
textItem.lineLimit = 2 | ||
data.append(textItem) | ||
} | ||
return TableRowItem(leadingAccessories: [], trailingAccessory: nil, data: data) | ||
} | ||
|
||
static func generateColumnAttributes(column: Int) -> [ColumnAttribute] { | ||
var output: [ColumnAttribute] = [] | ||
for i in 0 ..< column { | ||
let alignment: TextAlignment = i % 2 == 0 ? .leading : .trailing | ||
let width: ColumnAttribute.Width = i % 2 == 0 ? .flexible : .fixed(80) | ||
let att = ColumnAttribute(textAlignment: alignment, width: width) | ||
output.append(att) | ||
} | ||
return output | ||
} | ||
|
||
static func generateData(row: Int, column: Int) -> TableModel { | ||
var res: [TableRowItem] = [] | ||
var titles: [DataTextItem] = [] | ||
for k in 0 ..< column { | ||
let title = k == 0 ? "" : "Long Header Title: \(k)" | ||
titles.append(DataTextItem(title)) | ||
} | ||
for i in 0 ..< row { | ||
res.append(self.generateRowData(count: column, for: i)) | ||
} | ||
let header = TableRowItem(leadingAccessories: [], trailingAccessory: nil, data: titles) | ||
let model = TableModel(headerData: header, rowData: res, isFirstRowSticky: true, isFirstColumnSticky: true, showListView: true) | ||
model.columnAttributes = self.generateColumnAttributes(column: 12) | ||
model.didSelectRowAt = { _ in | ||
print(model.selectedIndexes) | ||
} | ||
model.selectedIndexes = [2, 3] | ||
|
||
return model | ||
} | ||
} | ||
|
||
public struct DataTableExample: View { | ||
var model: TableModel = TestRowData.generateData(row: 30, column: 12) | ||
@State var isEditing: Bool = false | ||
|
||
public init() {} | ||
|
||
public var body: some View { | ||
makeBody() | ||
} | ||
|
||
func makeBody() -> some View { | ||
var view = DataTable(model: self.model) | ||
return | ||
NavigationView { | ||
view | ||
// .environmentObject(self.model) | ||
.navigationBarTitle("Data Table", displayMode: .inline) | ||
.navigationBarItems(leading: | ||
Button("Add a row") { | ||
DispatchQueue.main.async { | ||
self.model.rowData.insert(TestRowData.generateNewRow(column: 12), at: 0) | ||
} | ||
}, 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()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Foundation | ||
import SwiftUI | ||
|
||
public struct ColumnAttribute { | ||
public enum Width { | ||
case fixed(CGFloat) | ||
case flexible | ||
} | ||
|
||
public var textAlignment: TextAlignment = .leading | ||
public var width: Width = .flexible | ||
|
||
public init(textAlignment: TextAlignment = .leading, width: Width = .flexible) { | ||
self.textAlignment = textAlignment | ||
self.width = width | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import SwiftUI | ||
|
||
open class DataImageItem: DataItem { | ||
public var type: DataItemType | ||
public var mapping: ObjectViewProperty.Image? | ||
|
||
var image: Image | ||
|
||
public init(_ image: Image, _ mapping: ObjectViewProperty.Image? = nil) { | ||
self.image = image.resizable() | ||
self.type = .image | ||
self.mapping = mapping | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import SwiftUI | ||
|
||
// MARK: - Public Enums | ||
|
||
/// An enum representing the different item styles that a `FUIGridRowItem` can have. | ||
public enum DataItemType { | ||
/// Indicating this `FUIGridRowItem` represents a text. | ||
case text | ||
/// Indicating this `FUIGridRowItem` represents a image. | ||
case image | ||
} | ||
|
||
/// A protocol defines style of a `FUIGridRowItem`. | ||
public protocol DataItem: AnyObject { | ||
/// Returns the `FUIGridRowItemStyle` enum value for the item. | ||
var type: DataItemType { get } | ||
} | ||
|
||
public enum ObjectViewProperty { | ||
/// Binding definitions for text in object view layout | ||
public enum Text { | ||
/// Object view headline area | ||
case title | ||
/// Object view subheadline area | ||
case subtitle | ||
/// Object view footnote area | ||
case footnote | ||
/// Object view status area | ||
case status | ||
/// Object view substatus area | ||
case substatus | ||
} | ||
|
||
/// Binding definitions for images in object view layout | ||
public enum Image { | ||
/// Object view detailImage area | ||
case detailImage | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import SwiftUI | ||
|
||
public struct DataTable: View { | ||
@ObservedObject public var model: TableModel | ||
|
||
@Environment(\.horizontalSizeClass) var horizontalSizeClass | ||
@Environment(\.verticalSizeClass) var verticalSizeClass | ||
|
||
public var isEditing: Bool = false { | ||
didSet { | ||
self.model.isEditing = self.isEditing | ||
} | ||
} | ||
|
||
public init(model: TableModel) { | ||
self.model = model | ||
} | ||
|
||
public var body: some View { | ||
GeometryReader { proxy in | ||
self.makeBody(in: proxy.frame(in: .local)) | ||
} | ||
} | ||
|
||
func makeBody(in rect: CGRect) -> some View { | ||
let layoutManager = TableLayoutManager(model: self.model) | ||
let dataManager = TableDataManager(selectedIndexes: self.model.selectedIndexes) | ||
layoutManager.sizeClass = self.horizontalSizeClass ?? .compact | ||
layoutManager.rect = rect | ||
|
||
return Group { | ||
if self.horizontalSizeClass == .compact, self.verticalSizeClass == .regular, self.model.showListView { | ||
let listView = TableListView(layoutManager: layoutManager) | ||
listView | ||
} else { | ||
let gridView = GridTableView(layoutManager: layoutManager) | ||
gridView | ||
.frame(minWidth: 300, idealWidth: UIScreen.main.bounds.width, maxWidth: .infinity, minHeight: 300, idealHeight: UIScreen.main.bounds.height, maxHeight: .infinity, alignment: .center) | ||
.clipped() | ||
} | ||
} | ||
.environmentObject(layoutManager) | ||
.environmentObject(dataManager) | ||
} | ||
} |
Oops, something went wrong.