feathersui / feathersui-starling

User interface components for Starling Framework and Adobe AIR
https://feathersui.com/learn/as3-starling/
Other
915 stars 386 forks source link

FocusManager: Generalize focus API to include tv platforms #1571

Open jamikado opened 7 years ago

jamikado commented 7 years ago

Josh, maybe you have already thought about this or have plans, but just wanted to throw this out as an official tracked enhancement issue with some ideas.

I realize the current FocusManager is designed around desktop and even the API enforces this with functions like 'nextTabFocus' and 'previousTabFocus', but focus management is just as important on some other AIR platforms, specifically thinking now about tvOS (maybe Android tv support too??).

Granted one can implement their own Feathers FocusManager for tvOS, but really the API might want to generalize at the very least, by switching from 'nextTabFocus' and 'previousTabFocus' to a direction based API? nextFocus(direction:Direction) where maybe there are directions like: Forward, Backward (mapped to existing nextTab and previousTab on desktop), but then also Up, Down, Left, Right directions that map for tvOS remote (along with arrow keys on desktop when appropriate (which I see you added specifically on the TabBar component already)).

(Apple's take on 2D focus: https://developer.apple.com/library/content/documentation/General/Conceptual/AppleTV_PG/WorkingwiththeAppleTVRemote.html )

Secondary, and less important, might also be a concept of focus change speed (which Apple does on tvOS Remote, possibly allowing a faster flip through a List or Grid, or maybe also on a long press repeated arrow key focus change...

I'd also imagine with a default focus manager done right, a Feathers app currently running on desktop and iOS might 'just work' when also built with tvOS focus support.

Thanks for listening Jeff

joshtynjala commented 7 years ago

I'm hoping that the AIR KeyboardEvent on tvOS has the keyLocation property set to KeyLocation.D_PAD when the directional keys are pressed on the remote. That would make it easier for things to "just work" in the default focus manager, since we don't want the arrow keys to change focus on desktop.

Have you played around with AIR on tvOS at all? Do you happen to know if Keyboard.UP/DOWN/LEFT/RIGHT are the key codes used for the remote? And if the keyLocation is set? I don't have any TV devices that I can test with AIR yet.

In addition to TabBar, I recently improved support for arrow keys in the List and GroupedList components too. Previously, you could use the arrow keys to change the selectedindex, but left/top were both selectedIndex-- and right/bottom where selectedIndex++. That worked well for VerticalLayout and HorizontalLayout, but not so much for other layouts. Starting in Feathers 3.3, the layout classes are asked to calculate the new index instead, based on the direction using the RelativePosition constants. Now, TiledRowsLayout and TiledColumnsLayout can navigate the grid in all four directions.

An API for focus changes would probably be similar to what the layouts are doing in lists, and it's basically the same as what you suggested with nextFocus(direction). I'd like some kind of automatic behavior too, so that you don't need to define the nextFocus() behavior manually most of the time. A while back, I remember seeing that Android has an algorithm to figure out how to change focus on devices with a physical input like a d-pad. Feathers should have something like that too.

joshtynjala commented 7 years ago

I see from Apple's documentation for the Siri remote that it doesn't have a d-pad. It uses swipe gestures for navigation. That makes it a little more interesting. Feathers would need to listen for different events on tvOS than on other TV platforms, but it should be able to use the same directional APIs for changing focus.

jamikado commented 7 years ago

Yea, though I was also assuming you might just use AIR's planned mappings for tvOS as documented in their release notes: https://fpdownload.macromedia.com//pub/labs/flashruntimes/shared/pvt/air26_appletv_releasenotes.pdf

using TransformGestureEvent.GESTURE_DIRECTIONAL_TAP and TransformGestureEvent.GESTURE_SWIPE

Interesting that you mention DPad, because in fact, the Siri Remote for tvOS does actually come across on Flash's GameInput API too http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/ui/GameInput.html (because Apple also registers the Siri Remote as a minimal GameController in their native iOS/tvOS GameController framework, so Adobe picks this up in their GameInput API as well) And on GameInput Flash API a Siri Remote has the following controls mapped (among others for the buttons): "DirectionPad Up", "DirectionPad Dpwn", DirectionPad Left", "DirectionPad Right")

So you probably could also support focus control through GameInput device discovery (which probably isn't a bad feature in general if people are using other game controllers with their AIR apps too) when navigating across UIs.

joshtynjala commented 7 years ago

I was also assuming you might just use AIR's planned mappings for tvOS as documented in their release notes: using TransformGestureEvent.GESTURE_DIRECTIONAL_TAP and TransformGestureEvent.GESTURE_SWIPE

I hadn't read the the tvOS details from the AIR release notes when I made my original response. I remember seeing a d-pad on older Apple TV remotes, so I assumed it was still how things were.

After I looked into more detail on Apples website, and saw the swipe gesture stuff, I read the AIR release notes. That's the context of my second response.

jamikado commented 7 years ago

This is super awesome, thanks for integrating all this!

joshtynjala commented 7 years ago

I should mention that tvOS support is stalled until Gamua/Adobe-Runtime-Support#11 is addressed. I don't recall closing this, as it was meant to be left open until I could address tvOS better.