Skip to content

Commit

Permalink
Enable Drawer when expand API invoke to display drawer in Expanded St…
Browse files Browse the repository at this point in the history
…ate. Added button in V2 Drawer Activity to expand directly
  • Loading branch information
mishramayank1 committed May 19, 2023
1 parent f558a18 commit 9f9cebe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.semantics.contentDescription
Expand Down Expand Up @@ -78,7 +79,6 @@ private fun CreateActivityUI() {
var selectedBehaviorType by remember { mutableStateOf(BehaviorType.BOTTOM_SLIDE_OVER) }
Column(horizontalAlignment = Alignment.CenterHorizontally) {
CreateDrawerWithButtonOnPrimarySurfaceToInvokeIt(
"Open Drawer",
selectedBehaviorType,
if (listContent)
getDrawerContent(selectedContent)
Expand Down Expand Up @@ -298,7 +298,6 @@ private fun CreateActivityUI() {

@Composable
private fun CreateDrawerWithButtonOnPrimarySurfaceToInvokeIt(
primaryScreenButtonText: String,
behaviorType: BehaviorType,
drawerContent: @Composable ((() -> Unit) -> Unit),
expandable: Boolean = true,
Expand All @@ -309,13 +308,24 @@ private fun CreateDrawerWithButtonOnPrimarySurfaceToInvokeIt(
val open: () -> Unit = {
scope.launch { drawerState.open() }
}
val expand: () -> Unit = {
scope.launch { drawerState.expand() }
}
val close: () -> Unit = {
scope.launch { drawerState.close() }
}
PrimarySurfaceContent(
open,
text = primaryScreenButtonText
)
Row {
PrimarySurfaceContent(
open,
text = stringResource(id = R.string.drawer_open)
)
Spacer(modifier = Modifier.width(10.dp))
PrimarySurfaceContent(
expand,
text = stringResource(id = R.string.drawer_expand)
)
}

Drawer(
drawerState = drawerState,
drawerContent = { drawerContent(close) },
Expand Down
9 changes: 8 additions & 1 deletion FluentUI.Demo/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@
<string name="card_description">Secondary copy for this banner can wrap to two lines if needed.</string>
<!-- UI Label Button -->
<string name="card_button">Button</string>

<!-- V2 Dialog -->
<!-- UI Label to display the dialog -->
<string name="show_dialog">Show Dialog</string>
Expand All @@ -835,4 +835,11 @@
<!-- A sample description -->
<string name="dialog_description">A dialog is a small window that prompts the user to make a decision or enter additional information.</string>

<!-- V2 Drawer -->
<!-- UI Label for Button which open Drawer-->
<string name="drawer_open">Open Drawer</string>
<!-- UI Label for Button which expand Drawer-->
<string name="drawer_expand">Expand Drawer</string>


</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ class DrawerState(
* @throws [CancellationException] if the animation is interrupted
*/
suspend fun expand() {
enable = true
animationInProgress = true
delay(50)
val targetValue = when {
hasExpandedState -> DrawerValue.Expanded
else -> DrawerValue.Open
Expand Down

0 comments on commit 9f9cebe

Please sign in to comment.