TwoPanelBox.kt 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package eu.kanade.presentation.components
  2. import androidx.compose.foundation.layout.Box
  3. import androidx.compose.foundation.layout.BoxScope
  4. import androidx.compose.foundation.layout.BoxWithConstraints
  5. import androidx.compose.foundation.layout.WindowInsets
  6. import androidx.compose.foundation.layout.asPaddingValues
  7. import androidx.compose.foundation.layout.calculateEndPadding
  8. import androidx.compose.foundation.layout.calculateStartPadding
  9. import androidx.compose.foundation.layout.fillMaxSize
  10. import androidx.compose.foundation.layout.width
  11. import androidx.compose.runtime.Composable
  12. import androidx.compose.ui.Alignment
  13. import androidx.compose.ui.Modifier
  14. import androidx.compose.ui.platform.LocalLayoutDirection
  15. import androidx.compose.ui.unit.dp
  16. @Composable
  17. fun TwoPanelBox(
  18. modifier: Modifier = Modifier,
  19. contentWindowInsets: WindowInsets = WindowInsets(0),
  20. startContent: @Composable BoxScope.() -> Unit,
  21. endContent: @Composable BoxScope.() -> Unit,
  22. ) {
  23. val direction = LocalLayoutDirection.current
  24. val padding = contentWindowInsets.asPaddingValues()
  25. val startPadding = padding.calculateStartPadding(direction)
  26. val endPadding = padding.calculateEndPadding(direction)
  27. BoxWithConstraints(modifier = modifier.fillMaxSize()) {
  28. val width = maxWidth - startPadding - endPadding
  29. val firstWidth = (width / 2).coerceAtMost(450.dp)
  30. val secondWidth = width - firstWidth
  31. Box(
  32. modifier = Modifier
  33. .align(Alignment.TopStart)
  34. .width(firstWidth + startPadding),
  35. content = startContent,
  36. )
  37. Box(
  38. modifier = Modifier
  39. .align(Alignment.TopEnd)
  40. .width(secondWidth + endPadding),
  41. content = endContent,
  42. )
  43. }
  44. }