-
Notifications
You must be signed in to change notification settings - Fork 0
week7 #7
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
base: main
Are you sure you want to change the base?
week7 #7
Conversation
hyeyeonie
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아주 LGTM입니다 ♡゛
| extension HomeView { | ||
| private var headerView: some View { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
각각의 뷰 파일로 따로 분리하지 않고 extension으로 나눈 이유가 있을까요?
코드가 다소 길어지긴 하지만, 뷰 단위가 명확해져서 이해하기는 더 쉬운 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
가독성을 높이기 위한 제 컨벤션입니다 !!
분리해서 사용하는 view의 경우, 다른 view에서 사용할 경우엔 파일 분리해서 재사용가능하도록 만들지만, 한 view에서만 사용하는 경우엔 그냥 해당 파일 안에 변수나 함수로 구현해서 사용하고 있습니다!
요거는 개인 스타일이기 때문에 참고만 해주세요 ~ ㅎㅎ
| .contentMargins(.leading, 15) | ||
| .padding(.top, 28) | ||
| .padding(.bottom, 12) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
찾아보니 contentMargins와 padding이 비슷한 역할을 하지만,
contentMargins는 여러 뷰를 포함한 컨테이너에서 정렬 기준을 바꿀 때,
padding은 텍스트나 버튼 등에서 간단히 여백을 줄 때 주로 사용한다고 하더라고요.ᐟ.ᐟ
해당 코드에서는 하나의 스크롤뷰에서 구분해서 사용하신 이유가 있는지 궁금해요💭
(여태껏 padding만 써온 1인...ㅎㅎ)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저도 contentMargins 처음 알았어요. 새로운 거 배워갑니당
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contentMargin의 경우! 저는 보통 스크롤뷰에서 많이 쓰는데요
가로 스크롤 기준, padding으로 양 옆을 주게 되면 스크롤했을 때 옆이 붕,,~ 떠버리는 경우가 있습니다..
이걸 방지하고자 contentMargin을 사용해줍니다! 요런 이유들 외에는 그냥 Padding으로 사용하고 있어요!
해당 코드의 경우 가로 스크롤이기 때문에 leading만 contentMargin을 주고 위아래는 그냥 padding 사용했습니다.
| struct TodayModel: Hashable { | ||
| let rank: Int | ||
| let image: ImageResource | ||
| } | ||
|
|
||
| extension TodayModel { | ||
| static func mock() -> [TodayModel] { | ||
| return [ | ||
| .init(rank: 1, image: .movie1), | ||
| .init(rank: 2, image: .movie2), | ||
| .init(rank: 3, image: .movie1), | ||
| .init(rank: 4, image: .movie2), | ||
| .init(rank: 5, image: .movie1), | ||
| .init(rank: 6, image: .movie2), | ||
| .init(rank: 7, image: .movie1) | ||
| ] | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오호라 이런 형식으로 모델을 만들어주셨군요 👀
Hashable을 채택해서 ForEach에서 바로 사용하기 편하고,
더미 데이터를 mock()으로 잘 구조화하신 점이 인상 깊습니다!
sangyup12
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 아직 모델 만들어서 쓰는 익숙하지 않은 거 같아요ㅠㅠ 너무 멋있습니다. 저도 이때릭을 쓰기 위해서 기본 폰트로 전부 진행했는데 다들 그렇게 하신 거 같아서 다행이네영. 고생하셨습니다!
| } | ||
| } | ||
|
|
||
| private var segmentView: some View { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
헉 struct가 아니라 var로도 가능하네요..? 저는 전부 struct로 하위 뷰들 만들었는데 어떤 차이가 있는건가요? var로 하니까 메인뷰에 붙일 때 todayView() 이렇게 괄호도 안 써도 되고 더 예쁜 거 같아요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
기능적으로 차이가 크진 않은 것으로 알고 있습니다만... 이건 더 공부해보면 좋을듯
저는 개인적으로 struct로 만들면 파일을 분리하고 싶어지기 때문에(ㄷㄷ) 내부 뷰는 변수 혹은 함수로 선언해주고 있습니다!
변수 - 내부 view를 그릴 때 변수가 필요 없는 경우
함수 - 내부 view를 그릴 때 변수가 필요한 경우 (예를들면 cell)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
감사합니다 더 공부해보겠습니다
| Image(.mainMovie) | ||
| .resizable() | ||
| .aspectRatio(contentMode: .fill) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저도 이거 그냥 쓸까 하다가 이 예쁜 곳에 수정자들 있는 걸 못참겠어서 이 이미지 하나를 위한 뷰를 따로 빼버렸는데 너무 비효율인가여?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ 아니요 괜찮습니다 .
| .contentMargins(.leading, 15) | ||
| .padding(.top, 28) | ||
| .padding(.bottom, 12) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저도 contentMargins 처음 알았어요. 새로운 거 배워갑니당
| HStack { | ||
| ForEach(ImageModel.dramaMock(), id: \.self) { model in | ||
| Image(model.image) | ||
| .clipShape(RoundedRectangle(cornerRadius: 5)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 방식도 아래 사용한 .cornerRadius(12) 이거와 같은 결과가 나오나여?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그러합니다. ~@!
HomeView.swiftModel.swift요 파일들만 보면 됩니다...
생각을 많이 하고 짠 코드는 아니라 좋은 코드는 아니라고 생각됩니다만... 추후 리팩토링해볼게요