Skip to content

Commit

Permalink
Make drop down selectable on Android TV. (#9849)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaynewstrom-stripe authored Jan 3, 2025
1 parent d2e57cb commit 69a3709
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.stripe.android.uicore.elements

import android.content.pm.PackageManager
import androidx.annotation.RestrictTo
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
Expand All @@ -15,6 +16,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredSizeIn
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.selection.selectable
import androidx.compose.material.DropdownMenu
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
Expand All @@ -31,6 +33,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
Expand Down Expand Up @@ -120,6 +123,17 @@ fun DropDown(
onClickLabel = stringResource(R.string.stripe_change),
onClick = { expanded = true },
)
.let {
if (isAndroidTv()) {
it.selectable(
selected = false,
enabled = shouldEnable,
onClick = { expanded = true },
)
} else {
it
}
}
.testTag("DropDown:${if (controller.tinyMode) "tiny" else "normal"}")
) {
if (controller.tinyMode) {
Expand Down Expand Up @@ -287,3 +301,8 @@ internal fun DropdownMenuItem(
// Size defaults.
internal val DropdownMenuItemDefaultMaxWidth = 280.dp
internal val DropdownMenuItemDefaultMinHeight = 48.dp

@Composable
private fun isAndroidTv(): Boolean {
return LocalContext.current.packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)
}

0 comments on commit 69a3709

Please sign in to comment.