'How to highlight a Text when is tapped on a TextField in SwiftUI?

I'm trying to highlight a text when is pressend on a TextField.

I have a bunch of TextFields on that view, but I will post just 2 of them for simplicity.

This is how I'm trying to do it, but is a little big buggy :

    @State private var colorField : Bool = false
    @State private var colorField2 : Bool = false

  Text(Texts.livrareViewText5)
                        .padding(.top)
                        .foregroundColor(colorField == false ? Color.gray : .orange)
                    EntryField(placeHolder: "Name", field: firstName)
                        .onTapGesture{
                            colorField = true
                        }


                   Text(Texts.livrareViewText6)
                        .padding(.top)
                        .foregroundColor(colorField2 == false ? Color.gray : .orange)
                    EntryField(placeHolder: "Last Name", field: lastName)
                        .onTapGesture{
                            colorField = false
                            colorField2 = true
                        }

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source