fix(creator-channel): 내 채널 커뮤니티 아이템이 위/아래가 잘리는 버그 수정

- HeightPreferenceKey를 사용해 아이템 사이즈 동적으로 갱신하여 LazyHStack의 사이즈를 현재 보이는 아이템의 사이즈로 설정하여 잘리는 버그 수정
This commit is contained in:
Yu Sung
2025-10-17 01:01:10 +09:00
parent 667195bd64
commit 76774d3d95

View File

@@ -20,6 +20,8 @@ struct UserProfileView: View {
@State private var isShowRouletteSettings: Bool = false
@State private var isShowMenuSettings: Bool = false
@State private var maxCommunityPostHeight: CGFloat? = nil
var body: some View {
GeometryReader { proxy in
BaseView(isLoading: $viewModel.isLoading) {
@@ -95,6 +97,12 @@ struct UserProfileView: View {
step: .creatorCommunityAll(creatorId: userId)
)
}
.background(
GeometryReader { geo in
Color.clear
.preference(key: HeightPreferenceKey.self, value: geo.size.height)
}
)
}
CreatorCommunityMoreItemView {
@@ -105,8 +113,15 @@ struct UserProfileView: View {
}
}
.padding(.horizontal, 13.3)
.frame(height: maxCommunityPostHeight)
.onPreferenceChange(HeightPreferenceKey.self) { value in
if let current = maxCommunityPostHeight {
maxCommunityPostHeight = max(current, value)
} else {
maxCommunityPostHeight = value
}
}
}
.frame(minHeight: 146)
.padding(.top, 26.7)
} else {
if UserDefaults.int(forKey: .userId) == creatorProfile.creator.creatorId {
@@ -399,6 +414,13 @@ struct UserProfileView: View {
}
}
struct HeightPreferenceKey: PreferenceKey {
static var defaultValue: CGFloat = 0
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
value = max(value, nextValue()) // height
}
}
struct UserProfileView_Previews: PreviewProvider {
static var previews: some View {
UserProfileView(userId: 0)