Files
sodalive-ios/SodaLive/Sources/Live/Room/V2/Component/View/LiveRoomInfoGuestView.swift

328 lines
12 KiB
Swift

//
// LiveRoomInfoGuestView.swift
// SodaLive
//
// Created by klaus on 2024/01/17.
//
import SwiftUI
struct LiveRoomInfoGuestView: View {
let title: String
let totalHeart: Int
let totalDonationCan: Int
let isOnBg: Bool
let isOnNotice: Bool
let isOnMenuPan: Bool
let isOnSignature: Bool
let isOnV2VCaption: Bool
let isShowMenuPanButton: Bool
let isShowV2VCaptionButton: Bool
let creatorId: Int
let creatorNickname: String
let creatorProfileUrl: String
let followButtonType: FollowButtonImageType
let speakerList: [LiveRoomMember]
let muteSpeakerList: [UInt]
let activeSpeakerList: [UInt]
let isAdult: Bool
let onClickQuit: () -> Void
let onClickToggleBg: () -> Void
let onClickShare: () -> Void
let onClickProfile: (Int) -> Void
let onClickNotice: () -> Void
let onClickMenuPan: () -> Void
let onClickTotalHeart: () -> Void
let onClickTotalDonation: () -> Void
let onClickFollow: () -> Void
let onClickChangeListener: () -> Void
let onClickToggleV2VCaption: () -> Void
let onClickToggleSignature: () -> Void
var body: some View {
ZStack {
VStack(spacing: 13.3) {
HStack(spacing: 5.3) {
LiveRoomOverlayStrokeTextButton(
text: I18n.LiveRoom.leaveButton,
textColor: Color.red,
strokeColor: Color.red,
strokeWidth: 1,
strokeCornerRadius: 5.3
) { onClickQuit() }
Spacer()
if speakerList.contains(where: { $0.id == UserDefaults.int(forKey: .userId)}) {
LiveRoomOverlayStrokeTextButton(
text: I18n.LiveRoom.changeListenerButton,
textColor: Color.grayee,
strokeColor: Color.graybb,
strokeWidth: 1,
strokeCornerRadius: 5.3
) { onClickChangeListener() }
}
if isShowV2VCaptionButton {
LiveRoomOverlayStrokeTextToggleButton(
isOn: isOnV2VCaption,
onText: I18n.LiveRoom.captionOn,
onTextColor: Color.button,
onStrokeColor: Color.button,
offText: I18n.LiveRoom.captionOff,
offTextColor: Color.graybb,
offStrokeColor: Color.graybb,
strokeWidth: 1,
strokeCornerRadius: 5.3
) { onClickToggleV2VCaption() }
}
LiveRoomOverlayStrokeTextToggleButton(
isOn: isOnSignature,
onText: I18n.LiveRoom.signatureOn,
onTextColor: Color.button,
onStrokeColor: Color.button,
offText: I18n.LiveRoom.signatureOff,
offTextColor: Color.graybb,
offStrokeColor: Color.graybb,
strokeWidth: 1,
strokeCornerRadius: 5.3
) { onClickToggleSignature() }
LiveRoomOverlayStrokeTextToggleButton(
isOn: isOnBg,
onText: I18n.LiveRoom.backgroundOn,
onTextColor: Color.button,
onStrokeColor: Color.button,
offText: I18n.LiveRoom.backgroundOff,
offTextColor: Color.graybb,
offStrokeColor: Color.graybb,
strokeWidth: 1,
strokeCornerRadius: 5.3
) { onClickToggleBg() }
LiveRoomOverlayStrokeImageButton(
imageName: "ic_share",
strokeColor: Color.graybb,
strokeWidth: 1,
strokeCornerRadius: 5.3
) { onClickShare() }
}
HStack(spacing: 8) {
LiveRoomInfoCreatorView(
roomTitle: title,
creatorNickname: creatorNickname,
creatorProfileUrl: creatorProfileUrl,
isMute: muteSpeakerList.contains(UInt(creatorId)),
isAdult: isAdult,
isActiveSpeaker: activeSpeakerList.contains(UInt(creatorId)),
onClickProfile: { onClickProfile(creatorId) }
)
Spacer()
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 8) {
ForEach(0..<speakerList.count, id: \.self) { index in
let speaker = speakerList[index]
if speaker.id != UInt(creatorId) {
LiveRoomInfoSpeakerView(
nickname: speaker.nickname,
profileUrl: speaker.profileImage,
isMute: muteSpeakerList.contains(UInt(speaker.id)),
isActiveSpeaker: activeSpeakerList.contains(UInt(speaker.id)),
onClickProfile: { onClickProfile(speaker.id) }
)
}
}
}
.rotationEffect(Angle(degrees: 180))
}
.rotationEffect(Angle(degrees: 180))
}
HStack(spacing: 5.3) {
LiveRoomOverlayStrokeTextToggleButton(
isOn: isOnNotice,
onText: I18n.LiveRoom.notice,
onTextColor: .button,
onStrokeColor: .button,
offText: nil,
offTextColor: .graybb,
offStrokeColor: .graybb,
strokeWidth: 1,
strokeCornerRadius: 5.3,
onClick: { onClickNotice() }
)
if isShowMenuPanButton {
LiveRoomOverlayStrokeTextToggleButton(
isOn: isOnMenuPan,
onText: I18n.LiveRoom.menuPan,
onTextColor: .button,
onStrokeColor: .button,
offText: nil,
offTextColor: .graybb,
offStrokeColor: .graybb,
strokeWidth: 1,
strokeCornerRadius: 5.3,
onClick: { onClickMenuPan() }
)
}
Spacer()
HStack(spacing: 6.7) {
Image("ic_heart_pink")
.resizable()
.frame(width: 12, height: 12)
Text("\(totalHeart)")
.appFont(size: 12, weight: .medium)
.foregroundColor(.graybb)
}
.padding(.horizontal, 11)
.padding(.vertical, 5.3)
.overlay(
RoundedRectangle(cornerRadius: 5.3)
.stroke(Color.graybb, lineWidth: 1)
)
.onTapGesture { onClickTotalHeart() }
HStack(spacing: 6.7) {
Image("ic_can")
.resizable()
.frame(width: 12, height: 12)
Text("\(totalDonationCan)")
.appFont(size: 12, weight: .medium)
.foregroundColor(.graybb)
}
.padding(.horizontal, 11)
.padding(.vertical, 5.3)
.overlay(
RoundedRectangle(cornerRadius: 5.3)
.stroke(Color.graybb, lineWidth: 1)
)
.onTapGesture { onClickTotalDonation() }
if creatorId != UserDefaults.int(forKey: .userId) {
followButtonView
}
}
}
if muteSpeakerList.contains(UInt(creatorId)) {
Image("img_noti_mute")
}
}
.padding(.horizontal, 13.3)
.padding(.top, 16)
.background(Color.gray22)
.onAppear {
UIScrollView.appearance().bounces = false
}
.onDisappear {
UIScrollView.appearance().bounces = true
}
}
private var followButtonText: String {
followButtonType == .follow ? I18n.LiveRoom.follow : I18n.LiveRoom.following
}
private var followButtonIconName: String {
switch followButtonType {
case .follow:
return "ic_live_creator_follow_plus"
case .following:
return "ic_live_creator_follow_alarm"
case .followingNoAlarm:
return "ic_live_creator_follow_no_alarm"
}
}
private var followButtonView: some View {
HStack(spacing: 6.7) {
Image(followButtonIconName)
.resizable()
.frame(width: 12, height: 12)
Text(followButtonText)
.appFont(size: 12, weight: .medium)
.foregroundColor(.graybb)
}
.padding(.horizontal, 11)
.padding(.vertical, 5.3)
.overlay(
RoundedRectangle(cornerRadius: 5.3)
.stroke(Color.graybb, lineWidth: 1)
)
.contentShape(Rectangle())
.onTapGesture { onClickFollow() }
}
}
struct LiveRoomInfoGuestView_Previews: PreviewProvider {
static var previews: some View {
LiveRoomInfoGuestView(
title: "qwer",
totalHeart: 1234,
totalDonationCan: 123456,
isOnBg: true,
isOnNotice: false,
isOnMenuPan: false,
isOnSignature: false,
isOnV2VCaption: false,
isShowMenuPanButton: false,
isShowV2VCaptionButton: true,
creatorId: 1,
creatorNickname: "도화",
creatorProfileUrl: "https://cf.sodalive.net/profile/26/26-profile-ddf78b4d-0300-4c50-9c84-5d8a95fd5fe2-4892-1705256364320",
followButtonType: .follow,
speakerList: [
LiveRoomMember(
id: 1,
nickname: "도화",
profileImage: "https://cf.sodalive.net/profile/26/26-profile-ddf78b4d-0300-4c50-9c84-5d8a95fd5fe2-4892-1705256364320",
role: .SPEAKER
),
LiveRoomMember(
id: 2,
nickname: "청령",
profileImage: "https://cf.sodalive.net/profile/13/13-profile-fabb75e0-2870-4d99-900e-1d9aa63e605b-685-1704859996417",
role: .SPEAKER
),
LiveRoomMember(
id: 3,
nickname: "LUNA",
profileImage: "https://cf.sodalive.net/profile/4679/4679-profile-41e83399-234e-4541-8591-f961a025cfaa-5819-1699536915310",
role: .SPEAKER
)
],
muteSpeakerList: [],
activeSpeakerList: [],
isAdult: false,
onClickQuit: {},
onClickToggleBg: {},
onClickShare: {},
onClickProfile: { _ in },
onClickNotice: {},
onClickMenuPan: {},
onClickTotalHeart: {},
onClickTotalDonation: {},
onClickFollow: {},
onClickChangeListener: {},
onClickToggleV2VCaption: {},
onClickToggleSignature: {}
)
}
}