How to detect when a TextField becomes active in SwiftUI?

The answer is to initialize TextField with the onEditingChanged parameter.

We can then execute a closure conditionally depending upon whether the text field was edited or changes were committed:

TextField("", text: $email, onEditingChanged: { changed in
  if changed {
    // User began editing the text field
  }
  else {
    // User tapped the return key
  }
})