Skip to content

Commit

Permalink
Position menu's underlying popup at 0,0
Browse files Browse the repository at this point in the history
  • Loading branch information
saket committed Oct 7, 2023
1 parent eef81d6 commit 56f6c89
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Shapes
import androidx.compose.material3.Text
import androidx.compose.material3.lightColorScheme
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -276,16 +275,16 @@ internal class CascadePopupAlignmentTest {
}
}

/** Screenshots the entire device instead of just the active Activity's content. */
private fun Dropshots.assertDeviceSnapshot(nameSuffix: String? = null) {
// This screenshots the entire device instead of just the active Activity's content.
val screenshot: Bitmap = takeScreenshot()

// The navigation bar's handle cross-fades its color smoothly and can
// appear slightly different each time. Crop it out to affect screenshots.
val navigationBarHeightInPx = composeTestRule.activity.resources.run {
getDimensionPixelSize(getIdentifier("navigation_bar_height", "dimen", "android"))
}
val screenshotWithoutNavBars: Bitmap = Bitmap.createBitmap(
val screenshotWithoutNavBar: Bitmap = Bitmap.createBitmap(
/* source = */ screenshot,
/* x = */ 0,
/* y = */ 0,
Expand All @@ -294,7 +293,7 @@ internal class CascadePopupAlignmentTest {
)

assertSnapshot(
bitmap = screenshotWithoutNavBars,
bitmap = screenshotWithoutNavBar,
name = testName.methodName + (if (nameSuffix != null) "_$nameSuffix" else "")
)
}
Expand Down
4 changes: 4 additions & 0 deletions cascade-compose/src/main/java/me/saket/cascade/Cascade.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Popup
import androidx.compose.ui.window.PopupProperties
Expand All @@ -67,6 +68,7 @@ import kotlinx.coroutines.flow.onEach
import me.saket.cascade.internal.AnimateEntryExit
import me.saket.cascade.internal.CoercePositiveValues
import me.saket.cascade.internal.DropdownMenuPositionProvider
import me.saket.cascade.internal.FixedPopupPositionProvider
import me.saket.cascade.internal.MinSdkReader
import me.saket.cascade.internal.PositionPopupContent
import me.saket.cascade.internal.RealMinSdkReader
Expand Down Expand Up @@ -158,7 +160,9 @@ fun CascadeDropdownMenu(
Popup(
onDismissRequest = onDismissRequest,
properties = properties.copy(usePlatformDefaultWidth = false),
popupPositionProvider = remember { FixedPopupPositionProvider(IntOffset.Zero) }
) {

PositionPopupContent(
modifier = Modifier
.fillMaxSize()
Expand Down

0 comments on commit 56f6c89

Please sign in to comment.