Post

Replies

Boosts

Views

Activity

Crash on the TextView in the ForEach and wrapped to the ScrollView and programmatically set FocusState.
I have a crash in my apps(6 different apps) on the TextField: I have a code for adding players with TextField in the ForEach and wrapped to ScrollView My code: @StateObject var viewState: PlayerViewState @FocusState var focusItemId: UUID? var body: some View { GeometryReader { reader in ZStack { VStack(spacing: 0) { HStack { Button { viewState.didTapBackButton() } label: { Text(L10n.Localizable.BackButton.title) .font(.HelveticaNeue(size: 20)) .foregroundColor(Asset.accentColor.swiftUIColor) } Spacer() }.padding(EdgeInsets(top: 20, leading: 8, bottom: 0, trailing: 0)) HStack { Spacer() Text(L10n.Localizable.Players.title.uppercased()) .font(.HelveticaNeueMedium(size: 65)) .foregroundColor(Asset.textForegroundColor.swiftUIColor) .padding(EdgeInsets(top: 24, leading: 0, bottom: 0, trailing: 12)) }.padding(.bottom, 42) ZStack { HStack { Text(L10n.Localizable.Players.Text.enterNameClickOnText) .font(.system(size: 30)) .foregroundColor(Asset.textForegroundColor.swiftUIColor) .rotationEffect(.degrees(-90)) .fixedSize() .frame(width: 50, height: 180) .padding(.bottom, 200) .padding(.leading, 8) Spacer() } ScrollViewReader { value in ScrollView { VStack { ForEach($viewState.players) { player in VStack { TextField(L10n.Localizable.Players.Text.enterName, text: player.name) .focused($focusItemId, equals: player.id) .font(.HelveticaNeueMedium(size: 32)) .foregroundColor(Asset.textForegroundColor.swiftUIColor) .multilineTextAlignment(.trailing) .frame(width: reader.size.width-80) .textContentType(.name) .id(player.id) Spacer() .frame(height: 27) }.padding(.trailing, 12) } Spacer().frame(height: 450) } } .onReceive(viewState.$focusItemId) { item in withAnimation { focusItemId = item value.scrollTo(item, anchor: .top) } } }.padding(.leading, 50) } } } HStack { Spacer().frame(width: 80) VStack { Spacer() VStack(spacing: 30) { Spacer() Button { viewState.didTapAddPlayerButton() } label: { HStack { Spacer() Text(L10n.Localizable.Players.Button.addPlayer) .font(.HelveticaNeueLight(size: 35)) .foregroundColor(Asset.accentColor.swiftUIColor) } }.padding(.trailing, 20) Button { viewState.didTapToPlayButton() } label: { HStack { Spacer() Text(L10n.Localizable.Players.Button.next) .font(.HelveticaNeueMedium(size: 44)) .foregroundColor(Asset.accentColor.swiftUIColor) } }.padding(.trailing, 20) } .frame(height: 150) .ignoresSafeArea() .background(Asset.mainColor.swiftUIColor) } } } .background(Asset.mainColor.swiftUIColor) .navigationBarBackButtonHidden(true) .onAppear { viewState.didAppear() } } } In the app organizer I see that: libswiftCore.dylib Array.subscript.read 5 libswiftCore.dylib protocol witness for Collection.subscript.read in conformance [A] 6 SwiftUl closure #1 in Binding<A>.subscript.getter 7 SwiftUl FunctionalLocation.get() 8 SwiftUl LocationBox.get() 60 SwiftUl runApp<A>(_:) 61 SwiftUl static App.main () 62 fivesecondbattle static RootApp.$main() 63 fivesecondbattle main 64 dyld start Note message: SwiftUI: closure #1 in Binding<A>.subscript.getter + 212 Detailed log: https://gist.github.com/maukur/4efce75982cc2e1d33aedf1add461493 Any ideas on how to fix it?
1
0
203
Jul ’24