YPImagePicker icon indicating copy to clipboard operation
YPImagePicker copied to clipboard

preSelectItemOnMultipleSelection not work

Open uxight opened this issue 4 years ago • 6 comments

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.

uxight avatar Aug 25 '20 21:08 uxight

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

Ludotrico avatar Aug 26 '20 02:08 Ludotrico

@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.

TheCoordinator avatar Aug 29 '20 15:08 TheCoordinator

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.

TheCoordinator avatar Aug 29 '20 15:08 TheCoordinator

@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?

Ludotrico avatar Aug 29 '20 19:08 Ludotrico

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 avatar Aug 30 '20 07:08 uxight

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

Ludotrico avatar Aug 30 '20 08:08 Ludotrico