Closed KhusanM closed 2 years ago
Hi @KhusanM 👋🏼
Please could you provide more info about the version that you are using, how are you showing the skeleton...Because it's impossible to solve this issue :/
Xcode version 13.1 my code
import UIKit import SkeletonView
class OrderVC: UIViewController {
@IBOutlet weak var segmentController: UISegmentedControl!{
didSet{
let titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
let titleextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.gray]
segmentController.setTitleTextAttributes(titleextAttributes, for: .normal)
segmentController.setTitleTextAttributes(titleTextAttributes, for: .selected)
}
}
@IBOutlet var proccessBtns: [UIButton]!{
didSet{
for i in proccessBtns{
i.layer.cornerRadius = 16
}
}
}
@IBOutlet weak var tableView: UITableView!{
didSet{
tableView.dataSource = self
tableView.delegate = self
tableView.register(OrderTVC.nib(), forCellReuseIdentifier: OrderTVC.identifier)
tableView.separatorStyle = .none
tableView.isSkeletonable = true
if #available(iOS 15.0, *) {
tableView.sectionHeaderTopPadding = 0
} else {
// Fallback on earlier versions
}
}
}
@IBOutlet weak var topStack: UIStackView!
let refreshControl = UIRefreshControl()
private var lastContentOffset: CGFloat = 0
var isTrue = false
var didSearchPressed = false
var orderDM:[OrderDM] = []
var fetchData:[OrderDM] = []
var currentPage: Int = 1
var isLoadingList: Bool = true
var type = "seller"
var totalItems = 10
var state = "pending"
override func viewDidLoad() {
super.viewDidLoad()
proccessBtns[0].backgroundColor = AppColors.customGray5
setUpNavigation()
getOrders(withLoader: true)
refreshControl.addTarget(self, action: #selector(self.refresh(_:)), for: .valueChanged)
tableView.addSubview(refreshControl)
}
private func getOrders(withLoader: Bool) {
if withLoader {
tableView.showAnimatedSkeleton()
}
API.getOrderPaging(limit: totalItems, page: currentPage, type: type, state: state) { orderDM, countLoader in
guard let orderDM = orderDM else {return self.tableView.hideSkeleton()}
for i in orderDM {
self.orderDM.append(i)
}
self.isLoadingList = !(countLoader == self.totalItems)
self.tableView.hideSkeleton()
self.tableView.reloadData()
}
}
@objc func refresh(_ sender: AnyObject) {
currentPage = 1
fetchData.removeAll()
orderDM.removeAll()
getOrders(withLoader: false)
self.refreshControl.endRefreshing()
}
@objc func onDidReceiveData() {
}
func observeNotification() {
NotificationCenter.default.addObserver(self, selector: #selector(onDidReceiveData), name: NSNotification.Name.init(Keys.LANGUAGENOTIFICATION), object: nil)
}
@IBAction func switchToggled(_ sender: UISwitch) {
isTrue = !isTrue
tableView.reloadData()
}
@IBAction func segmentChanged(_ sender: UISegmentedControl) {
currentPage = 1
fetchData.removeAll()
orderDM.removeAll()
if sender.selectedSegmentIndex == 0{
//Seller
type = "seller"
getOrders(withLoader: true)
}else {
//Buyer
type = "buyer"
getOrders(withLoader: true)
}
}
@IBAction func proccessBtnsPressed(_ sender: UIButton) {
for btn in proccessBtns{
btn.backgroundColor = .clear
}
fetchData.removeAll()
orderDM.removeAll()
if sender.tag == 0{
proccessBtns[0].backgroundColor = AppColors.customGray5
self.state = "pending"
}else if sender.tag == 1{
proccessBtns[1].backgroundColor = AppColors.customGray5
self.state = "inProgress"
}else{
proccessBtns[2].backgroundColor = AppColors.customGray5
self.state = "done"
}
self.getOrders(withLoader: true)
}
}
//MARK:TABLE VIEW extension OrderVC:UITableViewDelegate,SkeletonTableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return orderDM.count
}
// func numberOfSections(in tableView: UITableView) -> Int { // return orderDM.count // }
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: OrderTVC.identifier, for: indexPath) as! OrderTVC
if !orderDM.isEmpty {
cell.updateCell(didCollapse: isTrue, dm: orderDM[indexPath.row])
}
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let vc = OrderDetailVC(nibName: "OrderDetailVC", bundle: nil)
vc.hidesBottomBarWhenPushed = true
vc.orderDM = orderDM[indexPath.row]
navigationController?.pushViewController(vc, animated: true)
}
// func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { // // let label = UILabel() // label.backgroundColor = .clear // label.text = String.dateToString(date: orderDM[section].created_at, format: "dd.MM.YYYY") // label.textColor = AppColors.customGray // label.textAlignment = .left // label.font = UIFont.systemFont(ofSize: 12,weight: .regular) // // let containerView = UIView() // containerView.addSubview(label) // containerView.backgroundColor = .white // // label.snp.makeConstraints { make in // make.bottom.equalTo(-8) // make.left.equalTo(15) // make.right.equalTo(-15) // make.top.equalTo(8) // } // return containerView // }
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
lastContentOffset = scrollView.contentOffset.y
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if lastContentOffset > scrollView.contentOffset.y + 50 {
UIView.animate(withDuration: 0.25, animations: {
self.topStack.alpha = 1.0
}) { _ in
self.topStack.isHidden = false
}
} else if lastContentOffset + 50 < scrollView.contentOffset.y {
UIView.animate(withDuration: 0.25, animations: {
self.topStack.alpha = 0
}) { _ in
self.topStack.isHidden = true
}
}
//PAGINATION
if (((scrollView.contentOffset.y + scrollView.frame.size.height) > scrollView.contentSize.height ) && !isLoadingList){
self.isLoadingList = true
self.currentPage += 1
self.getOrders(withLoader: false)
}
}
//SKELETON
func collectionSkeletonView(_ skeletonView: UITableView, cellIdentifierForRowAt indexPath: IndexPath) -> ReusableCellIdentifier {
return OrderTVC.identifier
}
func collectionSkeletonView(_ skeletonView: UITableView, numberOfRowsInSection section: Int) -> Int {
12
}
}
please help me!
Hi @KhusanM, could you update to the latest version (1.29.1) the library and take a look at this issue, please?
🤖 This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions 🙂
https://user-images.githubusercontent.com/86423467/143032973-f7b4a0b0-f7be-44a6-bcd0-ada9cb681f87.mp4