Skip to content

Conversation

Sagar0-0
Copy link
Contributor

@Sagar0-0 Sagar0-0 commented Jun 3, 2025

🎯 Goal

Closes #5804

🛠 Implementation details

Although they have fixed it in 1.8+, we can use this approach for the time being. I don't think there are any cons of using onImageSelected in a coroutine.

🧪 Testing

Manually test by attaching a Layout Inspector on a slow device. Select and deselect as fast as you can. It won't crash.

☑️Contributor Checklist

General

  • I have signed the Stream CLA (required)
  • Assigned a person / code owner group (required)
  • Thread with the PR link started in a respective Slack channel (#android-chat-core or #android-chat-ui) (required)
  • PR is linked to the GitHub issue it resolves

Code & documentation

  • Changelog is updated with client-facing changes
  • New code is covered by unit tests
  • Comparison screenshots added for visual changes
  • Affected documentation updated (KDocs, docusaurus, tutorial)

☑️Reviewer Checklist

  • UI Components sample runs & works
  • Compose sample runs & works
  • UI Changes correct (before & after images)
  • Bugs validated (bugfixes)
  • New feature tested and works
  • Release notes and docs clearly describe changes
  • All code we touched has new or updated KDocs

@Sagar0-0 Sagar0-0 requested a review from a team as a code owner June 3, 2025 11:58
val dataSet = attachments

val itemIndex = dataSet.indexOf(attachmentItem)
val itemIndex = dataSet.indexOfFirst { it.attachmentMetaData == attachmentItem.attachmentMetaData }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes isSelected might not be updated into the dataset so the index can be -1 if we use indexOf(). This kotlin function will never give us index -1.


newFiles.removeAt(itemIndex)
newFiles.add(itemIndex, newItem)
newFiles[itemIndex] = newItem
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize the O(n) + O(n) remove and add to O(1).

Copy link
Contributor

github-actions bot commented Oct 6, 2025

This pull request has been automatically marked as stale because it has been inactive for 14 days. It will be closed in 7 days if no further activity occurs.

@github-actions github-actions bot added the Stale label Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ImagePicker CRASH with coroutines.CompletionHandlerException
1 participant