Skip to content

Commit

Permalink
[feat] 회원 탈퇴 Custom dropdownView 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
Byeonjinha committed Nov 18, 2023
1 parent 23367ac commit e5f0740
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// DropdownItem.swift
// Model
//
// Created by Byeon jinha on 11/18/23.
// Copyright © 2023 Wonji Suh. All rights reserved.
//

import Foundation

public struct DropdownItem: Identifiable {
public let id: Int
public let title: String
public let onSelect: () -> Void

public init(id: Int, title: String, onSelect: @escaping () -> Void) {
self.id = id
self.title = title
self.onSelect = onSelect
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// CustomDropdownMenu.swift
// Profile
//
// Created by Byeon jinha on 11/18/23.
// Copyright © 2023 Wonji Suh. All rights reserved.
//

import Common
import DesignSystem
import Model
import Authorization
import SwiftUI


struct CustomDropdownMenu: View {
@State var isSelecting = false
@State var selectionTitle = "이런 점이 불편했어요."
@State var selectedRowId = 0

var body: some View {
VStack {
HStack {
VStack {
HStack {
Text(isSelecting ? "선택해주세요." : selectionTitle)
.pretendardFont(family: .Medium, size: 16)
.foregroundColor(isSelecting ? .basicGray5 : .basicGray7)
.padding(EdgeInsets(top: 12, leading: 16, bottom: 12, trailing: 0))
Spacer()
VStack {
Image(systemName: isSelecting ? "chevron.up" : "chevron.down")
.foregroundColor(.basicGray8)
.padding(16)
Spacer()
}
}
if isSelecting {

VStack(spacing: 0) {
DropdownMenuItemView(isSelecting: $isSelecting, selectiontitle: $selectionTitle, selectionId: $selectedRowId, item: .init(id: 1, title: "서비스 이용이 불편해요.", onSelect: {}))
DropdownMenuItemView(isSelecting: $isSelecting, selectiontitle: $selectionTitle, selectionId: $selectedRowId, item: .init(id: 2, title: "명언이 마음에 들지 않아요.", onSelect: {}))
DropdownMenuItemView(isSelecting: $isSelecting, selectiontitle: $selectionTitle, selectionId: $selectedRowId, item: .init(id: 3, title: "비슷한 서비스 앱이 더 좋아요.", onSelect: {}))
DropdownMenuItemView(isSelecting: $isSelecting, selectiontitle: $selectionTitle, selectionId: $selectedRowId, item: .init(id: 3, title: "자주 사용하지 않아요.", onSelect: {}))
}
}
}
}
.frame(width: UIScreen.screenWidth - 40, height: isSelecting ? 240 : 48)
.overlay(
RoundedRectangle(cornerRadius: 8)
.stroke(lineWidth: 1)
.foregroundColor(.basicGray4)
)
.padding(EdgeInsets(top: 12, leading: 20, bottom: 12, trailing: 20))
}
.frame(maxWidth: .infinity)
.padding(.vertical)
.cornerRadius(5)
.onTapGesture {
isSelecting.toggle()
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// DropdownMenuItemView.swift
// Profile
//
// Created by Byeon jinha on 11/18/23.
// Copyright © 2023 Wonji Suh. All rights reserved.
//

import Common
import DesignSystem
import Model
import Authorization
import SwiftUI

struct DropdownMenuItemView: View {
@Binding var isSelecting: Bool
@Binding var selectiontitle: String
@Binding var selectionId: Int

let item: DropdownItem

var body: some View {
Button(action: {
isSelecting = false
selectiontitle = item.title
item.onSelect()
}) {
HStack {
Text(item.title)
.foregroundColor(.basicGray9)
.pretendardFont(family: .Medium, size: 16)
.padding(.leading, 16)

Spacer()
}
.frame(width: UIScreen.screenWidth - 40, height: 48)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,33 @@ struct WithDrawView: View {

VStack {
topHeaderBackButton()
withDrawViewTitle()
CustomDropdownMenu()
Spacer()
}
}
}

@ViewBuilder
private func withDrawViewTitle() -> some View {
VStack {
HStack {
Text("어떤 점이 불편하셨는지")
.padding(.leading, 20)
Spacer()
}
HStack {
Text("말씀해 주실 수 있을까요?")
.padding(.leading, 20)
Spacer()
}
}
.frame(width: UIScreen.screenWidth, height: 96, alignment: .leading)
.foregroundColor(.basicGray9)

.pretendardFont(family: .Medium, size: 18)
}

@ViewBuilder
private func topHeaderBackButton() -> some View {
Spacer()
Expand All @@ -56,7 +77,7 @@ struct WithDrawView: View {
presentationMode.wrappedValue.dismiss()
}


Spacer()
}
.padding(.horizontal, 20)
Expand All @@ -67,79 +88,3 @@ struct WithDrawView: View {
}


struct CustomDropdownMenu: View {
@State var isSelecting = false
@State var selectionTitle = "Selected option"
@State var selectedRowId = 0

var body: some View {
VStack {
HStack {
Text(selectionTitle)
.font(.system(size: 16, weight: .semibold, design: .rounded))

Spacer()
Image(systemName: "chevron.down")
.font(.system(size: 16, weight: .semibold))
}
.padding(.horizontal)
.foregroundColor(.white)

if isSelecting {
Divider()
.background(.white)
.padding(.horizontal)

VStack(spacing: 5) {
DropdownMenuItemView(isSelecting: $isSelecting, selectiontitle: $selectionTitle, selectionId: $selectedRowId, item: .init(id: 1, title: "Messages", iconImage: Image(systemName: "envelope"), onSelect: {}))
DropdownMenuItemView(isSelecting: $isSelecting, selectiontitle: $selectionTitle, selectionId: $selectedRowId, item: .init(id: 2, title: "Archived", iconImage: Image(systemName: "archivebox"), onSelect: {}))
DropdownMenuItemView(isSelecting: $isSelecting, selectiontitle: $selectionTitle, selectionId: $selectedRowId, item: .init(id: 3, title: "Trash", iconImage: Image(systemName: "trash"), onSelect: {}))
}

}

}
.frame(maxWidth: .infinity)
.padding(.vertical)
.background(Color(uiColor: UIColor.systemIndigo))
.cornerRadius(5)
.onTapGesture {
isSelecting.toggle()
}
}

}

struct DropdownMenuItemView: View {
@Binding var isSelecting: Bool
@Binding var selectiontitle: String
@Binding var selectionId: Int

let item: DropdownItem

var body: some View {
Button(action: {
isSelecting = false
selectiontitle = item.title
item.onSelect()
}) {
HStack {
Image(systemName: "checkmark")
.font(.system(size: 14, weight: .bold))
Text(item.title)
.font(.system(size: 16, weight: .regular, design: .rounded))
Spacer()
item.iconImage
}
.padding(.horizontal)
.foregroundColor(.white)
}
}
}

struct DropdownItem: Identifiable {
let id: Int
let title: String
let iconImage: Image
let onSelect: () -> Void
}

0 comments on commit e5f0740

Please sign in to comment.