Ypimagepicker: preSelectItemOnMultipleSelection not work

Created on 25 Aug 2020  路  6Comments  路  Source: Yummypets/YPImagePicker

config.library.preSelectItemOnMultipleSelection = false

I also tried below code and combination.
config.library.preselectedItems = nil
(or config.library.preselectedItems = [])

But first Item is always selected.

Bug

Most helpful comment

@peymankh @s4cha I have the exact same problem, +1

All 6 comments

@peymankh @s4cha I have the exact same problem, +1

@s4cha Can certainly reproduce the issue now.

We always have an item preselected in refreshMediaRequest being called from initialize. This used to be cleared out in showMultipleSelection but now has moved to multipleSelectionButtonTapped to preserve the selection.

Not entirely sure what to change here not to break current functionality, would be great if you could have a look as well and let me know what needs to be changed.

I have put a fix in place, it does resolve the problem! Hopefully won't break the current pre-selection functionality.

@Ludotrico and @uxight Feel free to give my branch a go and let me know if that resolves your issue.

@peymankh thank you for the fix, it seems to work well.

However, I do not believe it is the best way to approach it. Any ideas @s4cha @NikKovIos?

I think the problem is refreshMediaRequest() function in initialize()
refreshMediaRequest calls addToSelection(indexPath: IndexPath(row: 0, section: 0))
because in that time multipleSelectionEnabled is not true yet.

so I add parameter like this:
refreshMediaRequest(needsDefaultSelection: Bool = true)

and fix in initialize() to:
...
refreshMediaRequest(needsDefaultSelection: YPConfig.library.defaultMultipleSelection ? false : true)
...

fix in refreshMediaRequest() to:
...
if !multipleSelectionEnabled && needsDefaultSelection {
addToSelection(indexPath: IndexPath(row: 0, section: 0))
}
...

This fixed my problems

@peymankh @s4cha

@uxight make sure to tag users (@peymankh) that you are intending to communicate with.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Sieniek picture Sieniek  路  5Comments

VitaliiDeveloper picture VitaliiDeveloper  路  5Comments

roarapps picture roarapps  路  4Comments

rajabpour picture rajabpour  路  3Comments

fukemy picture fukemy  路  6Comments