Skip to content

Commit

Permalink
Added new section header (microsoft#270)
Browse files Browse the repository at this point in the history
* moving some files around so saving some progress

* Added new header styles

* Added chevron assets

* Updated new section header PR

* Added changes

* Added changes

* Added changes

* Added changes

* Added changes

* Removed extra line

* Added changes
  • Loading branch information
sophialee0416 authored Oct 24, 2020
1 parent 378f63b commit ab4610e
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class TableViewHeaderFooterViewDemoController: DemoController {
}()
private lazy var groupedTableView: UITableView = createTableView(style: .grouped)
private lazy var plainTableView: UITableView = createTableView(style: .plain)
private var collapsedSections: [Bool] = [Bool](repeating: false, count: TableViewHeaderFooterSampleData.groupedSections.count)

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -59,7 +60,7 @@ extension TableViewHeaderFooterViewDemoController: UITableViewDataSource {
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return TableViewHeaderFooterSampleData.numberOfItemsInSection
return collapsedSections[section] ? 0 : TableViewHeaderFooterSampleData.numberOfItemsInSection
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
Expand Down Expand Up @@ -88,11 +89,16 @@ extension TableViewHeaderFooterViewDemoController: UITableViewDelegate {

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header = tableView.dequeueReusableHeaderFooterView(withIdentifier: TableViewHeaderFooterView.identifier) as! TableViewHeaderFooterView
let index = section
let section = tableView.style == .grouped ? groupedSections[section] : plainSections[section]
if section.hasHandler {
header.onHeaderViewTapped = { [weak self] in self?.forHeaderTapped(header: header, section: index) }
}

if section.hasCustomAccessoryView {
header.setup(style: section.headerStyle, title: section.title, accessoryView: createCustomAccessoryView())
header.setup(style: section.headerStyle, title: section.title, accessoryView: createCustomAccessoryView(), leadingView: section.hasCustomLeadingView ? createCustomLeadingView(section: index) : nil)
} else {
header.setup(style: section.headerStyle, title: section.title, accessoryButtonTitle: section.hasAccessory ? "See More" : "")
header.setup(style: section.headerStyle, title: section.title, accessoryButtonTitle: section.hasAccessory ? "See More" : "", leadingView: section.hasCustomLeadingView ? createCustomLeadingView(section: index) : nil)
}

header.titleNumberOfLines = section.numberOfLines
Expand All @@ -109,6 +115,11 @@ extension TableViewHeaderFooterViewDemoController: UITableViewDelegate {
return button
}

private func createCustomLeadingView(section: Int) -> UIView {
let imageName = collapsedSections[section] ? "chevron-right-20x20" : "chevron-down-20x20"
return UIImageView(image: UIImage(named: imageName))
}

func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
if tableView.style == .grouped && groupedSections[section].hasFooter {
let footer = tableView.dequeueReusableHeaderFooterView(withIdentifier: TableViewHeaderFooterView.identifier) as! TableViewHeaderFooterView
Expand Down Expand Up @@ -143,6 +154,11 @@ extension TableViewHeaderFooterViewDemoController: UITableViewDelegate {
alert.addAction(action)
present(alert, animated: true)
}

private func forHeaderTapped(header: TableViewHeaderFooterView, section: Int) {
collapsedSections[section] = !collapsedSections[section]
groupedTableView.reloadSections(IndexSet(integer: section), with: UITableView.RowAnimation.fade)
}
}

// MARK: - TableViewHeaderFooterViewDemoController: TableViewHeaderFooterViewDelegate
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_chevron_down_20_outlined.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_chevron_right_20_outlined.pdf",
"language-direction" : "left-to-right"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class TableViewHeaderFooterSampleData: TableViewSampleData {
static let itemTitle: String = "Contoso Survey"

static let groupedSections: [Section] = [
Section(title: "Primary Title", headerStyle: .headerPrimary),
Section(title: "Primary Expandable", headerStyle: .headerPrimary, hasCustomLeadingView: true, hasHandler: true),
Section(title: "Default"),
Section(title: "Default with accessory button", hasAccessory: true),
Section(title: "Default with primary accessory button", hasAccessory: true, accessoryButtonStyle: .primary),
Expand Down
6 changes: 5 additions & 1 deletion ios/FluentUI.Demo/FluentUI.Demo/TableViewSampleData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ class TableViewSampleData {
let footerLinkText: String
let hasCustomLinkHandler: Bool
let hasCustomAccessoryView: Bool
let hasCustomLeadingView: Bool
let hasHandler: Bool

init(title: String, items: [Item] = [], numberOfLines: Int = 1, hasFullLengthLabelAccessoryView: Bool = false, hasAccessory: Bool = false, accessoryButtonStyle: TableViewHeaderFooterView.AccessoryButtonStyle = .regular, allowsMultipleSelection: Bool = true, headerStyle: TableViewHeaderFooterView.Style = .header, hasFooter: Bool = false, footerText: String = "", footerLinkText: String = "", hasCustomLinkHandler: Bool = false, hasCustomAccessoryView: Bool = false) {
init(title: String, items: [Item] = [], numberOfLines: Int = 1, hasFullLengthLabelAccessoryView: Bool = false, hasAccessory: Bool = false, accessoryButtonStyle: TableViewHeaderFooterView.AccessoryButtonStyle = .regular, allowsMultipleSelection: Bool = true, headerStyle: TableViewHeaderFooterView.Style = .header, hasFooter: Bool = false, footerText: String = "", footerLinkText: String = "", hasCustomLinkHandler: Bool = false, hasCustomAccessoryView: Bool = false, hasCustomLeadingView: Bool = false, hasHandler: Bool = false) {
self.title = title
self.items = items
self.numberOfLines = numberOfLines
Expand All @@ -37,6 +39,8 @@ class TableViewSampleData {
self.footerLinkText = footerLinkText
self.hasCustomLinkHandler = hasCustomLinkHandler
self.hasCustomAccessoryView = hasCustomAccessoryView
self.hasCustomLeadingView = hasCustomLeadingView
self.hasHandler = hasHandler
}
}

Expand Down
Loading

0 comments on commit ab4610e

Please sign in to comment.