TextFieldAlert.swift (1764B)
1 // 2 // TextFieldAlert.swift 3 // damus 4 // 5 // Created by William Casarin on 2022-06-09. 6 // 7 8 import SwiftUI 9 10 struct TextFieldAlert<Presenting>: View where Presenting: View { 11 @Binding var isShowing: Bool 12 @Binding var text: String 13 let presenting: Presenting 14 let title: String 15 16 var body: some View { 17 GeometryReader { (deviceSize: GeometryProxy) in 18 ZStack { 19 self.presenting 20 .disabled(isShowing) 21 VStack { 22 Text(self.title) 23 TextField(NSLocalizedString("Relay", comment: "Text field for relay server. Used for testing purposes."), text: self.$text) 24 Divider() 25 HStack { 26 Button(action: { 27 withAnimation { 28 self.isShowing.toggle() 29 } 30 }) { 31 Text("Dismiss", comment: "Button to dismiss a text field alert.") 32 } 33 } 34 } 35 .padding() 36 .background(Color.white) 37 .frame( 38 width: deviceSize.size.width*0.7, 39 height: deviceSize.size.height*0.7 40 ) 41 .shadow(radius: 1) 42 .opacity(self.isShowing ? 1 : 0) 43 } 44 } 45 } 46 47 } 48 49 50 extension View { 51 52 func textFieldAlert(isShowing: Binding<Bool>, 53 text: Binding<String>, 54 title: String) -> some View { 55 TextFieldAlert(isShowing: isShowing, 56 text: text, 57 presenting: self, 58 title: title) 59 } 60 61 }