Files
sodalive-ios/SodaLive/Sources/Follow/FollowCreatorItemView.swift

90 lines
2.7 KiB
Swift

//
// FollowCreatorItemView.swift
// SodaLive
//
// Created by klaus on 2023/08/19.
//
import SwiftUI
import Kingfisher
struct FollowCreatorItemView: View {
let creator: GetCreatorFollowingAllListItem
let onClickFollow: (Int) -> Void
let showCreatorFollowNotifyDialog: (Int) -> Void
let onTapUnfollow: ((Int) -> Void)?
init(
creator: GetCreatorFollowingAllListItem,
onClickFollow: @escaping (Int) -> Void,
showCreatorFollowNotifyDialog: @escaping (Int) -> Void,
onTapUnfollow: ((Int) -> Void)? = nil
) {
self.creator = creator
self.onClickFollow = onClickFollow
self.showCreatorFollowNotifyDialog = showCreatorFollowNotifyDialog
self.onTapUnfollow = onTapUnfollow
}
var body: some View {
VStack(spacing: 13.3) {
HStack(spacing: 0) {
KFImage(URL(string: creator.profileImageUrl))
.cancelOnDisappear(true)
.downsampling(
size: CGSize(
width: 60,
height: 60
)
)
.resizable()
.frame(width: 60, height: 60)
.clipShape(Circle())
Text(creator.nickname)
.appFont(size: 16.7, weight: .bold)
.foregroundColor(Color.grayee)
.padding(.leading, 13.3)
Spacer()
followButton
}
Rectangle()
.foregroundColor(Color.gray59)
.frame(height: 0.5)
}
}
@ViewBuilder
private var followButton: some View {
if creator.isFollow, let onTapUnfollow {
Button(action: { onTapUnfollow(creator.creatorId) }) {
Image("ic_new_following_white")
.resizable()
.frame(width: 20, height: 20)
.frame(width: 36, height: 36)
.background(Color.gray800)
.clipShape(Circle())
}
.buttonStyle(.plain)
} else {
let asset = FollowButtonImageAsset(
type: creator.isFollow
? (creator.isNotify ? .following : .followingNoAlarm)
: .follow
)
asset.imageView()
.onTapGesture {
if creator.isFollow {
showCreatorFollowNotifyDialog(creator.creatorId)
} else {
onClickFollow(creator.creatorId)
}
}
}
}
}