Swiftpack.co - Package - bagusandinata/BAStateTableView

BAStateTableView developed for developers when they get confused in tableview state management for set loading data, empty data, and available data.

alt text

:star2: Feature

  • ☑ State Loading
  • ☑ State Empty Data
  • ☑ State Available Data
  • ☑ Basic Loading View
  • ☑ Custom Loading View
  • ☑ Skeleton Loading View

:calling: Installation

Using Swift Package Manager

Once you have your Swift package set up, adding BAStateTableView as a dependency is as easy as adding it to the dependencies value of your Package.swift

dependencies: [
    .package(url: "https://github.com/bagusandinata/BAStateTableView.git", from: "1.0.6")
]

:hotsprings: How to use

1. Set custom class BAStateTableView in UITableView IB/Storyboards.

alt text

2. Import BAStateTableView in proper place.

import BAStateTableView

3. Using state basic loading.

Default basic loading
tableView.setState(.loading())
Custom basic loading
tableView.setState(.loading(indicatorWidth: 100, indicatorHeight: 100, indicatorColor: .gray, backgroundColor: .white))

4. Using state custom loading.

tableView.ba_loadingView = UIView.nib(withType: CustomLoadingView.self)
tableView.setState(.customLoadingView)

5. Using state skeleton loading.

Please set view skeletonable active in cell
* Using code:
view.isSkeletonable = true
view.skeletonCornerRadius = 10 (Optional)
* Using IB/Storyboards::

alt text

You can setup custom skeleton animation
tableView.config = SkeletonConfig(colors: SkeletonGradient(baseColor: .gray).colors, gradientDirection: .leftRight, animationDuration: 1.5, transitionShow: .none, transitionHide: .crossDissolve(2.5))
When you use skeleton loading set UITableViewDataSource
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    switch (tableView as! BAStateTableView).currentState {
        case .availableData:
            return data.count
        case .skeletonLoading:
            return 10
        default:
            return 0
    }
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueCell(with: ExampleCell.self, indexPath: indexPath)!
        
    switch (tableView as! BAStateTableView).currentState {
        case .availableData:
            cell.labelExample.text = data.exampleText
            return cell
        default:
            return cell
    }
}

6. Using state custom empty data.

tableView.ba_emptyView = UIView.nib(withType: EmptyView.self)
tableView.setState(.emptyData)

7. Using state custom available data.

tableView.setState(.availableData)

Github

link
Stars: 0

Dependencies

Used By

Total: 0

Releases

- 2020-08-24 02:47:53

Fix

  • Some bugs

- 2020-08-23 14:29:12

Fix

  • Skeleton corners

- 2020-08-22 18:57:02

Fix

  • Performance
  • State available data

Feature

  • Transition show skeleton loading
  • Transition hide skeleton loading

- 2020-08-19 07:40:06

Fix

  • Position PackageManager

- 2020-08-19 04:42:40

Feature

  • Default loading view
  • Custom loading view
  • Skeleton loading view
  • Empty data view
  • Available data