[go: nahoru, domu]

Skip to content

Commit

Permalink
Merge pull request #177 from Geletinousamigo/main
Browse files Browse the repository at this point in the history
Fix #174: Selecting Seekbar to move video time freezes controls
  • Loading branch information
chikoski authored Jun 12, 2024
2 parents b503b7b + 786fe16 commit 827d6e7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import androidx.compose.ui.unit.dp
import androidx.tv.material3.ExperimentalTvMaterial3Api
import androidx.tv.material3.MaterialTheme
import com.google.jetstream.presentation.utils.handleDPadKeyEvents
import com.google.jetstream.presentation.utils.ifElse

@OptIn(ExperimentalComposeUiApi::class, ExperimentalTvMaterial3Api::class)
@Composable
Expand Down Expand Up @@ -70,35 +71,35 @@ fun RowScope.VideoPlayerControllerIndicator(
}
}

val handleSeekEventModifier = Modifier.handleDPadKeyEvents(
onEnter = {
isSelected = !isSelected
onSeek(seekProgress)
},
onLeft = {
seekProgress = (seekProgress - 0.1f).coerceAtLeast(0f)
},
onRight = {
seekProgress = (seekProgress + 0.1f).coerceAtMost(1f)
}
)

val handleDpadCenterClickModifier = Modifier.handleDPadKeyEvents(
onEnter = {
seekProgress = progress
isSelected = !isSelected
}
)

Canvas(
modifier = Modifier
.weight(1f)
.height(animatedIndicatorHeight)
.padding(horizontal = 4.dp)
.handleDPadKeyEvents(
onEnter = {
if (isSelected) {
onSeek(seekProgress)
focusManager.moveFocus(FocusDirection.Exit)
} else {
seekProgress = progress
}
isSelected = !isSelected
},
onLeft = {
if (isSelected) {
seekProgress = (seekProgress - 0.1f).coerceAtLeast(0f)
} else {
focusManager.moveFocus(FocusDirection.Left)
}
},
onRight = {
if (isSelected) {
seekProgress = (seekProgress + 0.1f).coerceAtMost(1f)
} else {
focusManager.moveFocus(FocusDirection.Right)
}
}
.ifElse(
condition = isSelected,
ifTrueModifier = handleSeekEventModifier,
ifFalseModifier = handleDpadCenterClickModifier
)
.focusable(interactionSource = interactionSource),
onDraw = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ fun Modifier.handleDPadKeyEvents(
}

KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_NUMPAD_ENTER -> {
onEnter?.invoke().also {
onEnter?.apply {
onActionUp(::invoke)
return@onPreviewKeyEvent true
}
}
Expand Down

0 comments on commit 827d6e7

Please sign in to comment.