Skip to content

Commit e02053d

Browse files
Make sure HeaderFooterPage can contents be scrolled (#4704)
Co-authored-by: ElementBot <[email protected]>
1 parent df62dd1 commit e02053d

File tree

57 files changed

+153
-112
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+153
-112
lines changed

features/securebackup/impl/src/main/kotlin/io/element/android/features/securebackup/impl/enter/SecureBackupEnterRecoveryKeyView.kt

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,24 @@
77

88
package io.element.android.features.securebackup.impl.enter
99

10+
import androidx.compose.foundation.ExperimentalFoundationApi
1011
import androidx.compose.foundation.layout.ColumnScope
12+
import androidx.compose.foundation.layout.ExperimentalLayoutApi
13+
import androidx.compose.foundation.layout.WindowInsets
1114
import androidx.compose.foundation.layout.fillMaxWidth
15+
import androidx.compose.foundation.layout.isImeVisible
1216
import androidx.compose.foundation.layout.padding
17+
import androidx.compose.foundation.relocation.BringIntoViewRequester
18+
import androidx.compose.foundation.relocation.bringIntoViewRequester
1319
import androidx.compose.runtime.Composable
20+
import androidx.compose.runtime.LaunchedEffect
21+
import androidx.compose.runtime.getValue
22+
import androidx.compose.runtime.mutableStateOf
23+
import androidx.compose.runtime.remember
24+
import androidx.compose.runtime.rememberCoroutineScope
25+
import androidx.compose.runtime.setValue
1426
import androidx.compose.ui.Modifier
27+
import androidx.compose.ui.focus.onFocusChanged
1528
import androidx.compose.ui.res.stringResource
1629
import androidx.compose.ui.tooling.preview.PreviewParameter
1730
import androidx.compose.ui.unit.dp
@@ -25,6 +38,9 @@ import io.element.android.libraries.designsystem.preview.ElementPreview
2538
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
2639
import io.element.android.libraries.designsystem.theme.components.Button
2740
import io.element.android.libraries.ui.strings.CommonStrings
41+
import kotlinx.coroutines.delay
42+
import kotlinx.coroutines.launch
43+
import kotlin.time.Duration.Companion.milliseconds
2844

2945
@Composable
3046
fun SecureBackupEnterRecoveryKeyView(
@@ -55,12 +71,30 @@ fun SecureBackupEnterRecoveryKeyView(
5571
}
5672
}
5773

74+
@OptIn(ExperimentalFoundationApi::class, ExperimentalLayoutApi::class)
5875
@Composable
5976
private fun Content(
6077
state: SecureBackupEnterRecoveryKeyState,
6178
) {
79+
val bringIntoViewRequester = remember { BringIntoViewRequester() }
80+
var isFocused by remember { mutableStateOf(false) }
81+
val isImeVisible = WindowInsets.isImeVisible
82+
val coroutineScope = rememberCoroutineScope()
83+
LaunchedEffect(isImeVisible, isFocused) {
84+
// When the keyboard is shown, we want to scroll the text field into view
85+
if (isImeVisible && isFocused) {
86+
coroutineScope.launch {
87+
// Delay to ensure the keyboard is fully shown
88+
delay(100.milliseconds)
89+
bringIntoViewRequester.bringIntoView()
90+
}
91+
}
92+
}
6293
RecoveryKeyView(
63-
modifier = Modifier.padding(top = 52.dp, bottom = 32.dp),
94+
modifier = Modifier
95+
.onFocusChanged { isFocused = it.isFocused }
96+
.bringIntoViewRequester(bringIntoViewRequester)
97+
.padding(top = 52.dp, bottom = 32.dp),
6498
state = state.recoveryKeyViewState,
6599
onClick = null,
66100
onChange = {

libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/atomic/pages/FlowStepPage.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ import androidx.compose.foundation.layout.ColumnScope
1313
import androidx.compose.foundation.layout.fillMaxSize
1414
import androidx.compose.foundation.layout.padding
1515
import androidx.compose.material3.ExperimentalMaterial3Api
16+
import androidx.compose.material3.TopAppBarDefaults
1617
import androidx.compose.runtime.Composable
1718
import androidx.compose.ui.Alignment
1819
import androidx.compose.ui.Modifier
20+
import androidx.compose.ui.graphics.Color
1921
import androidx.compose.ui.unit.dp
2022
import io.element.android.compound.theme.ElementTheme
2123
import io.element.android.compound.tokens.generated.CompoundIcons
@@ -63,6 +65,7 @@ fun FlowStepPage(
6365
}
6466
},
6567
title = {},
68+
colors = TopAppBarDefaults.topAppBarColors(containerColor = Color.Transparent)
6669
)
6770
},
6871
header = {

libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/atomic/pages/HeaderFooterPage.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ package io.element.android.libraries.designsystem.atomic.pages
99

1010
import androidx.compose.foundation.layout.Box
1111
import androidx.compose.foundation.layout.Column
12+
import androidx.compose.foundation.layout.IntrinsicSize
1213
import androidx.compose.foundation.layout.PaddingValues
1314
import androidx.compose.foundation.layout.calculateEndPadding
1415
import androidx.compose.foundation.layout.calculateStartPadding
1516
import androidx.compose.foundation.layout.consumeWindowInsets
1617
import androidx.compose.foundation.layout.fillMaxSize
1718
import androidx.compose.foundation.layout.fillMaxWidth
19+
import androidx.compose.foundation.layout.height
1820
import androidx.compose.foundation.layout.imePadding
1921
import androidx.compose.foundation.layout.padding
2022
import androidx.compose.foundation.rememberScrollState
@@ -94,25 +96,27 @@ fun HeaderFooterPage(
9496
.run {
9597
if (isScrollable) {
9698
verticalScroll(rememberScrollState())
99+
// Make sure the scrollable content takes the full available height
100+
.height(IntrinsicSize.Max)
97101
} else {
98102
Modifier
99103
}
100104
}
101105
// Apply insets here so if the content is scrollable it can get below the top app bar if needed
102106
.padding(contentInsetsPadding)
103-
.weight(1f),
107+
.weight(1f, fill = true),
104108
) {
105109
// Header
106110
header()
107-
Box(modifier = Modifier.weight(1f)) {
111+
Box {
108112
content()
109113
}
110114
}
111115

112116
// Footer
113117
Box(
114118
modifier = Modifier
115-
.padding(horizontal = 16.dp)
119+
.padding(start = 16.dp, end = 16.dp, top = 16.dp)
116120
.fillMaxWidth()
117121
.padding(footerInsetsPadding)
118122
) {
Lines changed: 2 additions & 2 deletions
Lines changed: 2 additions & 2 deletions
Lines changed: 2 additions & 2 deletions
Lines changed: 2 additions & 2 deletions
Lines changed: 2 additions & 2 deletions
Lines changed: 2 additions & 2 deletions
Lines changed: 2 additions & 2 deletions

0 commit comments

Comments
 (0)