-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat [ANDROAPP-6793]: Add two pane layout (#353)
Signed-off-by: Pablo Pajuelo Cabezas <[email protected]>
- Loading branch information
Showing
5 changed files
with
126 additions
and
0 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
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
53 changes: 53 additions & 0 deletions
53
common/src/commonMain/kotlin/org/hisp/dhis/common/screens/layouts/TwoPaneLayoutScreen.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,53 @@ | ||
package org.hisp.dhis.common.screens.layouts | ||
|
||
import androidx.compose.animation.core.InfiniteRepeatableSpec | ||
import androidx.compose.animation.core.RepeatMode | ||
import androidx.compose.animation.core.animateFloat | ||
import androidx.compose.animation.core.rememberInfiniteTransition | ||
import androidx.compose.animation.core.tween | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import org.hisp.dhis.mobile.ui.designsystem.component.layout.TwoPaneConfig | ||
import org.hisp.dhis.mobile.ui.designsystem.component.layout.TwoPaneLayout | ||
|
||
@Composable | ||
fun TwoPaneLayoutScreen() { | ||
val infiniteTransition = rememberInfiniteTransition() | ||
|
||
val weight by infiniteTransition.animateFloat( | ||
initialValue = 0.1f, | ||
targetValue = 0.9f, | ||
animationSpec = InfiniteRepeatableSpec( | ||
animation = tween(2000), | ||
repeatMode = RepeatMode.Reverse, | ||
), | ||
) | ||
|
||
TwoPaneLayout( | ||
modifier = Modifier.fillMaxSize(), | ||
paneConfig = TwoPaneConfig.Weight(weight), | ||
primaryPane = { | ||
Box( | ||
modifier = Modifier.fillMaxSize().background(Color.Red), | ||
contentAlignment = Alignment.Center, | ||
) { | ||
Text(text = "Primary pane") | ||
} | ||
}, | ||
secondaryPane = { | ||
Box( | ||
modifier = Modifier.fillMaxSize().background(Color.Green), | ||
contentAlignment = Alignment.Center, | ||
) { | ||
Text(text = "Secondary pane") | ||
} | ||
}, | ||
) | ||
} |
9 changes: 9 additions & 0 deletions
9
.../commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/layout/TwoPaneConfig.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,9 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component.layout | ||
|
||
import androidx.compose.ui.unit.Dp | ||
|
||
sealed class TwoPaneConfig { | ||
data class Weight(val primaryPaneWeight: Float) : TwoPaneConfig() | ||
data class PrimaryPaneFixedSize(val size: Dp) : TwoPaneConfig() | ||
data class SecondaryPaneFixedSize(val size: Dp) : TwoPaneConfig() | ||
} |
61 changes: 61 additions & 0 deletions
61
.../commonMain/kotlin/org/hisp/dhis/mobile/ui/designsystem/component/layout/TwoPaneLayout.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,61 @@ | ||
package org.hisp.dhis.mobile.ui.designsystem.component.layout | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.RowScope | ||
import androidx.compose.foundation.layout.fillMaxHeight | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
|
||
/** | ||
* Two pane screen | ||
* Divides the screen in two parts for extended device screens | ||
* @param modifier: Modifier for styling | ||
* @param paneConfig: Pane configuration | ||
* @param primaryPane: Primary pane content | ||
* @param secondaryPane: Secondary pane content | ||
* */ | ||
@Composable | ||
fun TwoPaneLayout( | ||
modifier: Modifier = Modifier, | ||
paneConfig: TwoPaneConfig, | ||
primaryPane: @Composable () -> Unit, | ||
secondaryPane: @Composable () -> Unit, | ||
) { | ||
Row(modifier = modifier) { | ||
val (primaryPaneModifier, secondaryPaneModifier) = getPaneModifier(paneConfig) | ||
|
||
Box( | ||
modifier = primaryPaneModifier, | ||
) { | ||
secondaryPane() | ||
} | ||
Box( | ||
modifier = secondaryPaneModifier, | ||
) { | ||
primaryPane() | ||
} | ||
} | ||
} | ||
|
||
private fun RowScope.getPaneModifier(paneConfig: TwoPaneConfig): Pair<Modifier, Modifier> = | ||
when (paneConfig) { | ||
is TwoPaneConfig.PrimaryPaneFixedSize -> | ||
Pair( | ||
Modifier.fillMaxHeight().width(paneConfig.size), | ||
Modifier.fillMaxHeight().weight(1f), | ||
) | ||
|
||
is TwoPaneConfig.SecondaryPaneFixedSize -> | ||
Pair( | ||
Modifier.fillMaxHeight().weight(1f), | ||
Modifier.fillMaxHeight().width(paneConfig.size), | ||
) | ||
|
||
is TwoPaneConfig.Weight -> | ||
Pair( | ||
Modifier.fillMaxHeight().weight(paneConfig.primaryPaneWeight), | ||
Modifier.fillMaxHeight().weight(1f - paneConfig.primaryPaneWeight), | ||
) | ||
} |