Skip to content

Commit

Permalink
[Feat] #222 - ClipVC SkeletonView 세팅
Browse files Browse the repository at this point in the history
  • Loading branch information
mini-min committed Oct 19, 2024
1 parent 9dbba48 commit a818c1d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import UIKit

import SkeletonView
import SnapKit
import Then

Expand All @@ -27,6 +28,7 @@ final class ClipListCollectionViewCell: UICollectionViewCell {
setupStyle()
setupHierarchy()
setupLayout()
setupSkeleton()
}

required init?(coder: NSCoder) {
Expand Down Expand Up @@ -106,4 +108,11 @@ private extension ClipListCollectionViewCell {
$0.size.equalTo(20)
}
}

func setupSkeleton() {
isSkeletonable = true
[clipImage, clipNameLabel, countLabel, arrowImage].forEach {
$0.isSkeletonable = true
}
}
}
18 changes: 17 additions & 1 deletion TOASTER-iOS/Present/Clip/View/ClipViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import UIKit

import SkeletonView
import SnapKit
import Then

Expand Down Expand Up @@ -79,6 +80,7 @@ private extension ClipViewController {

func setupViewModel() {
viewModel.setupDataChangeAction(changeAction: reloadCollectionView,
loadingAction: setupSkeleton,
forUnAuthorizedAction: unAuthorizedAction,
editAction: addClipAction,
moveAction: moveBottomAction)
Expand All @@ -89,6 +91,16 @@ private extension ClipViewController {
clipEmptyView.isHidden = isHidden
}

func setupSkeleton(isLoading: Bool) {
clipListCollectionView.isSkeletonable = true
if isLoading {
clipEmptyView.isHidden = true
clipListCollectionView.showAnimatedGradientSkeleton()
} else {
clipListCollectionView.hideSkeleton()
}
}

func unAuthorizedAction() {
changeViewController(viewController: LoginViewController())
}
Expand Down Expand Up @@ -148,7 +160,11 @@ extension ClipViewController: UICollectionViewDelegate {

// MARK: - CollectionView DataSource

extension ClipViewController: UICollectionViewDataSource {
extension ClipViewController: SkeletonCollectionViewDataSource {
func collectionSkeletonView(_ skeletonView: UICollectionView, cellIdentifierForItemAt indexPath: IndexPath) -> SkeletonView.ReusableCellIdentifier {
return ClipListCollectionViewCell.className
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return viewModel.clipList.clips.count + 1
}
Expand Down
11 changes: 8 additions & 3 deletions TOASTER-iOS/Present/Clip/ViewModel/ClipViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ final class ClipViewModel: NSObject {

typealias DataChangeAction = (Bool) -> Void
private var dataChangeAction: DataChangeAction?
private var loadingStatusAction: DataChangeAction?
private var moveBottomAction: DataChangeAction?

typealias NormalChangeAction = () -> Void
private var unAuthorizedAction: NormalChangeAction?
private var textFieldEditAction: NormalChangeAction?

// MARK: - Data

private(set) var clipList: ClipModel = ClipModel(allClipToastCount: 0, clips: []) {
Expand All @@ -32,24 +33,28 @@ final class ClipViewModel: NSObject {

extension ClipViewModel {
func setupDataChangeAction(changeAction: @escaping DataChangeAction,
loadingAction: @escaping DataChangeAction,
forUnAuthorizedAction: @escaping NormalChangeAction,
editAction: @escaping NormalChangeAction,
moveAction: @escaping DataChangeAction) {
dataChangeAction = changeAction
loadingStatusAction = loadingAction
unAuthorizedAction = forUnAuthorizedAction
textFieldEditAction = editAction
moveBottomAction = moveAction
}

func getAllCategoryAPI() {
loadingStatusAction?(true)
NetworkService.shared.clipService.getAllCategory { [weak self] result in
self?.loadingStatusAction?(false)
switch result {
case .success(let response):
let allClipToastCount = response?.data.toastNumberInEntire
let clips = response?.data.categories.map {
AllClipModel(id: $0.categoryId,
title: $0.categoryTitle,
toastCount: $0.toastNum)
title: $0.categoryTitle,
toastCount: $0.toastNum)
}
self?.clipList = ClipModel(allClipToastCount: allClipToastCount ?? 0,
clips: clips ?? [])
Expand Down

0 comments on commit a818c1d

Please sign in to comment.