gringoireDM / LNZTreeView

A swift TreeView
MIT License
235 stars 47 forks source link

enhancement - filter by string #4

Closed johndpope closed 6 years ago

johndpope commented 6 years ago
screen shot 2018-02-19 at 11 23 00 am

need to trawl through the root node for matches. https://github.com/bfeher/SceneKit-COLLADA-Demo/pull/2

gringoireDM commented 6 years ago

I'm sorry, but I don't understand your request.

johndpope commented 6 years ago

So it would be neat if there was an integrated textfield that would apply a filter to the tree and just show results.

gringoireDM commented 6 years ago

This is a logic that should be in your datasource. This library simply provides a TreeView. Which are the data displayed by this view are responsibility of the datasource, so if there is any filtering logic you would like to adopt that must be on the implementation side, not on the library.

johndpope commented 6 years ago

@gringoireDM - it is possible using protocol

found this today - https://github.com/onekiloparsec/KPCSearchableOutlineView


//
//  SearchableNode.swift
//  KPCSearchableOutlineView
//
//  Created by Cédric Foellmi on 11/12/2016.
//  Copyright © 2016 onekiloparsec. All rights reserved.
//

import Foundation

extension IndexPath {
    func indexPathByAddingIndexInFront(_ index: Int) -> IndexPath {
        let indexPath = IndexPath(index: index)
        return indexPath.appending(self)
    }
}

public protocol SearchableNode: NSObjectProtocol {
    var uuid: UUID { get }
    var childNodes: [SearchableNode] { get set }
    var originalChildNodes: [SearchableNode] { get set }
    var parentNode: SearchableNode? { get }
    func searchableContent() -> String
}

public extension Collection where Iterator.Element == SearchableNode {
    func indexOf(_ element: Iterator.Element) -> Index? {
        return index(where: { $0.uuid == element.uuid })
    }
}

public extension SearchableNode {

    func indexPath() -> IndexPath {
        var indexPath = IndexPath()
        var activeNode: SearchableNode = self

        while activeNode.parentNode != nil {
            if let index = activeNode.parentNode!.childNodes.indexOf(self) {
                indexPath = indexPath.indexPathByAddingIndexInFront(index)
                activeNode = activeNode.parentNode!
            }
            else {
                break
            }
        }

        return indexPath
    }
}
gringoireDM commented 6 years ago

I never said it's not possible. I said that it is not what I'm proposing for this library. what this library does and wants to do is to give a generic Tree View for iOS. Not filtering through its data source. The feature is implementable on the client side, where the library is actually used.

Feel free to extend the features of this class in you project, but I will not add this feature in the main project. This library does not manipulate the dataSource.