Skip to content

Commit 30f08f5

Browse files
committed
Extra PaneTitle and PaneRow components for reusing
1 parent 0e0f904 commit 30f08f5

File tree

2 files changed

+86
-53
lines changed
  • stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui

2 files changed

+86
-53
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (c) 2014-2025 Stream.io Inc. All rights reserved.
3+
*
4+
* Licensed under the Stream License;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://github.com/GetStream/stream-chat-android/blob/main/LICENSE
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.getstream.chat.android.compose.sample.ui.component
18+
19+
import androidx.compose.foundation.background
20+
import androidx.compose.foundation.layout.Arrangement
21+
import androidx.compose.foundation.layout.PaddingValues
22+
import androidx.compose.foundation.layout.Row
23+
import androidx.compose.foundation.layout.RowScope
24+
import androidx.compose.foundation.layout.fillMaxWidth
25+
import androidx.compose.foundation.layout.padding
26+
import androidx.compose.foundation.shape.RoundedCornerShape
27+
import androidx.compose.material3.Text
28+
import androidx.compose.runtime.Composable
29+
import androidx.compose.ui.Modifier
30+
import androidx.compose.ui.graphics.RectangleShape
31+
import androidx.compose.ui.unit.dp
32+
import io.getstream.chat.android.compose.ui.theme.ChatTheme
33+
34+
@Composable
35+
internal fun PaneTitle(
36+
text: String,
37+
padding: PaddingValues = PaddingValues(
38+
top = 24.dp,
39+
start = 16.dp,
40+
bottom = 8.dp,
41+
end = 16.dp,
42+
),
43+
) {
44+
Text(
45+
modifier = Modifier.padding(padding),
46+
text = text,
47+
style = ChatTheme.typography.footnote,
48+
color = ChatTheme.colors.textLowEmphasis,
49+
)
50+
}
51+
52+
@Composable
53+
internal fun PaneRow(
54+
index: Int,
55+
lastIndex: Int,
56+
content: @Composable RowScope.() -> Unit,
57+
) {
58+
Row(
59+
modifier = Modifier
60+
.fillMaxWidth()
61+
.run {
62+
val shape = when (index) {
63+
0 -> if (lastIndex == 0) {
64+
// Single item in the list
65+
RoundedCornerShape(12.dp)
66+
} else {
67+
// Top item in the list
68+
RoundedCornerShape(topStart = 12.dp, topEnd = 12.dp)
69+
}
70+
// Bottom item in the list
71+
lastIndex -> RoundedCornerShape(bottomStart = 12.dp, bottomEnd = 12.dp)
72+
// Middle item in the list
73+
else -> RectangleShape
74+
}
75+
background(
76+
color = ChatTheme.colors.barsBackground,
77+
shape = shape,
78+
)
79+
}
80+
.padding(horizontal = 16.dp, vertical = 8.dp),
81+
horizontalArrangement = Arrangement.SpaceBetween,
82+
content = content,
83+
)
84+
}

stream-chat-android-compose-sample/src/main/java/io/getstream/chat/android/compose/sample/ui/profile/UserProfileScreen.kt

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import androidx.compose.foundation.layout.Box
2828
import androidx.compose.foundation.layout.Column
2929
import androidx.compose.foundation.layout.PaddingValues
3030
import androidx.compose.foundation.layout.Row
31-
import androidx.compose.foundation.layout.RowScope
3231
import androidx.compose.foundation.layout.Spacer
3332
import androidx.compose.foundation.layout.fillMaxSize
3433
import androidx.compose.foundation.layout.fillMaxWidth
@@ -81,6 +80,8 @@ import androidx.compose.ui.unit.dp
8180
import androidx.lifecycle.compose.collectAsStateWithLifecycle
8281
import androidx.lifecycle.viewmodel.compose.viewModel
8382
import io.getstream.chat.android.compose.sample.R
83+
import io.getstream.chat.android.compose.sample.ui.component.PaneRow
84+
import io.getstream.chat.android.compose.sample.ui.component.PaneTitle
8485
import io.getstream.chat.android.compose.ui.components.BackButton
8586
import io.getstream.chat.android.compose.ui.components.LoadingIndicator
8687
import io.getstream.chat.android.compose.ui.components.avatar.UserAvatar
@@ -752,58 +753,6 @@ private fun LazyListScope.unreadChannelsByTeam(
752753
}
753754
}
754755

755-
@Composable
756-
private fun PaneTitle(
757-
text: String,
758-
padding: PaddingValues = PaddingValues(
759-
top = 24.dp,
760-
start = 16.dp,
761-
bottom = 8.dp,
762-
end = 16.dp,
763-
),
764-
) {
765-
Text(
766-
modifier = Modifier.padding(padding),
767-
text = text,
768-
style = ChatTheme.typography.footnote,
769-
color = ChatTheme.colors.textLowEmphasis,
770-
)
771-
}
772-
773-
@Composable
774-
private fun PaneRow(
775-
index: Int,
776-
lastIndex: Int,
777-
content: @Composable RowScope.() -> Unit,
778-
) {
779-
Row(
780-
modifier = Modifier
781-
.fillMaxWidth()
782-
.run {
783-
val shape = when (index) {
784-
0 -> if (lastIndex == 0) {
785-
// Single item in the list
786-
RoundedCornerShape(12.dp)
787-
} else {
788-
// Top item in the list
789-
RoundedCornerShape(topStart = 12.dp, topEnd = 12.dp)
790-
}
791-
// Bottom item in the list
792-
lastIndex -> RoundedCornerShape(bottomStart = 12.dp, bottomEnd = 12.dp)
793-
// Middle item in the list
794-
else -> RectangleShape
795-
}
796-
background(
797-
color = ChatTheme.colors.barsBackground,
798-
shape = shape,
799-
)
800-
}
801-
.padding(horizontal = 16.dp, vertical = 8.dp),
802-
horizontalArrangement = Arrangement.SpaceBetween,
803-
content = content,
804-
)
805-
}
806-
807756
@Composable
808757
private fun CountText(
809758
count: Int,

0 commit comments

Comments
 (0)