eBay / NMessenger

A fast, lightweight messenger component built on AsyncDisplaykit and written in Swift
Other
2.42k stars 272 forks source link

[styling] NMessengerBarView does not support custom nib files #128

Open dodikk opened 7 years ago

dodikk commented 7 years ago

As a library user I'm ok with the existing set of controls on NMessengerBarView but my designer wants a different layout. Moreover, NMessengerBarView contains some useful camera and keyboard related logic.

So I'd like to load the NMessengerBarView from my own xib and my own [NSBundle mainBundle] (or from another one external to NMessenger). So far, no extension points are available.

dodikk commented 7 years ago

I'm going to add one more convenience constructor. See the code below. P.S. a pull request will follow.

    public required init(controller: NMessengerViewController,
                            nibName: String,
                             bundle: Bundle)
    {
        super.init(controller: controller)

        self.loadFrom(bundle: bundle, nibName: nibName)
    }

    fileprivate func loadFromBundle()
    {
        let nmessengerBundle = Bundle(for: NMessengerViewController.self)
        let nibName = "NMessengerBarView"

        self.loadFrom(bundle: nmessengerBundle, nibName: nibName)
    }

    fileprivate func loadFrom(bundle: Bundle,
                             nibName: String)
    {
        let nibObjects = bundle.loadNibNamed( nibName,
                                       owner: self,
                                     options: nil)
        /*let fileOwnerSelf*/ _ = nibObjects?[0] as! UIView

        self.addSubview(inputBarView)
        inputBarView.frame = self.bounds
        textInputView.delegate = self
        self.sendButton.isEnabled = false
        cameraVC.cameraDelegate = self

    }
dodikk commented 7 years ago

Another option is making open func loadFromBundle() and forcing library users to subclass the NMessengerBarView but that approach is less elegant, from my point of view.

dodikk commented 7 years ago

Fixed in https://github.com/eBay/NMessenger/pull/129