Skip to content

Commit cda94af

Browse files
committed
Fix MessageListView rotation crash and custom messagesStart not being applied
1 parent 99a0274 commit cda94af

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
@@ -662,9 +662,9 @@ public class MessageListView : ConstraintLayout {
662662
binding = StreamUiMessageListViewBinding.inflate(streamThemeInflater, this)
663663

664664
messageListViewStyle = MessageListViewStyle(context, attr)
665-
messageListViewStyle?.messagesStart?.let(::chatMessageStart)
666665

667666
initRecyclerView()
667+
messageListViewStyle?.messagesStart?.let(::chatMessageStart)
668668
initScrollHelper()
669669
initSwipeToReply()
670670
initLoadingView()
@@ -710,9 +710,7 @@ public class MessageListView : ConstraintLayout {
710710

711711
private fun initRecyclerView() {
712712
binding.chatMessagesRV.apply {
713-
layoutManager = LinearLayoutManager(context).apply {
714-
stackFromEnd = true
715-
}
713+
layoutManager = LinearLayoutManager(context)
716714
setHasFixedSize(false)
717715
setItemViewCacheSize(20)
718716
}
@@ -1332,15 +1330,16 @@ public class MessageListView : ConstraintLayout {
13321330

13331331
private fun changeLayoutForMessageStart(messagesStart: MessagesStart) {
13341332
val messagesRV = binding.chatMessagesRV
1333+
val layoutManager = messagesRV.layoutManager as? LinearLayoutManager ?: return
13351334

13361335
when (messagesStart) {
13371336
MessagesStart.BOTTOM -> {
1338-
messagesRV.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
1337+
layoutManager.stackFromEnd = true
13391338
messagesRV.overScrollMode = View.OVER_SCROLL_NEVER
13401339
}
13411340

13421341
MessagesStart.TOP -> {
1343-
messagesRV.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
1342+
layoutManager.stackFromEnd = false
13441343
messagesRV.overScrollMode = View.OVER_SCROLL_ALWAYS
13451344
}
13461345
}

0 commit comments

Comments
 (0)