Skip to content

Commit 11cacff

Browse files
committed
Fix MessageListView rotation crash and custom messagesStart not being applied (#6438)
1 parent 152245e commit 11cacff

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

  • stream-chat-android-ui-components/src/main/kotlin/io/getstream/chat/android/ui/feature/messages/list

stream-chat-android-ui-components/src/main/kotlin/io/getstream/chat/android/ui/feature/messages/list/MessageListView.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,9 @@ public class MessageListView : ConstraintLayout {
656656
binding = StreamUiMessageListViewBinding.inflate(streamThemeInflater, this)
657657

658658
messageListViewStyle = MessageListViewStyle(context, attr)
659-
messageListViewStyle?.messagesStart?.let(::chatMessageStart)
660659

661660
initRecyclerView()
661+
messageListViewStyle?.messagesStart?.let(::chatMessageStart)
662662
initScrollHelper()
663663
initSwipeToReply()
664664
initLoadingView()
@@ -704,9 +704,7 @@ public class MessageListView : ConstraintLayout {
704704

705705
private fun initRecyclerView() {
706706
binding.chatMessagesRV.apply {
707-
layoutManager = LinearLayoutManager(context).apply {
708-
stackFromEnd = true
709-
}
707+
layoutManager = LinearLayoutManager(context)
710708
setHasFixedSize(false)
711709
setItemViewCacheSize(20)
712710
}
@@ -1310,15 +1308,16 @@ public class MessageListView : ConstraintLayout {
13101308

13111309
private fun changeLayoutForMessageStart(messagesStart: MessagesStart) {
13121310
val messagesRV = binding.chatMessagesRV
1311+
val layoutManager = messagesRV.layoutManager as? LinearLayoutManager ?: return
13131312

13141313
when (messagesStart) {
13151314
MessagesStart.BOTTOM -> {
1316-
messagesRV.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
1315+
layoutManager.stackFromEnd = true
13171316
messagesRV.overScrollMode = View.OVER_SCROLL_NEVER
13181317
}
13191318

13201319
MessagesStart.TOP -> {
1321-
messagesRV.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
1320+
layoutManager.stackFromEnd = false
13221321
messagesRV.overScrollMode = View.OVER_SCROLL_ALWAYS
13231322
}
13241323
}

0 commit comments

Comments
 (0)