Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REFACT :: [#338] 자세 - Flow RF #339

Merged
merged 6 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions Projects/Features/PostureFeature/Demo/Sources/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {

window = UIWindow(frame: scene.coordinateSpace.bounds)
window?.windowScene = scene

let useCase = DefaultPostureUseCase(repository: PostureRepository(networkService: PostureService()))
let viewModel = PostureDetailViewModel(useCase: useCase)
let viewController = PostureDetailViewController(viewModel)

window?.rootViewController = viewController

// mainFlow = PostureFlow()
//
// coordinator.coordinate(flow: mainFlow, with: OneStepper(withSingleStep: MGStep.postureDetailIsRequired(withDetailId: 0)))
// Flows.use(mainFlow, when: .created) { root in
// self.window?.rootViewController = root
// self.window?.makeKey()
// }
//
// let useCase = DefaultPostureUseCase(repository: PostureRepository(networkService: PostureService()))
// let viewModel = PostureDetailViewModel(useCase: useCase)
// let viewController = PostureDetailViewController(viewModel)
//
// window?.rootViewController = viewController

mainFlow = PostureFlow()

coordinator.coordinate(flow: mainFlow, with: OneStepper(withSingleStep: MGStep.postureMainIsRequired))
Flows.use(mainFlow, when: .created) { root in
self.window?.rootViewController = root
self.window?.makeKey()
}
window?.makeKeyAndVisible()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import UIKit
import Data

import RxCocoa
import RxSwift
Expand All @@ -11,12 +12,15 @@ import DSKit
import Core
import Domain

import MGNetworks

import PostureFeatureInterface

public class PostureMainViewController: BaseViewController<PostureMainViewModel>, Stepper {

private lazy var naviBar = PostureMainNavigationBar()

let rootViewController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)


private let categoryTitleList = [
Expand All @@ -26,7 +30,9 @@ public class PostureMainViewController: BaseViewController<PostureMainViewModel>
"어깨",
"팔",
"복근",
"앞 허벅지"
"앞 허벅지",
"뒷 허벅지",
"종아리"
]

private let titleText = MGLabel(text: "자세",
Expand All @@ -43,27 +49,22 @@ public class PostureMainViewController: BaseViewController<PostureMainViewModel>

private lazy var pagingTabBar = MGPagingTabBar(categoryTitleList: categoryTitleList)

// lazy var recommandUseCase = DefaultPostureUseCase(repository: PostureRepository(networkService: PostureService()))
// lazy var recommandViewModel = PostureRecommandViewModel(useCase: recommandUseCase)
// lazy var recommandViewController = PostureRecommandViewController(recommandViewModel)

// lazy var chestUseCase = DefaultPostureUseCase(repository: PostureRepository(networkService: PostureService()))
// lazy var chestUseCase = PostureUseCase()
// lazy var chestViewModel = PostureChestViewModel(useCase: chestUseCase)
// lazy var chestViewController = PostureChestViewController(chestViewModel)
//
// lazy var backUseCase = DefaultPostureUseCase(repository: PostureRepository(networkService: PostureService()))
// lazy var backViewModel = PostureBackViewModel(useCase: backUseCase)
// lazy var backViewController = PostureBackViewController(backViewModel)
lazy var postureUseCase = DefaultPostureUseCase(repository: PostureRepository(networkService: PostureService()))

lazy var recommandViewController = PostureRecommandViewController(PostureRecommandViewModel(useCase: postureUseCase))
lazy var chestViewController = PostureChestViewController(PostureChestViewModel(useCase: postureUseCase))
lazy var backViewController = PostureBackViewController(PostureBackViewModel(useCase: postureUseCase))

private lazy var viewControllers: [UIViewController] = [
// recommandViewController,
// chestViewController,
// backViewController,
// backViewController,
// backViewController,
// backViewController,
// backViewController,
recommandViewController,
chestViewController,
backViewController,
backViewController,
backViewController,
backViewController,
backViewController,
backViewController,
backViewController,
]

private lazy var containerView: UIView = {
Expand Down Expand Up @@ -101,9 +102,9 @@ public class PostureMainViewController: BaseViewController<PostureMainViewModel>
}

pagingTabBar.snp.makeConstraints {
$0.top.equalTo(titleText.snp.bottom).offset(12.0)
$0.leading.trailing.equalToSuperview()
$0.height.equalTo(pagingTabBar.cellHeight)
$0.top.equalTo(titleText.snp.bottom).offset(12.0)
$0.leading.trailing.equalToSuperview()
$0.height.equalTo(56.0)
}

containerView.snp.makeConstraints {
Expand Down Expand Up @@ -139,9 +140,6 @@ public class PostureMainViewController: BaseViewController<PostureMainViewModel>
super.bindViewModel()

let searchButtonTapped = naviBar.rightButtonTap.asDriver(onErrorDriveWith: .never())
// let useCase = DefaultPostureUseCase(repository: PostureRepository(networkService: PostureService()))
//
// viewModel = PostureMainViewModel(useCase: useCase)

let input = PostureMainViewModel.Input(
searchButtonTapped: searchButtonTapped
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "recommandChestIcon.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "recommandShoulderIcon.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import Then
import SnapKit

public class MGPagingTabBar: UIView {

public var cellHeight: CGFloat { 36.0 }


private var categoryTitleList: [String]

public let selectedIndex = PublishSubject<Int>()
Expand All @@ -19,20 +17,16 @@ public class MGPagingTabBar: UIView {
public lazy var collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal

let inset: CGFloat = 0.0
let cellWidth: CGFloat = (UIScreen.main.bounds.width - inset * 2) / CGFloat(min(categoryTitleList.count, 7))
layout.itemSize = CGSize(width: cellWidth, height: cellHeight)
layout.minimumLineSpacing = 0.0
layout.minimumInteritemSpacing = 0.0
layout.sectionInset = UIEdgeInsets(top: 0, left: inset, bottom: 0, right: inset)
layout.minimumLineSpacing = 16
layout.minimumInteritemSpacing = 16.0
layout.sectionInset = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)

let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)

collectionView.backgroundColor = .systemBackground
collectionView.showsHorizontalScrollIndicator = false
collectionView.bounces = false

collectionView.backgroundColor = .clear
collectionView.register(MGPagingTabBarCell.self,
forCellWithReuseIdentifier:
MGPagingTabBarCell.identifier)
Expand All @@ -51,6 +45,19 @@ public class MGPagingTabBar: UIView {
return collectionView
}()

private lazy var grayUnderline = UIView().then {
$0.backgroundColor = DSKitAsset.Colors.gray50.color
$0.alpha = 1.0
}

private func calculateCellWidth(text: String) -> Double {
let nonSpaceCount = text.filter { !$0.isWhitespace }.count
let spaceCount = text.filter { $0.isWhitespace }.count

let textWidth = Double((Double(nonSpaceCount) * 18) + (Double(spaceCount) * 5) + 8)
return textWidth
}

public init(categoryTitleList: [String]) {
self.categoryTitleList = categoryTitleList
super.init(frame: .zero)
Expand All @@ -67,17 +74,31 @@ public class MGPagingTabBar: UIView {
strongSelf.selectedIndex.onNext(indexPath.row)
}).disposed(by: self.disposeBag)

collectionView.rx.setDelegate(self)
.disposed(by: disposeBag)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}


}

extension MGPagingTabBar: UICollectionViewDelegateFlowLayout {
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
collectionView.scrollToItem(at: indexPath, at: .centeredHorizontally, animated: true)
}

public func collectionView(
_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAt indexPath: IndexPath
) -> CGSize {
let cellWidth = calculateCellWidth(text: categoryTitleList[indexPath.row])
print("\(indexPath.row) : height = \(cellWidth)")
return CGSize(width: cellWidth, height: 56.0)
}
}

extension MGPagingTabBar: UICollectionViewDataSource {
Expand All @@ -98,9 +119,15 @@ extension MGPagingTabBar: UICollectionViewDataSource {

private extension MGPagingTabBar {
func setupLayout() {
addSubview(grayUnderline)
addSubview(collectionView)
collectionView.snp.makeConstraints {
$0.edges.equalToSuperview()
}

grayUnderline.snp.makeConstraints {
$0.leading.trailing.bottom.equalToSuperview()
$0.height.equalTo(2.0)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ public class MGPagingTabBarCell: UICollectionViewCell {
$0.textColor = DSKitAsset.Colors.gray400.color
$0.textAlignment = .center
}

private lazy var grayUnderline = UIView().then {
$0.backgroundColor = DSKitAsset.Colors.gray50.color
$0.alpha = 1.0
}

private lazy var underline = UIView().then {
$0.backgroundColor = DSKitAsset.Colors.blue500.color
Expand All @@ -39,23 +34,16 @@ private extension MGPagingTabBarCell {
func setupLayout() {
[
titleLabel,
grayUnderline,
underline
].forEach { addSubview($0) }
titleLabel.snp.makeConstraints { make in
make.leading.top.trailing.equalToSuperview()
}

grayUnderline.snp.makeConstraints { make in
make.height.equalTo(2.0)
make.top.equalTo(titleLabel.snp.bottom).offset(4.0)
make.leading.trailing.bottom.equalToSuperview()
}

underline.snp.makeConstraints { make in
make.height.equalTo(2.0)
make.top.equalTo(titleLabel.snp.bottom).offset(4.0)
make.leading.trailing.equalToSuperview().inset(14.0)
make.leading.trailing.equalToSuperview()
make.bottom.equalToSuperview()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class PostureService {
Single<[PostureRecommandModel]> {
let postureRecommandData: [PostureRecommandModel] = [
PostureRecommandModel(
titleImage: DSKitAsset.Assets.appleLogo.image,
titleImage: DSKitAsset.Assets.recommandChestIcon.image,
titleText: "가슴 운동",
exerciseData: [
PostureRecommandExerciseModel(image: DSKitAsset.Assets.pushUp.image, name: "푸시업", part: "가슴"),
Expand All @@ -19,7 +19,7 @@ public class PostureService {
]
),
PostureRecommandModel(
titleImage: DSKitAsset.Assets.appleLogo.image,
titleImage: DSKitAsset.Assets.recommandShoulderIcon.image,
titleText: "어깨 운동",
exerciseData: [
PostureRecommandExerciseModel(image: DSKitAsset.Assets.deeps.image, name: "딥스", part: "가슴"),
Expand Down
Loading