Skip to content

Commit 66eb876

Browse files
authored
[a11y] Add click action to the message bottom sheet handle (#5228)
1 parent f0ba59d commit 66eb876

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ import androidx.compose.ui.draw.shadow
3939
import androidx.compose.ui.graphics.RectangleShape
4040
import androidx.compose.ui.platform.LocalView
4141
import androidx.compose.ui.res.stringResource
42+
import androidx.compose.ui.semantics.Role
4243
import androidx.compose.ui.semantics.heading
44+
import androidx.compose.ui.semantics.onClick
45+
import androidx.compose.ui.semantics.role
4346
import androidx.compose.ui.semantics.semantics
4447
import androidx.compose.ui.text.font.FontStyle
4548
import androidx.compose.ui.text.style.TextAlign
@@ -81,6 +84,7 @@ import io.element.android.features.roomcall.api.RoomCallState
8184
import io.element.android.libraries.androidutils.ui.hideKeyboard
8285
import io.element.android.libraries.designsystem.atomic.molecules.ComposerAlertMolecule
8386
import io.element.android.libraries.designsystem.components.ExpandableBottomSheetLayout
87+
import io.element.android.libraries.designsystem.components.ExpandableBottomSheetLayoutState
8488
import io.element.android.libraries.designsystem.components.avatar.Avatar
8589
import io.element.android.libraries.designsystem.components.avatar.AvatarData
8690
import io.element.android.libraries.designsystem.components.avatar.AvatarType
@@ -288,7 +292,25 @@ fun MessagesView(
288292
)
289293
},
290294
sheetDragHandle = if (state.composerState.showTextFormatting) {
291-
@Composable { BottomSheetDragHandle() }
295+
@Composable { toggleAction ->
296+
val expandA11yLabel = stringResource(CommonStrings.a11y_expand_message_text_field)
297+
val collapseA11yLabel = stringResource(CommonStrings.a11y_collapse_message_text_field)
298+
BottomSheetDragHandle(
299+
modifier = Modifier.semantics {
300+
role = Role.Button
301+
302+
// Accessibility action to toggle the bottom sheet state
303+
val label = when (expandableState.position) {
304+
ExpandableBottomSheetLayoutState.Position.COLLAPSED, ExpandableBottomSheetLayoutState.Position.DRAGGING -> expandA11yLabel
305+
ExpandableBottomSheetLayoutState.Position.EXPANDED -> collapseA11yLabel
306+
}
307+
onClick(label) {
308+
toggleAction()
309+
true
310+
}
311+
}
312+
)
313+
}
292314
} else {
293315
@Composable {}
294316
},

libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/ExpandableBottomSheetLayout.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import kotlin.math.roundToInt
6060

6161
@Composable
6262
fun ExpandableBottomSheetLayout(
63-
sheetDragHandle: @Composable BoxScope.() -> Unit,
63+
sheetDragHandle: @Composable BoxScope.(toggleAction: () -> Unit) -> Unit,
6464
bottomSheetContent: @Composable ColumnScope.() -> Unit,
6565
state: ExpandableBottomSheetLayoutState,
6666
maxBottomSheetContentHeight: Dp,
@@ -152,7 +152,19 @@ fun ExpandableBottomSheetLayout(
152152
}
153153
) {
154154
Box(Modifier.fillMaxWidth()) {
155-
sheetDragHandle()
155+
sheetDragHandle {
156+
coroutineScope.launch {
157+
val destination = if (state.position == ExpandableBottomSheetLayoutState.Position.EXPANDED) {
158+
state.internalPosition = ExpandableBottomSheetLayoutState.Position.COLLAPSED
159+
minBottomContentHeightPx.toFloat()
160+
} else {
161+
state.internalPosition = ExpandableBottomSheetLayoutState.Position.EXPANDED
162+
calculatedMaxBottomContentHeightPx.toFloat()
163+
}
164+
animatable.snapTo(currentBottomContentHeightPx.toFloat())
165+
animatable.animateTo(destination)
166+
}
167+
}
156168
}
157169
bottomSheetContent()
158170
}

libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/components/ExpandableBottomSheetLayoutState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ExpandableBottomSheetLayoutState {
3838
/**
3939
* The current position of the bottom sheet layout.
4040
*/
41-
val position = internalPosition
41+
val position get() = internalPosition
4242

4343
/**
4444
* The percentage of the bottom sheet layout that is currently being dragged.

0 commit comments

Comments
 (0)