111 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
			
		
		
	
	
			111 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
//
 | 
						|
//  SodaDialog.swift
 | 
						|
//  SodaLive
 | 
						|
//
 | 
						|
//  Created by klaus on 2023/08/10.
 | 
						|
//
 | 
						|
 | 
						|
import SwiftUI
 | 
						|
 | 
						|
struct SodaDialog: View {
 | 
						|
    
 | 
						|
    let title: String
 | 
						|
    let desc: String
 | 
						|
    let confirmButtonTitle: String
 | 
						|
    let confirmButtonAction: () -> Void
 | 
						|
    let cancelButtonTitle: String
 | 
						|
    let cancelButtonAction: () -> Void
 | 
						|
    let textAlignment: TextAlignment
 | 
						|
    
 | 
						|
    init(
 | 
						|
        title: String,
 | 
						|
        desc: String,
 | 
						|
        confirmButtonTitle: String,
 | 
						|
        confirmButtonAction: @escaping () -> Void,
 | 
						|
        cancelButtonTitle: String = "",
 | 
						|
        cancelButtonAction: @escaping () -> Void = {},
 | 
						|
        textAlignment: TextAlignment = .leading
 | 
						|
    ) {
 | 
						|
        self.title = title
 | 
						|
        self.desc = desc
 | 
						|
        self.confirmButtonTitle = confirmButtonTitle
 | 
						|
        self.confirmButtonAction = confirmButtonAction
 | 
						|
        self.cancelButtonTitle = cancelButtonTitle
 | 
						|
        self.cancelButtonAction = cancelButtonAction
 | 
						|
        self.textAlignment = textAlignment
 | 
						|
    }
 | 
						|
    
 | 
						|
    var body: some View {
 | 
						|
        GeometryReader { geo in
 | 
						|
            ZStack {
 | 
						|
                Color.black
 | 
						|
                    .opacity(0.5)
 | 
						|
                    .frame(width: geo.size.width, height: geo.size.height)
 | 
						|
                
 | 
						|
                VStack(spacing: 0) {
 | 
						|
                    Text(title)
 | 
						|
                        .font(.custom(Font.bold.rawValue, size: 18.3))
 | 
						|
                        .foregroundColor(Color.graybb)
 | 
						|
                        .padding(.top, 40)
 | 
						|
                    
 | 
						|
                    Text(desc)
 | 
						|
                        .font(.custom(Font.medium.rawValue, size: 15))
 | 
						|
                        .foregroundColor(Color.graybb)
 | 
						|
                        .multilineTextAlignment(textAlignment)
 | 
						|
                        .padding(.top, 12)
 | 
						|
                        .padding(.horizontal, 13.3)
 | 
						|
                        .fixedSize(horizontal: false, vertical: true)
 | 
						|
                    
 | 
						|
                    HStack(spacing: 13.3) {
 | 
						|
                        if cancelButtonTitle.count > 0 {
 | 
						|
                            Text(cancelButtonTitle)
 | 
						|
                                .font(.custom(Font.bold.rawValue, size: 15.3))
 | 
						|
                                .foregroundColor(Color.button)
 | 
						|
                                .padding(.vertical, 16)
 | 
						|
                                .frame(width: (geo.size.width - 66.7) / 3)
 | 
						|
                                .background(Color.bg)
 | 
						|
                                .cornerRadius(8)
 | 
						|
                                .overlay(
 | 
						|
                                    RoundedRectangle(cornerRadius: 8)
 | 
						|
                                        .stroke(Color.button, lineWidth: 1)
 | 
						|
                                )
 | 
						|
                                .onTapGesture {
 | 
						|
                                    cancelButtonAction()
 | 
						|
                                }
 | 
						|
                        }
 | 
						|
                        
 | 
						|
                        Text(confirmButtonTitle)
 | 
						|
                            .font(.custom(Font.bold.rawValue, size: 15.3))
 | 
						|
                            .foregroundColor(Color.white)
 | 
						|
                            .padding(.vertical, 16)
 | 
						|
                            .frame(width: (geo.size.width - 66.7) * 2 / 3)
 | 
						|
                            .background(Color.button)
 | 
						|
                            .cornerRadius(8)
 | 
						|
                            .onTapGesture {
 | 
						|
                                confirmButtonAction()
 | 
						|
                            }
 | 
						|
                    }
 | 
						|
                    .padding(.top, 45)
 | 
						|
                    .padding(.bottom, 16.7)
 | 
						|
                }
 | 
						|
                .frame(width: geo.size.width - 26.7, alignment: .center)
 | 
						|
                .background(Color.gray22)
 | 
						|
                .cornerRadius(10)
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
struct SodaDialog_Previews: PreviewProvider {
 | 
						|
    static var previews: some View {
 | 
						|
        SodaDialog(
 | 
						|
            title: "작성글 등록",
 | 
						|
            desc: "작성한 글을 등록하시겠습니까?",
 | 
						|
            confirmButtonTitle: "결제 후 입장",
 | 
						|
            confirmButtonAction: {},
 | 
						|
            cancelButtonTitle: "취소",
 | 
						|
            cancelButtonAction: {}
 | 
						|
        )
 | 
						|
    }
 | 
						|
}
 |