Hi there,
If I open the preview with an iOS device while developing a screen, I can control it with the mouse and I can do actions such as scrolling and clicking. But if I preview a tvOS device, I can't control it with keyboard, or mouse. Can't we test the tvos devices in preview and try the focus actions?
Thanks,
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I am developing a tvOS application and I wanted to use a view like split-screen of course I need focus management in it. I've seen a video from WWDC and my research that this can be done with the prefersDefaultFocus(_:in:)modifier. I even made a little demo. While it works fine if TabView is not used on the screen, prefersDefaultFocus(_:in:) does not work when TabView is added.
Have any of you encountered this situation? How can it be overcome?
Here is my code sample, you can test both cases;
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
//ContentView()
ContentWithTabView()
}
}
}
struct ContentView: View {
@Environment(\.resetFocus) var resetFocus
@Namespace private var namespace
var body: some View {
HStack(spacing: 100) {
Group {
VStack {
Button ("1") {}
.prefersDefaultFocus(in: namespace)
Button ("2") {}
Button ("3") {}
}}
Group{
VStack {
Button ("1") {}
Button ("2") {}
Button ("3") {}
Button ("Reset to default focus") {
resetFocus(in: namespace)
}
}
}
}
.focusScope(namespace)
}
}
struct ContentWithTabView: View {
var body: some View {
NavigationView {
TabView {
ContentView()
.tabItem {
Image(systemName: "house.fill")
Text("Home")
}
ContentView()
.tabItem {
Image(systemName: "house.fill")
Text("Home")
}
}
}
}
}