라이브방 - 메뉴판 사이즈

- 높이가 500보다 작으면 메뉴의 길이만큼 표시되도록 수정
- 최대 높이 500
This commit is contained in:
Yu Sung 2024-10-28 14:12:25 +09:00
parent 88055c47c3
commit 5b55c9d2e3
1 changed files with 16 additions and 1 deletions

View File

@ -15,6 +15,7 @@ struct LiveRoomViewV2: View {
@StateObject var viewModel = LiveRoomViewModel()
@State private var textHeight: CGFloat = .zero
@State private var menuTextHeight: CGFloat = .zero
var body: some View {
ZStack {
@ -341,11 +342,18 @@ struct LiveRoomViewV2: View {
.foregroundColor(.white)
.lineSpacing(4)
}
.background(GeometryReader { geometry in
Color.clear.preference(key: TextViewHeightKey.self, value: geometry.size.height)
})
}
.padding(8)
.background(Color.gray33)
.padding(.horizontal, 60)
.padding(.bottom, 120)
.frame(maxWidth: 350)
.frame(height: menuTextHeight > 500 ? 500 : menuTextHeight, alignment: .topLeading)
.onPreferenceChange(TextViewHeightKey.self) { value in
menuTextHeight = value + 15
}
}
}
}
@ -759,6 +767,13 @@ struct LiveRoomViewV2: View {
value += nextValue()
}
}
struct TextViewHeightKey: PreferenceKey {
static var defaultValue: CGFloat = .zero
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
value = nextValue()
}
}
}
struct LiveRoomViewV2_Previews: PreviewProvider {