* ios: create address during onboarding * contact picker * email wip * send email w/t leaving app * fomatting * layout, texts * remove contact picker, add email button to address page * refactor * refactor --------- Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
62 lines
1.8 KiB
Swift
62 lines
1.8 KiB
Swift
//
|
|
// MailView.swift
|
|
// SimpleX (iOS)
|
|
//
|
|
// Created by spaced4ndy on 01.05.2023.
|
|
// Copyright © 2023 SimpleX Chat. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
import UIKit
|
|
import MessageUI
|
|
|
|
struct MailView: UIViewControllerRepresentable {
|
|
@Binding var isShowing: Bool
|
|
@Binding var result: Result<MFMailComposeResult, Error>?
|
|
var subject = ""
|
|
var messageBody = ""
|
|
|
|
class Coordinator: NSObject, MFMailComposeViewControllerDelegate {
|
|
@Binding var isShowing: Bool
|
|
@Binding var result: Result<MFMailComposeResult, Error>?
|
|
|
|
init(isShowing: Binding<Bool>,
|
|
result: Binding<Result<MFMailComposeResult, Error>?>) {
|
|
_isShowing = isShowing
|
|
_result = result
|
|
}
|
|
|
|
func mailComposeController(
|
|
_ controller: MFMailComposeViewController,
|
|
didFinishWith result: MFMailComposeResult,
|
|
error: Error?
|
|
) {
|
|
defer {
|
|
isShowing = false
|
|
}
|
|
if let error = error {
|
|
self.result = .failure(error)
|
|
return
|
|
}
|
|
self.result = .success(result)
|
|
}
|
|
}
|
|
|
|
func makeCoordinator() -> Coordinator {
|
|
return Coordinator(isShowing: $isShowing, result: $result)
|
|
}
|
|
|
|
func makeUIViewController(context: UIViewControllerRepresentableContext<MailView>) -> MFMailComposeViewController {
|
|
let vc = MFMailComposeViewController()
|
|
vc.setSubject(subject)
|
|
vc.setMessageBody(messageBody, isHTML: true)
|
|
vc.mailComposeDelegate = context.coordinator
|
|
return vc
|
|
}
|
|
|
|
func updateUIViewController(_ uiViewController: MFMailComposeViewController,
|
|
context: UIViewControllerRepresentableContext<MailView>) {
|
|
|
|
}
|
|
}
|