Skip to content

Commit

Permalink
[Feat] CompanyMentorCollectionViewCell (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ohjackson committed Nov 25, 2024
1 parent 82d2333 commit fcd3b96
Show file tree
Hide file tree
Showing 2 changed files with 270 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//
// ChatReSearchButtonView.swift
// LINKAREER-iOS
//
// Created by Jaehyun Ahn on 11/25/24.
//

import UIKit

import SnapKit
import Then

final class ChatReSearchButtonView: UIView {

private let button: UIButton = UIButton()

override init(frame: CGRect) {
super.init(frame: frame)
setHierarchy()
setStyle()
setLayout()
setActions()
}

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

private func setHierarchy() {
addSubview(button)
}

private func setStyle() {

button.do {
$0.setTitle("다른 채팅방 보기", for: .normal)
$0.setTitleColor(.gray700, for: .normal)
$0.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: .medium)
$0.setImage(UIImage(resource: .icArrowRefresh), for: .normal) // 아이콘
$0.imageView?.contentMode = .scaleAspectFit
$0.backgroundColor = .white
$0.layer.cornerRadius = 20
$0.layer.borderWidth = 1
$0.layer.borderColor = UIColor.gray300.cgColor
$0.contentEdgeInsets = UIEdgeInsets(top: 8, left: 16, bottom: 8, right: 16)
$0.imageEdgeInsets = UIEdgeInsets(top: 0, left: -8, bottom: 0, right: 8)
}
}

private func setLayout() {
button.snp.makeConstraints {
$0.edges.equalToSuperview()

}
}

private func setActions() {
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
}

@objc private func buttonTapped() {
print("muyaho~~")
}
}




import SwiftUI

struct ChatReSearchButtonView_Preview: PreviewProvider {
static var previews: some View {
ChatReSearchButtonViewWrapper()
.previewLayout(.sizeThatFits)
.padding()
}
}

struct ChatReSearchButtonViewWrapper: UIViewRepresentable {
func makeUIView(context: Context) -> UIView {
return ChatReSearchButtonView()
}
func updateUIView(_ uiView: UIView, context: Context) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
//
// CompanyMentorCollectionViewCell.swift
// LINKAREER-iOS
//
// Created by Jaehyun Ahn on 11/25/24.
//

import Foundation
import UIKit
import SnapKit
import Then

final class CompanyMentorCollectionViewCell: UICollectionViewCell {

private var collectionView: UICollectionView = UICollectionView(
frame: .zero,
collectionViewLayout: UICollectionViewFlowLayout()
)

private let bottomButton: ChatReSearchButtonView = ChatReSearchButtonView()

private var tagHeaderData: TagHeader?
private var chatListData: [ChatList] = []

override init(frame: CGRect) {
super.init(frame: frame)
setHierarchy()
setLayout()
setDelegate()
setStyle()
registerCell()
}

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

private func setHierarchy() {
addSubviews(collectionView,bottomButton)
}

private func setLayout() {
collectionView.snp.makeConstraints {
$0.edges.equalToSuperview()
$0.bottom.equalTo(bottomButton.snp.top)
}

bottomButton.snp.makeConstraints {
$0.centerX.equalToSuperview()
$0.top.equalTo(collectionView.snp.bottom).offset(10)
$0.height.equalTo(36)
$0.width.equalTo(150)
}
}

private func setDelegate() {
collectionView.dataSource = self
collectionView.delegate = self
}

private func setStyle() {
if let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
layout.scrollDirection = .vertical
layout.minimumLineSpacing = 8
layout.minimumInteritemSpacing = 0
}
collectionView.backgroundColor = .clear
}

private func registerCell() {
collectionView.register(
TagHeaderView.self,
forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader,
withReuseIdentifier: TagHeaderView.identifier
)
collectionView.register(
ChatListCollectionViewCell.self,
forCellWithReuseIdentifier: ChatListCollectionViewCell.identifier
)
}
}

extension CompanyMentorCollectionViewCell {

func configure(with tagHeaderData: TagHeader, chatListData: [ChatList]) {
self.tagHeaderData = tagHeaderData
self.chatListData = chatListData
collectionView.reloadData()
}
}

extension CompanyMentorCollectionViewCell: UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 3
}

func collectionView(
_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath
) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(
withReuseIdentifier: ChatListCollectionViewCell.identifier,
for: indexPath
) as? ChatListCollectionViewCell else {
return UICollectionViewCell()
}
cell.configure(data: chatListData[indexPath.item])
return cell
}

func collectionView(
_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAt indexPath: IndexPath
) -> CGSize {
return CGSize(width: collectionView.bounds.width , height: 97)
}


func collectionView(
_ collectionView: UICollectionView,
viewForSupplementaryElementOfKind kind: String,
at indexPath: IndexPath
) -> UICollectionReusableView {
if kind == UICollectionView.elementKindSectionHeader {
guard let header = collectionView.dequeueReusableSupplementaryView(
ofKind: kind,
withReuseIdentifier: TagHeaderView.identifier,
for: indexPath
) as? TagHeaderView else {
return UICollectionReusableView()
}
if let tagHeaderData = tagHeaderData {
header.configure(headerData: tagHeaderData)
}
return header
}
return UICollectionReusableView()
}

func collectionView(
_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
referenceSizeForHeaderInSection section: Int
) -> CGSize {
return CGSize(width: collectionView.bounds.width, height: 70)
}
}


import SwiftUI

struct CompanyMentorCollectionViewCellPreview: UIViewRepresentable {

func makeUIView(context: Context) -> UIView {
let cell = CompanyMentorCollectionViewCell()


let tagHeaderData = TagHeader(
nickname: "UX/UI",
title: "직무 취준생들의 이야기",
discription: "에 대한 이야기가 화두예요.",
tags: ["산학", "대학원", "인턴 경험"]
)
let chatListData = ChatList.listDummy()

cell.configure(with: tagHeaderData, chatListData: chatListData)

return cell
}

func updateUIView(_ uiView: UIView, context: Context) {}
}

struct CompanyMentorCollectionViewCellPreview_Previews: PreviewProvider {
static var previews: some View {
CompanyMentorCollectionViewCellPreview()
.frame(width: UIScreen.main.bounds.width, height: 400)
.previewLayout(.sizeThatFits)
.padding()
}
}

0 comments on commit fcd3b96

Please sign in to comment.