Code Monkey home page Code Monkey logo

Comments (2)

DianQK avatar DianQK commented on May 31, 2024

@VincentSit
create your provider.
for example,

open class MyUniqueCustomTableViewSectionProvider: NSObject, FSPagerViewDataSource, AnimatablePartionSectionTableViewProvider, StringIdentifiableType {
    
    public var identity: String {
        return self._flix_identity
    }

    public static func ==(lhs: UniqueCustomTableViewSectionProvider, rhs: UniqueCustomTableViewSectionProvider) -> Bool {
        return true
    }
    
    public typealias Cell = UITableViewHeaderFooterView
    public typealias Value = UniqueCustomTableViewSectionProvider

    open let customIdentity: String
    open let tableElementKindSection: UITableElementKindSection

    open var isHidden: Bool {
        get {
            return _isHidden.value
        }
        set {
            _isHidden.value = newValue
        }
    }
    private let _isHidden = Variable(false)
    
    open var sectionHeight: ((UITableView) -> CGFloat)?
    
    open let contentView: UIView = NeverHitSelfView()
    open var backgroundView: UIView? {
        didSet {
            _view?.backgroundView = backgroundView
        }
    }

    private weak var _view: UITableViewHeaderFooterView?
    
    public init(customIdentity: String, tableElementKindSection: UITableElementKindSection) {
        self.customIdentity = customIdentity
        self.tableElementKindSection = tableElementKindSection
    }
    
    public init(tableElementKindSection: UITableElementKindSection) {
        self.customIdentity = ""
        self.tableElementKindSection = tableElementKindSection
    }

    open func tableView(_ tableView: UITableView, heightInSection section: Int, value: UniqueCustomTableViewSectionProvider) -> CGFloat? {
        return self.sectionHeight?(tableView)
    }

    open func configureSection(_ tableView: UITableView, view: UITableViewHeaderFooterView, viewInSection section: Int, value: UniqueCustomTableViewSectionProvider) {
        if !view.hasConfigured {
            _view = view
            view.hasConfigured = true
            view.backgroundView = self.backgroundView
            view.contentView.addSubview(contentView)
            contentView.translatesAutoresizingMaskIntoConstraints = false
            contentView.topAnchor.constraint(equalTo: view.contentView.topAnchor).isActive = true
            contentView.leadingAnchor.constraint(equalTo: view.contentView.leadingAnchor).isActive = true
            contentView.trailingAnchor.constraint(equalTo: view.contentView.trailingAnchor).isActive = true
            contentView.bottomAnchor.constraint(equalTo: view.contentView.bottomAnchor).isActive = true
        }
    }

    open func genteralSection() -> Observable<UniqueCustomTableViewSectionProvider?> {
        return self._isHidden.asObservable()
            .map { [weak self] isHidden in
                return isHidden ? nil : self
        }
    }
    
}

extension Reactive where Base: UniqueCustomTableViewSectionProvider {

    public var isHidden: Binder<Bool> {
        return Binder(self.base) { provider, hidden in
            provider.isHidden = hidden
        }
    }

}

from flix.

VincentSit avatar VincentSit commented on May 31, 2024

@DianQK

Thanks for your help, my problem has been solved.

BTW, maybe you could consider changing the access level of NeverHitSelfView to public.

from flix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.