Return highlighting by focus; move focus to navbar by Down arrow

This commit is contained in:
kilowatt 2020-11-03 18:26:24 +03:00
parent 55c7d32c13
commit ca8969eb28
2 changed files with 16 additions and 8 deletions

View File

@ -250,20 +250,27 @@ class _MainScreenState extends State<MainScreen> with SingleTickerProviderStateM
switch (keyCode) {
case 127: // Menu on Android TV
case 327: // EPG on Hisense TV
navigatorFocusNode.requestFocus();
navigatorFocusNode.focusInDirection(TraversalDirection.down);
focusToNavbar(navigatorFocusNode);
break;
case 22: // LEFT + RIGHT
case 21:
if (_keyPressed == 21 && keyCode == 22 || _keyPressed == 22 && keyCode == 21) {
navigatorFocusNode.requestFocus();
navigatorFocusNode.focusInDirection(TraversalDirection.down);
focusToNavbar(navigatorFocusNode);
}
_keyPressed = keyCode;
Future.delayed(Duration(milliseconds: 100), () => {
_keyPressed = 0
});
break;
case 20: // DOWN
// If it's bottom row, go to navigation bar
var row = FocusManager.instance.primaryFocus.parent;
var column = row.parent;
if (column.children.last == row) {
focusToNavbar(navigatorFocusNode);
}
break;
case 19: // UP
if (navigatorFocusNode.hasFocus) {
rootFocusNode.focusInDirection(TraversalDirection.up);
@ -287,6 +294,11 @@ class _MainScreenState extends State<MainScreen> with SingleTickerProviderStateM
};
}
void focusToNavbar(FocusScopeNode navigatorFocusNode) {
navigatorFocusNode.requestFocus();
navigatorFocusNode.focusInDirection(TraversalDirection.down); // If player bar is hidden, focus won't be visible, so go down once more
}
@override
Widget build(BuildContext context) {
FocusScopeNode navigatorFocusNode = FocusScopeNode(); // for bottom navigator

View File

@ -135,7 +135,6 @@ class ArtistTile extends StatelessWidget {
return SizedBox(
width: 150,
child: Container(
color: Theme.of(context).scaffoldBackgroundColor,
child: InkWell(
onTap: onTap,
onLongPress: onHold,
@ -246,7 +245,6 @@ class PlaylistCardTile extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
color: Theme.of(context).scaffoldBackgroundColor,
height: 180.0,
child: InkWell(
onTap: onTap,
@ -293,7 +291,6 @@ class SmartTrackListTile extends StatelessWidget {
Widget build(BuildContext context) {
return Container(
height: 200.0,
color: Theme.of(context).scaffoldBackgroundColor,
child: InkWell(
onTap: onTap,
onLongPress: onHold,
@ -364,7 +361,6 @@ class AlbumCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
color: Theme.of(context).scaffoldBackgroundColor,
child: InkWell(
onTap: onTap,
onLongPress: onHold,