62 lines
1.7 KiB
Swift
62 lines
1.7 KiB
Swift
//
|
|
// TextFieldAlert.swift
|
|
// damus
|
|
//
|
|
// Created by William Casarin on 2022-06-09.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct TextFieldAlert<Presenting>: View where Presenting: View {
|
|
@Binding var isShowing: Bool
|
|
@Binding var text: String
|
|
let presenting: Presenting
|
|
let title: String
|
|
|
|
var body: some View {
|
|
GeometryReader { (deviceSize: GeometryProxy) in
|
|
ZStack {
|
|
self.presenting
|
|
.disabled(isShowing)
|
|
VStack {
|
|
Text(self.title)
|
|
TextField(NSLocalizedString("Relay", comment: "Text field for relay server. Used for testing purposes."), text: self.$text)
|
|
Divider()
|
|
HStack {
|
|
Button(action: {
|
|
withAnimation {
|
|
self.isShowing.toggle()
|
|
}
|
|
}) {
|
|
Text("Dismiss", comment: "Button to dismiss a text field alert.")
|
|
}
|
|
}
|
|
}
|
|
.padding()
|
|
.background(Color.white)
|
|
.frame(
|
|
width: deviceSize.size.width*0.7,
|
|
height: deviceSize.size.height*0.7
|
|
)
|
|
.shadow(radius: 1)
|
|
.opacity(self.isShowing ? 1 : 0)
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
extension View {
|
|
|
|
func textFieldAlert(isShowing: Binding<Bool>,
|
|
text: Binding<String>,
|
|
title: String) -> some View {
|
|
TextFieldAlert(isShowing: isShowing,
|
|
text: text,
|
|
presenting: self,
|
|
title: title)
|
|
}
|
|
|
|
}
|