Skip to content

Commit

Permalink
ProfileEditViewのUI実装
Browse files Browse the repository at this point in the history
  • Loading branch information
boardguy1024 committed Oct 20, 2023
1 parent 6036e93 commit 1b1ddb5
Show file tree
Hide file tree
Showing 10 changed files with 447 additions and 12 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct FollowingUserListView: View {

@EnvironmentObject var viewModel: UserStatusDetailViewModel

var tabType: FollowStatusType
var tabType: FollowButtonType

var body: some View {
VStack(spacing: 0) {
Expand Down
8 changes: 4 additions & 4 deletions TwitterSwiftUI/Core/Components/Users/UserStatsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ struct UserStatsView: View {
@Binding var following: Int
@Binding var followers: Int

var buttonTapped: (FollowStatusType) -> Void
var buttonTapped: (FollowButtonType) -> Void

init(following: Binding<Int>,
followers: Binding<Int>,
buttonTapped: @escaping (FollowStatusType) -> Void) {
buttonTapped: @escaping (FollowButtonType) -> Void) {
_following = following
_followers = followers
self.buttonTapped = buttonTapped
Expand All @@ -31,7 +31,7 @@ struct UserStatsView: View {
Text("\(following)").bold()
.font(.subheadline).bold()
.foregroundColor(.black)
Text(FollowStatusType.following.title)
Text(FollowButtonType.following.title)
.font(.subheadline)
}
}
Expand All @@ -43,7 +43,7 @@ struct UserStatsView: View {
Text("\(followers)").bold()
.font(.subheadline).bold()
.foregroundColor(.black)
Text(FollowStatusType.followers.title)
Text(FollowButtonType.followers.title)
.font(.subheadline)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct UserStatusDetailView: View {
@EnvironmentObject var tabBarViewModel: MainTabBarViewModel
@StateObject var viewModel: UserStatusDetailViewModel

init(initialTab: FollowStatusType, user: User) {
init(initialTab: FollowButtonType, user: User) {
_viewModel = .init(wrappedValue: UserStatusDetailViewModel(initialTab: initialTab, user: user))
}
var body: some View {
Expand All @@ -23,7 +23,7 @@ struct UserStatusDetailView: View {
TabLabel(type: .following),
TabLabel(type: .followers)
]) {
ForEach(FollowStatusType.allCases) { type in
ForEach(FollowButtonType.allCases) { type in
FollowingUserListView(tabType: type)
.environmentObject(self.viewModel)
.frame(width: UIScreen.main.bounds.width)
Expand All @@ -35,7 +35,7 @@ struct UserStatusDetailView: View {
}

@ViewBuilder
func TabLabel(type: FollowStatusType) -> some View {
func TabLabel(type: FollowButtonType) -> some View {
Text(type.title)
.font(.subheadline)
.fontWeight(.bold)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

enum FollowStatusType: Int, CaseIterable, Identifiable {
enum FollowButtonType: Int, CaseIterable, Identifiable {
case following
case followers

Expand All @@ -30,7 +30,7 @@ class UserStatusDetailViewModel: ObservableObject {

@Published var selectedTab: Int

init(initialTab: FollowStatusType, user: User) {
init(initialTab: FollowButtonType, user: User) {
self.selectedTab = initialTab.rawValue
self.user = user

Expand Down
172 changes: 172 additions & 0 deletions TwitterSwiftUI/Core/Profile/View/ProfileEditView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
//
// ProfileEditView.swift
// TwitterSwiftUI
//
// Created by paku on 2023/10/20.
//

import SwiftUI
import Kingfisher

struct ProfileEditView: View {

@StateObject var viewModel: ProfileEditViewModel
@Environment(\.dismiss) var dismiss

init(user: User) {
_viewModel = .init(wrappedValue: ProfileEditViewModel(user: user))
}

var body: some View {

VStack(alignment: .leading, spacing: 0) {
header

ZStack {
Color.gray
.frame(height: 120).opacity(0.6)

Image(systemName: "camera")
.font(.title)
.foregroundColor(.white)
}
.onTapGesture {

}

ZStack {
KFImage(URL(string: viewModel.user.profileImageUrl))
.resizable()
.frame(width: 70, height: 70)
.clipShape(Circle())
.overlay(
Circle().strokeBorder(Color.white, lineWidth: 3)
)
Image(systemName: "camera")
.font(.title2)
.foregroundColor(.white)
}
.padding(.leading, 20)
.offset(y: -20)
.onTapGesture {

}

nameInput

bioInput

loactionInput

webUrlInput

Spacer()
}
}
}

extension ProfileEditView {
var header: some View {
ZStack {
HStack {
Button {
dismiss()
} label: {
Text("キャンセル")
}
Spacer()

Button {
dismiss()
} label: {
Text("保存")
.opacity(viewModel.saveButtonDisable ? 0.5 : 1)
}
.disabled(viewModel.saveButtonDisable)

}

Text("編集")
.font(.headline)
.bold()
}
.foregroundStyle(.black)
.padding(.horizontal)
.padding(.vertical, 6)
.padding(.top, 5)
}

var nameInput: some View {
VStack(spacing: 0) {
Divider()
HStack {
Text("名前")
.fontWeight(.semibold)
TextField("名前を追加", text: $viewModel.name)
.foregroundColor(.blue)
.frame(maxWidth: .infinity)
}
.padding(.horizontal)
.padding(.vertical, 12)
}
.font(.subheadline)
}

var bioInput: some View {
VStack(spacing: 0) {
Divider()
HStack(alignment: .top) {
Text("自己紹介")
.fontWeight(.semibold)
TextField("プロフィールに自己紹介を追加", text: $viewModel.bio, axis: .vertical)
.foregroundColor(.blue)

// 自己紹介のエリアは高さが60あり、TextFieldをtopに配置させるためのSpacer
Spacer()
.frame(width: 1)
.frame(minHeight: 60)
}
.padding(.horizontal)
.padding(.vertical, 12)

}
.font(.subheadline)
}

var loactionInput: some View {
VStack(spacing: 0) {
Divider()
HStack {
Text("場所")
.fontWeight(.semibold)
TextField("場所を追加", text: $viewModel.name)
.foregroundColor(.blue)
.frame(maxWidth: .infinity)
}
.padding(.horizontal)
.padding(.vertical, 12)
}
.font(.subheadline)
}

var webUrlInput: some View {
VStack(spacing: 0) {
Divider()
HStack {
Text("Web")
.fontWeight(.semibold)
TextField("Webサイトを追加", text: $viewModel.name)
.keyboardType(.URL)
.foregroundColor(.blue)
.frame(maxWidth: .infinity)
}
.padding(.horizontal)
.padding(.vertical, 12)
}
.font(.subheadline)
}
}

#Preview {
ProfileEditView(user: .init(username: "username", fullname: "fullname", profileImageUrl: "profileImageUrl", email: "email"))
}
Loading

0 comments on commit 1b1ddb5

Please sign in to comment.