jriosdev / iOSDropDown

Drop Down Menu for iOS With Search And Other Awesome Customisation
https://cocoapods.org/pods/iOSDropDown
MIT License
659 stars 150 forks source link

Adding search filter customization capability #108

Closed scy0334 closed 2 years ago

scy0334 commented 2 years ago

Hi! Thanks for this amazing library.

I want to add a search functionality for Korean, but current search feature isn't compatible with Korean.

So I was wondering what if we add search feature customization for iOS DropDown as below.

Current

var searchText = String() {
        didSet{
            if searchText == "" {
                self.dataArray = self.optionArray
            }else{
                self.dataArray = optionArray.filter {
                    return $0.range(of: searchText, options: .caseInsensitive) != nil
                }
            }
            reSizeTable()
            selectedIndex = nil
            self.table.reloadData()
        }
    }

My Suggestion

 var searchText = String() {
        didSet{
            if searchText == "" {
                self.dataArray = self.optionArray
            }else{
                self.dataArray = optionArray.filter {
                    return searchFilter(text: $0, searchText: searchText)
                }
            }
            reSizeTable()
            selectedIndex = nil
            self.table.reloadData()
        }
    }

    open func searchFilter(text: String, searchText: String) -> Bool {
        return text.range(of: searchText, options: .caseInsensitive) != nil
    }

In this way, I can subclass DropDown and customize the searchFilter as my own need.

Thanks!

jriosdev commented 2 years ago

Thanks for your suggestions, i will update it