-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove
Modifier.handleDPadKeyEvents
from pillarbox-ui
- Loading branch information
Showing
9 changed files
with
121 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/extension/ModifierExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) SRG SSR. All rights reserved. | ||
* License information is available from the LICENSE file. | ||
*/ | ||
package ch.srgssr.pillarbox.demo.tv.extension | ||
|
||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.input.key.Key | ||
import androidx.compose.ui.input.key.KeyEventType | ||
import androidx.compose.ui.input.key.key | ||
import androidx.compose.ui.input.key.onPreviewKeyEvent | ||
import androidx.compose.ui.input.key.type | ||
|
||
/** | ||
* This [Modifier] allows you to define actions to perform when a button of the D-pad or the back button is press. Each action returns a [Boolean] | ||
* to indicate if the event was handled or not. | ||
* | ||
* @param onLeft The action to perform when the left button is press. | ||
* @param onUp The action to perform when the up button is press. | ||
* @param onRight The action to perform when the right button is press. | ||
* @param onDown The action to perform when the down button is press. | ||
* @param onEnter The action to perform when the enter button is press. | ||
* @param onBack The action to perform when the back button is press. | ||
*/ | ||
fun Modifier.onDpadEvent( | ||
onLeft: () -> Boolean = { false }, | ||
onUp: () -> Boolean = { false }, | ||
onRight: () -> Boolean = { false }, | ||
onDown: () -> Boolean = { false }, | ||
onEnter: () -> Boolean = { false }, | ||
onBack: () -> Boolean = { false } | ||
): Modifier { | ||
return onPreviewKeyEvent { | ||
if (it.type == KeyEventType.KeyDown) { | ||
when (it.key) { | ||
Key.DirectionLeft, | ||
Key.SystemNavigationLeft, | ||
-> onLeft() | ||
|
||
Key.DirectionUp, | ||
Key.SystemNavigationUp, | ||
-> onUp() | ||
|
||
Key.DirectionRight, | ||
Key.SystemNavigationRight, | ||
-> onRight() | ||
|
||
Key.DirectionDown, | ||
Key.SystemNavigationDown, | ||
-> onDown() | ||
|
||
Key.Enter, | ||
Key.DirectionCenter, | ||
Key.NumPadEnter, | ||
-> onEnter() | ||
|
||
Key.Back -> onBack() | ||
|
||
else -> false | ||
} | ||
} else { | ||
false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 0 additions & 87 deletions
87
pillarbox-ui/src/main/java/ch/srgssr/pillarbox/ui/extension/DPadExtensions.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.