Skip to content

Commit

Permalink
Fix access control at CollapseTableView Increase version number
Browse files Browse the repository at this point in the history
  • Loading branch information
Kharauzov committed Jun 8, 2019
1 parent fb3dc6b commit ea27bf2
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 89 deletions.
20 changes: 2 additions & 18 deletions CollapseTableView.podspec
Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
Pod::Spec.new do |s|

# 1

s.platform = :ios
s.ios.deployment_target = '10.0'
s.name = "CollapseTableView"
s.summary = "CollapseTableView enables to expand sections with cells inside."
s.requires_arc = true

# 2
s.version = "1.0.0"

# 3
s.version = "1.0.1"
s.license = { :type => "MIT", :file => "LICENSE" }

# 4 - Replace with your name and e-mail address
s.author = { "Serhii Kharauzov" => "serhii.kharauzov@gmail.com" }

# 5 - Replace this URL with your own GitHub page's URL (from the address bar)
s.homepage = "https://github.com/Kharauzov/CollapseTableView"

# 6 - Replace this URL with your own Git URL from "Quick Setup"
s.source = { :git => "https://github.com/Kharauzov/CollapseTableView.git",
:tag => s.version }

# 7
s.framework = "UIKit"

# 8
s.source_files = "CollapseTableView/**/*.{swift}"

# 10
s.swift_version = "5.0"

end
2 changes: 1 addition & 1 deletion CollapseTableView/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<string>1.0.1</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
</dict>
Expand Down
139 changes: 69 additions & 70 deletions CollapseTableView/Source/CollapseTableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,70 +57,10 @@ open class CollapseTableView: UITableView {
}
return super.responds(to: aSelector) || collapseDataSource?.responds(to: aSelector) ?? false || collapseDelegate?.responds(to: aSelector) ?? false
}
}

// MARK: UITableViewDataSource

extension CollapseTableView: UITableViewDataSource {
public func numberOfSections(in tableView: UITableView) -> Int {
let numberOfSections = collapseDataSource.numberOfSections?(in: tableView) ?? 0
while numberOfSections < sectionStates.count {
sectionStates.removeAll()
}
while numberOfSections > sectionStates.count {
sectionStates.append(false)
}
return numberOfSections
}

public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if sectionStates[section] {
return collapseDataSource.tableView(tableView, numberOfRowsInSection: section)
}
return 0
}
// MARK: Public methods

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
return collapseDataSource.tableView(tableView, cellForRowAt: indexPath)
}
}

// MARK: UITableViewDelegate

extension CollapseTableView: UITableViewDelegate {
public func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
guard let view = collapseDelegate.tableView?(tableView, viewForHeaderInSection: section) else {
return nil
}
if shouldHandleHeadersTap {
let gestures = view.gestureRecognizers ?? []
var tapGestureFound = false
for gesture in gestures {
if gesture.isKind(of: UITapGestureRecognizer.self) {
tapGestureFound = true
break
}
}
if !tapGestureFound {
view.tag = section
view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleTapGesture(_:))))
}
}
return view
}
}

// MARK: CollapseTableView methods

extension CollapseTableView {
@objc func handleTapGesture(_ sender: UITapGestureRecognizer) {
guard let view = sender.view, view.tag >= 0 else {
return
}
toggleSection(view.tag, sectionView: view, animated: true)
}

func toggleSection(_ sectionIndex: Int, sectionView: UIView, animated: Bool) {
public func toggleSection(_ sectionIndex: Int, sectionView: UIView, animated: Bool) {
if sectionIndex >= sectionStates.count {
return
}
Expand All @@ -137,7 +77,7 @@ extension CollapseTableView {
}
}

func openSection(_ sectionIndex: Int, animated: Bool) {
public func openSection(_ sectionIndex: Int, animated: Bool) {
if sectionIndex >= sectionStates.count || sectionStates[sectionIndex] {
return
}
Expand All @@ -151,7 +91,7 @@ extension CollapseTableView {
}
}

func closeSection(_ sectionIndex: Int, animated: Bool) {
public func closeSection(_ sectionIndex: Int, animated: Bool) {
setSectionAtIndex(sectionIndex, open: false)
if animated {
if let indexPathsToDelete = indexPathsForRowsInSectionAtIndex(sectionIndex) {
Expand All @@ -162,14 +102,23 @@ extension CollapseTableView {
}
}

func setSectionAtIndex(_ sectionIndex: Int, open: Bool) {
public func isOpenSection(_ sectionIndex: Int) -> Bool {
if sectionIndex >= sectionStates.count {
return false
}
return sectionStates[sectionIndex]
}

// MARK: Private methods

private func setSectionAtIndex(_ sectionIndex: Int, open: Bool) {
if sectionIndex >= sectionStates.count {
return
}
sectionStates[sectionIndex] = open
}

func indexPathsForRowsInSectionAtIndex(_ sectionIndex: Int) -> [IndexPath]? {
private func indexPathsForRowsInSectionAtIndex(_ sectionIndex: Int) -> [IndexPath]? {
if sectionIndex >= sectionStates.count {
return nil
}
Expand All @@ -181,11 +130,61 @@ extension CollapseTableView {
return array
}

func isOpenSection(_ sectionIndex: Int) -> Bool {
if sectionIndex >= sectionStates.count {
return false
@objc private func handleTapGesture(_ sender: UITapGestureRecognizer) {
guard let view = sender.view, view.tag >= 0 else {
return
}
return sectionStates[sectionIndex]
toggleSection(view.tag, sectionView: view, animated: true)
}
}

// MARK: UITableViewDataSource

extension CollapseTableView: UITableViewDataSource {
public func numberOfSections(in tableView: UITableView) -> Int {
let numberOfSections = collapseDataSource.numberOfSections?(in: tableView) ?? 0
while numberOfSections < sectionStates.count {
sectionStates.removeAll()
}
while numberOfSections > sectionStates.count {
sectionStates.append(false)
}
return numberOfSections
}

public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if sectionStates[section] {
return collapseDataSource.tableView(tableView, numberOfRowsInSection: section)
}
return 0
}

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
return collapseDataSource.tableView(tableView, cellForRowAt: indexPath)
}
}

// MARK: UITableViewDelegate

extension CollapseTableView: UITableViewDelegate {
public func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
guard let view = collapseDelegate.tableView?(tableView, viewForHeaderInSection: section) else {
return nil
}
if shouldHandleHeadersTap {
let gestures = view.gestureRecognizers ?? []
var tapGestureFound = false
for gesture in gestures {
if gesture.isKind(of: UITapGestureRecognizer.self) {
tapGestureFound = true
break
}
}
if !tapGestureFound {
view.tag = section
view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleTapGesture(_:))))
}
}
return view
}
}

0 comments on commit ea27bf2

Please sign in to comment.