How should i get FocusState from ChildView to ParentView in SwiftUI?

I am still kinda a newbie in programming. I have a problem how to deal with FocusState in my project.

My parent View has an enum created on top:

enum RegistrationFocus: Hashable { case username, password, confirmPassword, nameAndSurname, email, confirmEmail, phoneNumber }

And i have a focusState variable inside my struct

@FocusState var focus: RegistrationFocus?

My childview is in a VStack to display all views. (only wrote 3 down there for now)
PersonalUserDetailsRow(title: "UserName", text: $registerModel.username, textContentType: .username, focus: $focus, focusfield: .username) PersonalUserDetailsRow(title: "Password", text: $registerModel.password, textContentType: .newPassword, focus: $focus, focusfield: .password) PersonalUserDetailsRow(title: "Confirm Password", text: $registerModel.confirmPassword, textContentType: .confirmPassword focus: $focus, focusfield: .confirmPassword)

And my ChildView looks like this:

`struct PersonalUserDetailsRow: View {

var title: String
@Binding var text: String
let textContentType: UITextContentType
var focus: FocusState<RegistrationFocus?>.Binding
@State var focusField: RegistrationFocus?

var body: some View {

if textContentType == .newPassword {

SecureField(title, text: $text)

.padding(.top, 15)

.disableAutocorrection(true)

.textContentType(textContentType)

.focused(focus.projectedValue, equals: focusField)

Divider() .overlay(Color.black)`

So my child view does contain var focus: FocusState<RegistrationFocus?>.Binding and State focusField: RegistrationFocus?
But i have no clue how to use those 2.
I want to go to the next textField when the user tappes the return key on keyboard.

I have seen many examples where people use 2 textfields in Parent view and i understand those examples and how to move around textFields when using .focused(, equals:).

But i cant find any examples how to do this with a child View, specialy with this .focused(focus.projectedValue, equals: focusField) if its even correct.

How should i do this so it will work?
And i keep geting this error: The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions. with the above code

Any help appreciated. I suck at explaining, so hope people understand what i am asking .
Thank you.

I tried both of these :

var focus: FocusState<RegistrationFocus?>.Binding @State var focusField: RegistrationFocus?
@binding var focusField doesnt work.

And i dont really want to copy paste the textField and Divider() from child view 7 times in my parents view. It will be just to much copy pasting. I want to learn how to use the custom view with FocusState in my parents view.

New contributor

Anze Slapar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật