For this demo, we will require the following SAP frameworks.
import SwiftUI
import SAPFiori
struct FilterTableView {
// MARK: - Properties
typealias UIViewType = UITableView
let tableView = UITableView(frame: .zero, style: .plain)
}
// MARK: - UIViewRepresentable
extension FilterTableView: UIViewRepresentable {
func makeUIView(context: Context) -> UITableView {
setupDatasourceDelegate(context)
setupTable()
return tableView
}
func updateUIView(_ uiView: UITableView, context: Context) { }
func makeCoordinator() -> FilterTableViewCoordinator {
FilterTableViewCoordinator(self)
}
}
// MARK: - Private
private extension FilterTableView {
func setupTable() {
tableView.estimatedRowHeight = 80
tableView.rowHeight = UITableView.automaticDimension
tableView.register(FUIFilterFormCell.self, forCellReuseIdentifier: FUIFilterFormCell.reuseIdentifier)
tableView.separatorStyle = .none
}
func setupDatasourceDelegate(_ context: Context) {
tableView.dataSource = context.coordinator
tableView.delegate = context.coordinator
}
}
// MARK: - Coordinator
class FilterTableViewCoordinator: NSObject {
// MARK: - Properties
var parent: FilterTableView
var selectedValues = [1]
// MARK: - Initialization
init(_ parent: FilterTableView) {
self.parent = parent
}
}
// MARK: - UITableViewDataSource, UITableViewDelegate
extension FilterTableViewCoordinator: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1 // return number of rows of data source
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let filterFormCell = tableView.dequeueReusableCell(withIdentifier: FUIFilterFormCell.reuseIdentifier, for: indexPath) as! FUIFilterFormCell
filterFormCell.valueOptions = ["Option 1", "Option 2", "Option 3", "Option 4"]
filterFormCell.keyName = "Filter Options"
filterFormCell.allowsMultipleSelection = true
filterFormCell.value = selectedValues
filterFormCell.allowsEmptySelection = true
filterFormCell.onChangeHandler = { newValue in
self.selectedValues = newValue
filterFormCell.setSelected(true, animated: true)
}
return filterFormCell
}
}
import SwiftUI
struct ContentView: View {
// MARK: - Body
var body: some View {
NavigationView {
FilterTableView()
.navigationBarTitle("NSS Stylesheet Demo", displayMode: .inline)
}
.navigationViewStyle(StackNavigationViewStyle())
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
filterFormCell.setTintColor(UIColor.orange, for: .normal)
fdlFUIFilterFormCell_item_titleLabel {
font-color: #BB0000;
}
fdlFUIFilterFormCell_item_titleLabel_selected {
font-color: #2B7D2B;
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
NUISettings.initWithStylesheet(name: "Theme")
return true
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
28 | |
14 | |
12 | |
11 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 |