Q:

App freezes when return button is tapped on keyboard with UIViewRepresentable

When I click the return button on the keyboard, the application freezes and never becomes responsive again. I am using a UIViewRepresentable that returns a UITextField because I am unable to create an outline on the text using SwiftUI. I'm running this on Xcode beta 5 on and iPhone XR simulator. 
import SwiftUI
import UIKit

struct CustomTextField: View {
    @State var text: String
    @State var pos: CGPoint

    var body: some View {
        StrokeTextLabel(text: text)
//            .frame(width: UIScreen.main.bounds.width - 16, height: 40, alignment: .center)
            .position(pos)
            .gesture(dragGesture)
    }

    var dragGesture : some Gesture {
        DragGesture()
            .onChanged { value in
                self.pos = value.location
                print(self.pos)
        }
    }
}

struct StrokeTextLabel: UIViewRepresentable {
    var text: String

    func makeUIView(context: Context) -> UITextField {
        let attributedStringParagraphStyle = NSMutableParagraphStyle()
        attributedStringParagraphStyle.alignment = NSTextAlignment.center
        let attributedString = NSAttributedString(
            string: text,
            attributes:[
                NSAttributedString.Key.strokeColor : UIColor.white,
                NSAttributedString.Key.foregroundColor : UIColor.black,
                NSAttributedString.Key.strokeWidth : -4.0,
                NSAttributedString.Key.font: UIFont(name: "impact", size: 50.0)!
            ]
        )

        let strokeLabel = UITextField(frame: CGRect.zero)
        strokeLabel.attributedText = attributedString
        strokeLabel.backgroundColor = UIColor.clear
        strokeLabel.sizeToFit()
        strokeLabel.center = CGPoint.init(x: 0.0, y: 0.0)
        strokeLabel.sizeToFit()
        return strokeLabel
    }

    func updateUIView(_ uiView: UITextField, context: Context) {}
}

#if DEBUG
struct CustomTextField_Previews: PreviewProvider {
    static var previews: some View {
        CustomTextField(text: "test text", pos: CGPoint(x: 300, y: 500))
    }
}
#endif

I expect the application to be close the keyboard when the return button is clicked but instead the app freezes.

A:

Credits to this answer goes to https://github.com/valvoline/SATextField/blob/master/SATextField/ContentView.swift. This answer wouldn't be here without the above source.
Nothing major changed.
struct CustomTextField: View {
    @State var text: String
    @State var pos: CGPoint

    var body: some View {
        StrokeTextLabel(text: $text, changeHandler: { newString in
            self.text = newString
        }, onCommitHandler: {
            print("commitHandler")
        })
            .position(pos)
            .gesture(dragGesture)
    }

    var dragGesture : some Gesture {
        DragGesture()
            .onChanged { value in
                self.pos = value.location
                print(self.pos)
        }
    }
}

Added UITextField and UITextFieldDelegate to use their functions
class WrappableTextField: UITextField, UITextFieldDelegate {
    var textFieldChangedHandler: ((String)->Void)?
    var onCommitHandler: (()->Void)?

    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }

    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        if let currentValue = textField.text as NSString? {
            let proposedValue = currentValue.replacingCharacters(in: range, with: string)
            textFieldChangedHandler?(proposedValue as String)
        }
        return true
    }

    func textFieldDidEndEditing(_ textField: UITextField) {
        onCommitHandler?()
    }
}

Use the delegate as an object and add the attributes. Also made the string a Binding
struct StrokeTextLabel: UIViewRepresentable {
    private let tmpView = WrappableTextField()

    @Binding var text: String

    //var exposed to SwiftUI object init
    var changeHandler:((String)->Void)?
    var onCommitHandler:(()->Void)?

    func makeUIView(context: Context) -> UITextField {
        tmpView.delegate = tmpView
        tmpView.onCommitHandler = onCommitHandler
        tmpView.textFieldChangedHandler = changeHandler

        let attributedStringParagraphStyle = NSMutableParagraphStyle()
        attributedStringParagraphStyle.alignment = NSTextAlignment.center
        let attributedString = NSAttributedString(
            string: text,
            attributes:[
                NSAttributedString.Key.strokeColor : UIColor.white,
                NSAttributedString.Key.foregroundColor : UIColor.black,
                NSAttributedString.Key.strokeWidth : -4.0,
                NSAttributedString.Key.font: UIFont(name: "impact", size: 50.0)!
            ]
        )

        tmpView.attributedText = attributedString
        tmpView.autocorrectionType = .no
        tmpView.keyboardType = .default

        return tmpView
    }

    func updateUIView(_ uiView: UITextField, context: Context) {
        uiView.setContentHuggingPriority(.defaultHigh, for: .vertical)
        uiView.setContentHuggingPriority(.defaultLow, for: .horizontal)
    }
}

