180 lines
5.8 KiB
Swift
180 lines
5.8 KiB
Swift
import SwiftUI
|
|
|
|
struct CreatorChannelTitleBar: View {
|
|
let nickname: String
|
|
let isFollow: Bool
|
|
let isNotify: Bool
|
|
let backgroundProgress: CGFloat
|
|
let showsCreatorActions: Bool
|
|
let onTapBack: () -> Void
|
|
let onTapFollow: () -> Void
|
|
let onTapUnfollow: () -> Void
|
|
let onTapNotify: () -> Void
|
|
let onTapUnnotify: () -> Void
|
|
let onTapMore: () -> Void
|
|
|
|
init(
|
|
nickname: String,
|
|
isFollow: Bool,
|
|
isNotify: Bool,
|
|
backgroundProgress: CGFloat,
|
|
showsCreatorActions: Bool = true,
|
|
onTapBack: @escaping () -> Void,
|
|
onTapFollow: @escaping () -> Void,
|
|
onTapUnfollow: @escaping () -> Void,
|
|
onTapNotify: @escaping () -> Void,
|
|
onTapUnnotify: @escaping () -> Void,
|
|
onTapMore: @escaping () -> Void
|
|
) {
|
|
self.nickname = nickname
|
|
self.isFollow = isFollow
|
|
self.isNotify = isNotify
|
|
self.backgroundProgress = backgroundProgress
|
|
self.showsCreatorActions = showsCreatorActions
|
|
self.onTapBack = onTapBack
|
|
self.onTapFollow = onTapFollow
|
|
self.onTapUnfollow = onTapUnfollow
|
|
self.onTapNotify = onTapNotify
|
|
self.onTapUnnotify = onTapUnnotify
|
|
self.onTapMore = onTapMore
|
|
}
|
|
|
|
var body: some View {
|
|
HStack(spacing: SodaSpacing.s12) {
|
|
Button(action: onTapBack) {
|
|
Image("ic_new_bar_back")
|
|
.resizable()
|
|
.frame(width: 24, height: 24)
|
|
}
|
|
.buttonStyle(.plain)
|
|
|
|
Text(nickname)
|
|
.appFont(.heading2)
|
|
.foregroundColor(Color.white)
|
|
.lineLimit(1)
|
|
.truncationMode(.tail)
|
|
.opacity(backgroundProgress >= 1 ? 1 : 0)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
|
if showsCreatorActions {
|
|
HStack(spacing: SodaSpacing.s14) {
|
|
followButton
|
|
|
|
if isFollow {
|
|
notifyButton
|
|
}
|
|
|
|
Button(action: onTapMore) {
|
|
Image("ic_new_more")
|
|
.resizable()
|
|
.frame(width: 24, height: 24)
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
.layoutPriority(1)
|
|
}
|
|
}
|
|
.padding(.horizontal, SodaSpacing.s14)
|
|
.frame(height: 56)
|
|
.background(Color.black.opacity(max(0, min(backgroundProgress, 1))))
|
|
}
|
|
|
|
private var followButton: some View {
|
|
Button(action: isFollow ? onTapUnfollow : onTapFollow) {
|
|
HStack(spacing: SodaSpacing.s6) {
|
|
Image(isFollow ? "ic_new_following" : "ic_new_follow")
|
|
.resizable()
|
|
.renderingMode(.template)
|
|
.foregroundColor(isFollow ? Color.black : Color.white)
|
|
.frame(width: 20, height: 20)
|
|
|
|
if isFollow == false {
|
|
Text(I18n.CreatorChannelHome.follow)
|
|
.appFont(size: 16, weight: .medium)
|
|
.foregroundColor(Color.white)
|
|
}
|
|
}
|
|
.frame(width: isFollow ? 36 : nil, height: 36)
|
|
.padding(.horizontal, isFollow ? 0 : SodaSpacing.s12)
|
|
.background(isFollow ? Color.white : Color.clear)
|
|
.clipShape(Capsule())
|
|
}
|
|
.accessibilityLabel(isFollow ? I18n.CreatorChannelHome.following : "팔로우")
|
|
.buttonStyle(.plain)
|
|
}
|
|
|
|
private var notifyButton: some View {
|
|
Button(action: isNotify ? onTapUnnotify : onTapNotify) {
|
|
Image(isNotify ? "ic_bar_bell_colored" : "ic_bar_bell")
|
|
.resizable()
|
|
.frame(width: 24, height: 24)
|
|
.frame(width: 36, height: 36)
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
}
|
|
|
|
struct CreatorChannelTitleBar_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
VStack(spacing: SodaSpacing.s16) {
|
|
CreatorChannelTitleBar(
|
|
nickname: "Soda Creator Long Nickname Soda Creator Long Nickname",
|
|
isFollow: false,
|
|
isNotify: false,
|
|
backgroundProgress: 1,
|
|
showsCreatorActions: true,
|
|
onTapBack: {},
|
|
onTapFollow: {},
|
|
onTapUnfollow: {},
|
|
onTapNotify: {},
|
|
onTapUnnotify: {},
|
|
onTapMore: {}
|
|
)
|
|
|
|
CreatorChannelTitleBar(
|
|
nickname: "Soda Creator",
|
|
isFollow: true,
|
|
isNotify: true,
|
|
backgroundProgress: 1,
|
|
showsCreatorActions: true,
|
|
onTapBack: {},
|
|
onTapFollow: {},
|
|
onTapUnfollow: {},
|
|
onTapNotify: {},
|
|
onTapUnnotify: {},
|
|
onTapMore: {}
|
|
)
|
|
|
|
CreatorChannelTitleBar(
|
|
nickname: "Soda Creator",
|
|
isFollow: true,
|
|
isNotify: false,
|
|
backgroundProgress: 1,
|
|
showsCreatorActions: true,
|
|
onTapBack: {},
|
|
onTapFollow: {},
|
|
onTapUnfollow: {},
|
|
onTapNotify: {},
|
|
onTapUnnotify: {},
|
|
onTapMore: {}
|
|
)
|
|
|
|
CreatorChannelTitleBar(
|
|
nickname: "Soda Creator",
|
|
isFollow: true,
|
|
isNotify: true,
|
|
backgroundProgress: 1,
|
|
showsCreatorActions: false,
|
|
onTapBack: {},
|
|
onTapFollow: {},
|
|
onTapUnfollow: {},
|
|
onTapNotify: {},
|
|
onTapUnnotify: {},
|
|
onTapMore: {}
|
|
)
|
|
}
|
|
.background(Color.gray)
|
|
.previewLayout(.sizeThatFits)
|
|
}
|
|
}
|