Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix images being out of order in ShareDialog #2468

Conversation

sebastiangrail
Copy link
Contributor

  • sign contributor license agreement (signed by company)
  • I've ensured that all existing tests pass and added tests (when/where necessary)
  • I've updated the documentation (when/where necessary) and Changelog (when/where necessary)
  • I've added the proper label to this pull request (e.g. bug for bug fixes)

Pull Request Details

When sharing multiple images their order is not stable:

let content = SharePhotoContent()
content.photos = imagePaths
let dialog = ShareDialog(viewController: presenter, content: content, delegate: delegate)
try dialog.validate()
dialog.show()

This is because they are uniqued by converting into a Set and back to an Array:

let uniqueImages = Set(photoContent.photos.compactMap(\.image))
return Array(uniqueImages)

This PR ensures that the original order is preserved by using an Array.filter with an auxiliary Set to keep the performance O(n).

Test Plan

Uniquing is done in a private property and is currently not covered by tests.

@sebastiangrail sebastiangrail requested a review from joesus as a code owner August 27, 2024 01:50
@facebook-github-bot
Copy link
Contributor

Hi @sebastiangrail!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@yuriy-tolstoguzov yuriy-tolstoguzov self-requested a review August 27, 2024 17:43
@yuriy-tolstoguzov yuriy-tolstoguzov self-assigned this Aug 27, 2024
@facebook-github-bot
Copy link
Contributor

@yuriy-tolstoguzov has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@yuriy-tolstoguzov merged this pull request in 5141366.

@yuriy-tolstoguzov
Copy link
Contributor

Thank you for the fix @sebastiangrail !

facebook-github-bot pushed a commit that referenced this pull request Aug 27, 2024
Summary:
- [x] sign [contributor license agreement](https://code.facebook.com/cla) (signed by company)
- [x] I've ensured that all existing tests pass and added tests (when/where necessary)
- [x] I've updated the documentation (when/where necessary) and [Changelog](CHANGELOG.md) (when/where necessary)
- [ ] I've added the proper label to this pull request (e.g. `bug` for bug fixes)

## Pull Request Details

When sharing multiple images their order is not stable:

```Swift
let content = SharePhotoContent()
content.photos = imagePaths
let dialog = ShareDialog(viewController: presenter, content: content, delegate: delegate)
try dialog.validate()
dialog.show()
```

This is because they are uniqued by converting into a `Set` and back to an `Array`:

```
let uniqueImages = Set(photoContent.photos.compactMap(\.image))
return Array(uniqueImages)
```

This PR ensures that the original order is preserved by using an `Array.filter` with an auxiliary `Set` to keep the performance `O(n)`.

Pull Request resolved: #2468

Test Plan: Uniquing is done in a private property and is currently not covered by tests.

Reviewed By: caodoan

Differential Revision: D61862742

Pulled By: yuriy-tolstoguzov

fbshipit-source-id: 36878263588dade8c56e7bc79ffdabb35af9e7ab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants