You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recently I wrote a test in the large app that I work on for a view that used a UIViewControllerRepresentable with a toolbar modifier applied to it.
The test failed because it couldn't find the modifier even when searching the parent view for the accessibility identifier of the toolbar button. But, when I embedded the UIViewControllerRepresentable in a ZStack and applied the toolbar to the ZStack instead the test succeeded & the app still worked as expected. I wasn't trying to test other modifiers but it seemed like they were also duplicated in the output, so this could be an issue with any modifier applied to a UIViewControllerRepresentable. It seems like the UIViewControllerRepresentable is acting more like a Group than a View. I'm not sure if that is expected, but it would be great to be able to inspect a modifier that gets applied directly to the view instead of using the workaround.
Code Example
This is a min reproducible example of the view structure:
import SwiftUI
structMyView:View{staticletstrings=["Google","Apple","View Inspector"]@Statevarselected:String?@StatevarpresentChild= false
varbody:someView{VStack{ForEach(Self.strings, id: \.self){ string inButton(action:{
selected = string
presentChild = true
}, label:{Text(string).foregroundColor(.blue).padding()})}
if let selected {NavigationLink(
destination:// ZStack {ChildViewControllerRepresentable(title: selected)// }.navigationBarBackButtonHidden(true).toolbar{ToolbarItem(placement:.navigationBarLeading){Button(action:{
presentChild = false
self.selected =nil}, label:{Image(systemName:"chevron.left")}).accessibility(identifier:"ChildBackButton")}},
isActive: $presentChild,
label:{EmptyView()}).accessibility(identifier:"ParentNavigationLink")}}}}structChildViewControllerRepresentable:UIViewControllerRepresentable{lettitle:Stringfunc makeUIViewController(context:Context)->WrapperViewController{returnWrapperViewController(title: title)}classCoordinator{}func makeCoordinator()->Self.Coordinator{Coordinator()}func updateUIViewController(_:WrapperViewController, context _:Context){}}finalclassWrapperViewController:UIViewController{init(title:String?){
super.init(nibName:nil, bundle:nil)self.title = title
}requiredinit?(coder _:NSCoder){fatalError("init(coder:) has not been implemented")}}
And the associated test method which will fail if you copy & paste the code from above, but will succeed if you comment the ZStack back in:
Recently I wrote a test in the large app that I work on for a view that used a
UIViewControllerRepresentable
with a toolbar modifier applied to it.The test failed because it couldn't find the modifier even when searching the parent view for the accessibility identifier of the toolbar button. But, when I embedded the
UIViewControllerRepresentable
in aZStack
and applied the toolbar to theZStack
instead the test succeeded & the app still worked as expected. I wasn't trying to test other modifiers but it seemed like they were also duplicated in the output, so this could be an issue with any modifier applied to aUIViewControllerRepresentable
. It seems like the UIViewControllerRepresentable is acting more like aGroup
than aView
. I'm not sure if that is expected, but it would be great to be able to inspect a modifier that gets applied directly to the view instead of using the workaround.Code Example
This is a min reproducible example of the view structure:
And the associated test method which will fail if you copy & paste the code from above, but will succeed if you comment the
ZStack
back in:Here's a screenshot of the output when I run the test locally:
The text was updated successfully, but these errors were encountered: