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

Feat [#105] 404 페이지 구현 및 답글에서 프로필 클릭시 유저페이지로 이동 및 유저 투명도에 따른 글쓰기 분기처리 #110

Merged
merged 6 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
12 changes: 12 additions & 0 deletions DontBe-iOS/DontBe-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
2A5220EF2B507F97001510B7 /* NotificationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A5220EE2B507F97001510B7 /* NotificationViewModel.swift */; };
2A5220F22B507FAE001510B7 /* NotificationTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A5220F12B507FAE001510B7 /* NotificationTableViewCell.swift */; };
2A5D68F82B58E9C0000AE1B7 /* CommentLikeRequestDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A5D68F72B58E9C0000AE1B7 /* CommentLikeRequestDTO.swift */; };
2A5D68FC2B5938BD000AE1B7 /* ErrorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A5D68FB2B5938BD000AE1B7 /* ErrorViewController.swift */; };
2A6D54C12B479B4300F9891E /* adjusted+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A6D54C02B479B4300F9891E /* adjusted+.swift */; };
2A6D54C32B493A8400F9891E /* UIFont+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A6D54C22B493A8400F9891E /* UIFont+.swift */; };
2A6D54C62B493E3F00F9891E /* Pretendard-SemiBold.otf in Resources */ = {isa = PBXBuildFile; fileRef = 2A6D54C42B493E3F00F9891E /* Pretendard-SemiBold.otf */; };
Expand Down Expand Up @@ -177,6 +178,7 @@
2A5220EE2B507F97001510B7 /* NotificationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationViewModel.swift; sourceTree = "<group>"; };
2A5220F12B507FAE001510B7 /* NotificationTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationTableViewCell.swift; sourceTree = "<group>"; };
2A5D68F72B58E9C0000AE1B7 /* CommentLikeRequestDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentLikeRequestDTO.swift; sourceTree = "<group>"; };
2A5D68FB2B5938BD000AE1B7 /* ErrorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorViewController.swift; sourceTree = "<group>"; };
2A6D54C02B479B4300F9891E /* adjusted+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "adjusted+.swift"; sourceTree = "<group>"; };
2A6D54C22B493A8400F9891E /* UIFont+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIFont+.swift"; sourceTree = "<group>"; };
2A6D54C42B493E3F00F9891E /* Pretendard-SemiBold.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Pretendard-SemiBold.otf"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -461,6 +463,14 @@
path = Models;
sourceTree = "<group>";
};
2A5D68FA2B593864000AE1B7 /* 404 */ = {
isa = PBXGroup;
children = (
2A5D68FB2B5938BD000AE1B7 /* ErrorViewController.swift */,
);
path = 404;
sourceTree = "<group>";
};
2A7341592B58532A00F65FD0 /* ContentLike */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -795,6 +805,7 @@
3C6193032B3A773800220CEB /* Presentation */ = {
isa = PBXGroup;
children = (
2A5D68FA2B593864000AE1B7 /* 404 */,
3CE9C1332B4C4BA90086E4A3 /* Helpers */,
2AAEFC952B4A9BF100C2D323 /* TabBar */,
2A51AE832B4B05AA00FF770A /* Splash */,
Expand Down Expand Up @@ -1254,6 +1265,7 @@
2A2672022B4C3B44009D214F /* ViewModelType.swift in Sources */,
3C6192ED2B3A719A00220CEB /* AppDelegate.swift in Sources */,
2F8735402B4BE65300E55552 /* HomeView.swift in Sources */,
2A5D68FC2B5938BD000AE1B7 /* ErrorViewController.swift in Sources */,
2F8735442B4BE67300E55552 /* HomeViewModel.swift in Sources */,
2F87354C2B4D28D700E55552 /* HomeCollectionFooterView.swift in Sources */,
2A5220EC2B507F2A001510B7 /* UITableViewCellRegisterable.swift in Sources */,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주어진 코드 패치의 코드 리뷰를 해드리겠습니다.

  1. 빌드 파일과 파일 참조 추가:
    • ErrorViewController.swift가 소스로 추가됩니다.
  2. 그룹 및 경로 추가:
    • 404이라는 이름의 새로운 그룹이 생성되며, ErrorViewController.swift 파일이 해당 그룹에 포함됩니다.
  3. 폴더 구조 변경:
    • 404 그룹이 Presentation 그룹 내에 추가됩니다.
  4. 파일 참조 추가:
    • ErrorViewController.swift in Sources 파일 참조가 추가됩니다.

버그나 개선점을 파악하기 위해서는 전체 소스 코드와 어떤 프레임워크/도구를 사용하는지 알아야 합니다. 따라서 여기서 설명드릴 수 있는 점은 제한적입니다. 이 코드 패치가 올바르게 작동하려면 다음을 고려해야 할 수 있습니다:

  • 코드 변경의 목적과 예상 동작을 검토하세요.
  • 파일 및 그룹 구조가 원하는 방식으로 설정되었는지 확인하세요.
  • 코드 간의 의존성이 올바르게 구성되었는지 확인하세요.
  • 파일을 올바른 위치와 그룹에 배치했는지 확인하세요.
  • 필요한 빌드 설정이 적용되었는지 확인하세요.
  • 다른 코드 변경 사항과 충돌이 발생하는지 주의하세요.

이외에도 세부적인 내용은 제공되지 않아서 더 자세한 코드 분석이 어렵습니다. 전체 코드를 주실 경우 보다 정확하고 구체적인 피드백을 제공할 수 있습니다.

Expand Down
1 change: 1 addition & 0 deletions DontBe-iOS/DontBe-iOS/Global/Literals/ImageLiterals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum ImageLiterals {
static var logoSymbol: UIImage { .load(name: "logo_symbol") }
static var imgProfile: UIImage { .load(name: "img_profile") }
static var btnBackGray: UIImage { .load(name: "btn_back_gray") }
static var img404: UIImage { .load(name: "img_404") }
}

enum TabBar {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드 수정 내용:

  1. 새로운 이미지 리터럴 img404이 추가되었습니다.

버그 위험:

  • 보안 상의 문제는 없어 보입니다. 그러나 코드에서 실제로 로드되는지 확인해야 합니다.

개선 제안:

  1. 이미지 리터럴을 사용하는 다른 부분과 일관성을 유지하기 위해 img404 대신에 더 명확한 이름을 선택하는 것이 좋습니다. 예를 들어, "notFoundImage"와 같이 이미지가 발견되지 않은 경우를 나타내는 이름으로 변경할 수 있습니다.
  2. 필요한 최소한의 기능만 포함된 코드인 것 같으며, 그 외에 개선할 사항은 없어 보입니다. 그러나 코드 베이스의 전반적인 구조와 일관성을 확인하는 것이 좋습니다.
  3. 이미지 파일 이름과 실제 파일이 일치하는지 확인하십시오. 파일명의 철자나 대/소문자가 정확하지 않을 경우 이미지가 로드되지 않을 수 있습니다.

추가로, 코드 리뷰를 더 정확하게 할 수 있도록 전체 코드 및 관련 문맥을 제공해 주시면 감사하겠습니다.

Expand Down
2 changes: 2 additions & 0 deletions DontBe-iOS/DontBe-iOS/Global/Literals/StringLiterals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ enum StringLiterals {
static let later = "한 줄 소개 나중에 작성하기"
static let finish = "완료하기"
static let editFinish = "수정완료"
static let goHome = "홈으로 가기"
}

enum Toast {
Expand Down Expand Up @@ -143,5 +144,6 @@ enum StringLiterals {
static let baseImageURL = "https://github.com/TeamDon-tBe/SERVER/assets/97835512/fb3ea04c-661e-4221-a837-854d66cdb77e"
static let notificationImageURL = "https://github.com/TeamDon-tBe/SERVER/assets/128011308/327d416e-ef1f-4c10-961d-4d9b85632d87"
static let warnUserGoogleFormURL = "https://forms.gle/FTgZKkajwtzFvAk99"
static let errorMessage = "이런!\n현재 요청하신 페이지를 찾을 수 없어요!"
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드 리뷰를 해드리겠습니다. 여기에 나와 있는 코드 패치에 대한 간단한 리뷰입니다:

  1. 모든 변경 사항은 추가된 새로운 문자열 상수를 포함하고 있습니다. 이러한 변경은 안전한 변동으로 보입니다.
  2. 새롭게 추가된 "홈으로 가기" 문자열은 어플리케이션의 특정 기능을 위해 사용되는 것으로 추측됩니다. 이 변경은 올바르게 이루어졌으며, 어플리케이션에 해당 기능이 없을 경우 문제가 될 수 있습니다.
  3. 이미지 URL들과 경고 메시지 URL도 업데이트되었습니다. 이러한 변경은 이미지나 링크가 변경되었다면 필요한 수정으로 보입니다.

전반적으로, 주어진 코드 패치는 안전하고 예상되는 동작 작업을 위한 문자열 상수들을 추가하고 있습니다. 추가된 내용은 잘못된 점이 없으며, 안정성을 유지하기 위해 앱 컨텍스트와 일치하는지 확인하는 것이 좋습니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "img_404.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "img_404@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "img_404@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 코드는 Xcode에서 사용하는 이미지 정보를 정의하는 JSON 형식의 파일입니다.
이 코드 패치는 "img_404.png"라는 파일에 대해서 "1x", "2x", "3x"의 스케일을 가지는 이미지를 정의합니다.

버그 위험은 존재하지 않습니다.
개선 제안으로는, 아래와 같은 사항들이 있을 수 있습니다:

  • 이미지의 확장자(.png)을 명시적으로 지정하고, 확장자가 올바른지 확인하는 것이 좋습니다.
  • 파일 이름의 일관성을 유지하기 위해, "img_404"라는 부분을 변수로 추출해 사용할 수 있습니다.
  • 구조화된 데이터를 사용하여, 이미지 관련 정보가 추가될 경우 손쉽게 확장할 수 있도록 할 수 있습니다.

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 @@ -92,7 +92,13 @@ final class NetworkService: NetworkServiceType {

print("👻👻👻👻👻 토큰 재발급 👻👻👻👻👻")
return try await donNetwork(type: type, baseURL: baseURL, accessToken: newAccessToken, body: body, pathVariables: pathVariables)
case 404 :
case 404:
if let sceneDelegate = await UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate {
DispatchQueue.main.async {
let viewController = ErrorViewController()
sceneDelegate.window?.rootViewController = UINavigationController(rootViewController: viewController)
}
}
throw NetworkError.notFoundError
case 500:
throw NetworkError.internalServerError

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 코드 패치에 대한 간단한 코드 리뷰를 도와드리겠습니다. 버그 위험과 개선 제안을 환영합니다:

  • 92번 줄에서 donNetwork 함수 호출 시, 오타로 인해 "do"가 "don"으로 오타되었습니다. 이 부분을 수정해야 합니다.
  • 92번 줄 아래의 코드는 404 상태 코드일 때 실행됩니다. UIApplication.shared.connectedScenes.first에서 await 키워드를 사용하고 있으므로 비동기적인 작업이 수행되고 있다고 가정합니다. 해당 코드 블록 내에서 UI 작업을 수행하고 있으며, 이는 메인 스레드에서 실행되어야 합니다. 따라서 DispatchQueue.main.async를 사용하여 UI 작업을 메인 큐에서 비동기적으로 실행하도록 변경하는 것이 좋습니다. 그럼으로써 UI 업데이트가 제대로 이루어지는 것을 보장할 수 있습니다.
  • 96번 줄과 98번 줄 사이에 들여쓰기가 잘못되어 있는 것 같습니다. 코드의 일관성을 위해 적절한 들여쓰기를 추가하는 것이 좋습니다.

그 외에는 코드에 큰 문제가 없어보입니다. 이 코드 리뷰를 참고하여 수정 및 개선을 진행하시면 됩니다.

Expand Down
98 changes: 98 additions & 0 deletions DontBe-iOS/DontBe-iOS/Presentation/404/ErrorViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
//
// ErrorViewController.swift
// DontBe-iOS
//
// Created by 변희주 on 1/18/24.
//

import UIKit

import SnapKit

final class ErrorViewController: UIViewController {

// MARK: - Properties

// MARK: - UI Components

private let errorImage: UIImageView = {
let emptyImage = UIImageView()
emptyImage.image = ImageLiterals.Common.img404
return emptyImage
}()

private let errorTitle: UILabel = {
let emptyTitle = UILabel()
emptyTitle.text = StringLiterals.Network.errorMessage
emptyTitle.textColor = .donBlack
emptyTitle.font = .font(.body1)
emptyTitle.setTextWithLineHeight(text: emptyTitle.text, lineHeight: 22.adjusted, alignment: .center)
emptyTitle.numberOfLines = 2
return emptyTitle
}()

private let homeButton = CustomButton(title: StringLiterals.Button.goHome, backColor: .donBlack, titleColor: .donWhite)

// MARK: - Life Cycles

override func viewDidLoad() {
super.viewDidLoad()

setUI()
setHierarchy()
setLayout()
setAddTarget()
}
}


// MARK: - Extensions

extension ErrorViewController {
private func setUI() {
self.view.backgroundColor = .donWhite
}

private func setHierarchy() {
self.view.addSubviews(errorImage,
errorTitle,
homeButton)
}

private func setLayout() {
errorImage.snp.makeConstraints {
$0.top.equalToSuperview().inset(statusBarHeight + 182.adjustedH)
$0.centerX.equalToSuperview()
$0.width.equalTo(255.adjusted)
$0.height.equalTo(150.adjusted)
}

errorTitle.snp.makeConstraints {
$0.top.equalTo(errorImage.snp.bottom).offset(34.adjustedH)
$0.centerX.equalToSuperview()
}

homeButton.snp.makeConstraints {
$0.bottom.equalTo(self.view.safeAreaLayoutGuide).inset(29.adjusted)
$0.centerX.equalToSuperview()
}
}

private func setAddTarget() {
self.homeButton.addTarget(self, action: #selector(homeButtonTapped), for: .touchUpInside)
}

@objc
private func homeButtonTapped() {
if let sceneDelegate = UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate {
DispatchQueue.main.async {
let viewController = DontBeTabBarController()
viewController.selectedIndex = 0
if let selectedViewController = viewController.selectedViewController {
viewController.applyFontColorAttributes(to: selectedViewController.tabBarItem, isSelected: true)
}
sceneDelegate.window?.rootViewController = UINavigationController(rootViewController: viewController)
}
}
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 코드 패치는 ErrorViewController 클래스를 정의하는 것으로 보입니다. 주요 기능 및 UI 구성 요소가 제공되며, ErrorViewController 뷰 컨트롤러의 뷰 계층 구조, 레이아웃 및 이벤트 처리가 설정됩니다.

주요 개선 제안:

  1. import UIKit은 이미 UIKit 프레임워크에 속하므로 중복으로 임포트하지 않아도 됩니다.
  2. SnapKit 라이브러리를 사용하여 UI 레이아웃 구성을 쉽게 할 수 있습니다.
  3. 앱의 상태 바 높이 및 여백과 같은 값은 하드코딩 대신 값을 참조하여 사용하는 것이 좋습니다.
  4. customButton은 번역되어야 합니다.

버그/위험 사항:

  1. 예외 처리가 없으므로 문제가 발생할 경우 애플리케이션이 충돌할 수 있습니다.
  2. 코드 내에서 앱의 최상위 뷰 컨트롤러를 변경하는 메서드(window?.rootViewController)가 사용되었는데, 현재 시스템에 연결된 장면(delegate)이 있는지 확인하지 않습니다.

추가 제안:

  1. 에러 처리 로직을 추가하여 네트워크 오류 및 다른 예기치 않은 오류에 대한 조치를 취할 수 있습니다.
  2. ErrorViewController 클래스의 테스트를 작성하여 코드가 예상한 대로 작동하는지 확인할 수 있습니다.

Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ extension MyPageViewController {
self.navigationController?.navigationBar.addSubviews(navigationBackButton)
navigationBackButton.snp.makeConstraints {
$0.centerY.equalToSuperview()
$0.leading.equalToSuperview().inset(23.adjusted)
$0.leading.equalToSuperview().inset(16.adjusted)
}
rootView.pageViewController.view.snp.makeConstraints {
$0.top.equalTo(rootView.segmentedControl.snp.bottom).offset(2.adjusted)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 코드 패치를 간략히 검토해보겠습니다. 개선할 점과 버그 위험에 대한 의견을 드리겠습니다.

  1. 변경된 부분 중 $0.leading.equalToSuperview().inset(16.adjusted)는 원래 값인 23에서 16으로 변경되었습니다. 이는 왼쪽 여백의 크기를 조정한 것입니다.

  2. 수정된 코드에서 rootView.pageViewController.view.snp.makeConstraints를 통해 top 제약 조건이 설정되었는데, rootView.segmentedControl.snp.bottom에서 2만큼 떨어진 위치로 지정되었습니다.

  3. 해당 코드 패치의 문제점이나 버그 위험은 찾지 못했습니다. 그러나 프로젝트 전반적인 컨텍스트와 함께 실제 사용 시의 동작을 고려해야 합니다.

주의할 점: 위의 검토 내용은 기존 코드와의 차이점에 초점을 맞추어 일반적인 개선점을 제시한 것일 뿐, 애플리케이션에서의 동작 결함 등 개별적인 사항은 파악하지 못하였습니다. 전체 코드와 함께 테스트하여 문제를 발견하고 수정하는 것이 좋습니다.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ final class MyPageProfileView: UIView {

let userNickname: UILabel = {
let label = UILabel()
label.text = "안녕하세요반가와요우히히"
label.text = loadUserData()?.userNickname
label.textColor = .donWhite
label.textAlignment = .center
label.font = .font(.head3)
Expand All @@ -51,7 +51,7 @@ final class MyPageProfileView: UIView {

let userIntroduction: UILabel = {
let label = UILabel()
label.setTextWithLineHeight(text: "안녕하세요히안우히히안녕하세요반가와요우히히히히안녕하세요히안우히히안녕하세요반가와요우히히히히", lineHeight: 20.adjusted, alignment: .center)
label.setTextWithLineHeight(text: "", lineHeight: 20.adjusted, alignment: .center)
label.textColor = .donGray7
label.textAlignment = .center
label.font = .font(.caption2)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아래는 코드 패치이며, 해당 코드의 간단한 코드 리뷰를 도와드리겠습니다. 버그 위험 및 개선 제안 사항은 환영합니다:

주목할 점:

  1. 라인 42에서 userNickname 레이블의 텍스트가 "안녕하세요반가와요우히히"로 고정되어 있습니다.

    • 개선 제안: loadUserData()?.userNickname으로 대체하여 사용자의 닉네임을 동적으로 설정하는 것이 좋습니다.
  2. 라인 51에서 userIntroduction 레이블의 텍스트가 빈 문자열("")로 설정되어 있습니다.

    • 개선 제안: 필요한 텍스트를 적절하게 설정하여 사용자 소개를 나타내는 것이 좋습니다.

위의 주목할 점들을 고려하여 코드를 수정하시면 됩니다.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ final class PostReplyCollectionViewCell: UICollectionViewCell, UICollectionViewR
var KebabButtonAction: (() -> Void) = {}
var LikeButtonAction: (() -> Void) = {}
var TransparentButtonAction: (() -> Void) = {}
var ProfileButtonAction: (() -> Void) = {}
var isLiked: Bool = false
var alarmTriggerType: String = ""
var targetMemberId: Int = 0
Expand Down Expand Up @@ -44,6 +45,7 @@ final class PostReplyCollectionViewCell: UICollectionViewCell, UICollectionViewR
image.clipsToBounds = true
image.image = ImageLiterals.Common.imgProfile
image.layer.cornerRadius = 22.adjusted
image.isUserInteractionEnabled = true
return image
}()

Expand Down Expand Up @@ -277,6 +279,8 @@ extension PostReplyCollectionViewCell {
kebabButton.addTarget(self, action: #selector(showButtons), for: .touchUpInside)
likeButton.addTarget(self, action: #selector(likeToggleButton), for: .touchUpInside)
ghostButton.addTarget(self, action: #selector(transparentShowPopupButton), for: .touchUpInside)
profileImageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(profileButton)))

}

@objc
Expand All @@ -292,4 +296,9 @@ extension PostReplyCollectionViewCell {
func transparentShowPopupButton() {
TransparentButtonAction()
}

@objc
func profileButton() {
ProfileButtonAction()
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

다음은 코드 패치입니다. 해당 코드의 간단한 코드 리뷰를 도와드리겠습니다. 버그 위험 또는 개선 제안을 알려주세요.

  1. ProfileButtonAction 변수가 추가되었습니다. 이 변수는 프로필 버튼 클릭 시 호출될 클로저를 저장하는 용도로 사용됩니다.
  2. image.isUserInteractionEnabled = true 구문이 추가되었습니다. image 뷰에 대한 사용자 상호 작용을 가능하게 합니다.
  3. profileImageView에 탭 제스처 recognizer가 추가되었습니다. profileButton() 메서드가 탭 제스처를 처리하고, ProfileButtonAction() 클로저를 호출합니다. 이에 따라 프로필 이미지를 탭할 때 ProfileButtonAction에 지정된 동작이 실행됩니다.

개선할 점:
각 클로저 및 버튼의 액션 이름을 보다 명확하게 나타낼 수 있다면 가독성이 향상될 것입니다. 현재 KebabButtonAction, LikeButtonAction, TransparentButtonAction, ProfileButtonAction 등은 개선의 여지가 있습니다. 더 의미있는 이름으로 변경해주는 것이 좋습니다.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ final class PostViewController: UIViewController {
.map { _ in return self.contentId }
.throttle(for: .seconds(2), scheduler: DispatchQueue.main, latest: false)
.eraseToAnyPublisher()
}
}

let viewModel: PostViewModel
private var cancelBag = CancelBag()

Expand Down Expand Up @@ -114,6 +115,11 @@ final class PostViewController: UIViewController {
}
getAPI()
}

override func viewWillDisappear(_ animated: Bool) {
self.navigationController?.navigationBar.isHidden = false
self.navigationController?.navigationBar.backgroundColor = .clear
}
}

// MARK: - Extensions
Expand Down Expand Up @@ -304,6 +310,28 @@ extension PostViewController {
presentView()
}

@objc
private func pushToMypage() {
if self.memberId == loadUserData()?.memberId ?? 0 {
self.tabBarController?.selectedIndex = 3
if let selectedViewController = self.tabBarController?.selectedViewController {
self.applyTabBarAttributes(to: selectedViewController.tabBarItem, isSelected: true)
}
let myViewController = self.tabBarController?.viewControllers ?? [UIViewController()]
for (index, controller) in myViewController.enumerated() {
if let tabBarItem = controller.tabBarItem {
if index != self.tabBarController?.selectedIndex {
self.applyTabBarAttributes(to: tabBarItem, isSelected: false)
}
}
}
} else {
let viewController = MyPageViewController(viewModel: MyPageViewModel(networkProvider: NetworkService()))
viewController.memberId = memberId
self.navigationController?.pushViewController(viewController, animated: true)
}
}

func popView() {
if UIApplication.shared.keyWindowInConnectedScenes != nil {
UIView.animate(withDuration: 0.3, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
Expand Down Expand Up @@ -426,7 +454,8 @@ extension PostViewController {
self.postView.profileImageView.load(url: "\(data.memberProfileUrl)")
postView.likeButton.setImage(data.isLiked ? ImageLiterals.Posting.btnFavoriteActive : ImageLiterals.Posting.btnFavoriteInActive, for: .normal)
self.memberId = data.memberId

self.postView.profileImageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(pushToMypage)))

// 내가 투명도를 누른 유저인 경우 -85% 적용
if data.isGhost {
self.grayView.alpha = 0.85
Expand Down Expand Up @@ -517,6 +546,10 @@ extension PostViewController: UICollectionViewDataSource, UICollectionViewDelega
self.alarmTriggerdId = cell.alarmTriggerdId
self.present(self.transparentPopupVC, animated: false, completion: nil)
}
cell.ProfileButtonAction = {
self.memberId = self.viewModel.postReplyData[indexPath.row].memberId
self.pushToMypage()
}
cell.nicknameLabel.text = viewModel.postReplyData[indexPath.row].memberNickname
cell.transparentLabel.text = "투명도 \(viewModel.postReplyData[indexPath.row].memberGhost)%"
cell.contentTextLabel.text = viewModel.postReplyData[indexPath.row].commentText

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아래는 코드 패치에 대한 간단한 코드 리뷰입니다. 버그 위험과/또는 개선 제안이 있는 경우 알려주세요:

  1. eraseToAnyPublisher를 사용하여 publisher를 어떤 타입의 publisher로 지정하고 있습니다. 이 문제가 의도된 것인지 확인하세요.
  2. viewWillDisappear(_ animated: Bool) 메서드에서 navigationController?.navigationBar의 속성을 변경하고 있습니다. 이것이 원하는 동작인지 확인하세요.
  3. pushToMypage() 함수에서 새로운 뷰 컨트롤러를 생성하고 내비게이션 스택에 푸시하고 있습니다. 이 작업은 원하는 동작인지 확인하세요.
  4. ProfileButtonAction 클로저에서 self.memberId를 설정하고 pushToMypage()를 호출하고 있습니다. 클로저 동작이 원하는 대로 실행되는지 확인하세요.

이 외에는 보이는 문제가 없어 보입니다.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ final class PostView: UIView {
image.clipsToBounds = true
image.layer.cornerRadius = 22.adjusted
image.image = ImageLiterals.Common.imgProfile
image.isUserInteractionEnabled = true
return image
}()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드 패치에 대한 간단한 코드 리뷰를 도와드리겠습니다. 버그 위험 사항 및 개선 제안을 언급할 예정입니다:

  1. 해당 코드 패치에서는 이미지 뷰(image)의 isUserInteractionEnabled 속성을 true로 설정하고 있습니다. 이로 인해 사용자의 상호 작용이 가능해집니다. 따라서, 해당 코드는 사용자가 이미지를 터치하거나 다른 상호 작용을 할 수 있도록 하는 용도로 사용되었다고 가정할 수 있습니다.

위의 사항을 감안하여 적절한 사용 방법인지 확인하십시오. 만약 이미지에 대한 상호 작용이 필요하지 않은 경우에는 isUserInteractionEnabled 속성을 false로 설정하는 것이 좋을 수 있습니다.

그 외에는 코드 패치에서 별다른 버그 위험 사항은 보이지 않습니다.

Expand Down