GithubHelp home page GithubHelp logo

Comments (13)

eliburke avatar eliburke commented on May 10, 2024 3

You have to create it your self. But it's easy. This should be enough to get you started. ( I stripped a bunch of stuff out of some live code so I won't guarantee it compiles. 😄 )

class GerbilPageItem: BLTNPageItem {

    public private(set) var textField: UITextField!

    override init(title: String) {
        super.init(title: "Title")
         self.descriptionText = "Description"
         self.actionButtonTitle = "Ok"
         self.isDismissable = true
         self.alternativeButtonTitle = "Cancel"

        self.presentationHandler = { (_ item: BLTNItem) in
            self.textField?.becomeFirstResponder() // open the keyboard  
        }
    
    override func makeViewsUnderDescription(with interfaceBuilder: BLTNInterfaceBuilder) -> [UIView]? {
        var contentViews = [UIView]()
        
            let textField = interfaceBuilder.makeTextField(delegate: self)
            textField.returnKeyType = .done
            textField.spellCheckingType = .no
            textField.autocorrectionType = .no
            textField.autocapitalizationType = .none
            textField.placeholder = "username"
            textField.addTarget(self, action: #selector(textFieldDidChange), for: .editingChanged)
            contentViews.append(textField)
            self.textField = textField
        
        return contentViews
    }
}

extension GerbilPageItem: UITextFieldDelegate {
    
    @objc func textFieldDidChange(textField: UITextField) {
        textField.text = textField.text?.lowercased()
       // actionButton?.isEnabled = textField.text?.trim().isValidUsername() ?? false
    }
    
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        if let text = textField.text, text.isEmpty == false {
            textField.resignFirstResponder()
            return true
        } else {
            textField.backgroundColor = .red
            return false
        }
    }
}

from bulletinboard.

eliburke avatar eliburke commented on May 10, 2024 1

Oops. I had a bug in my test code, and i got confused between ActionBulletinItem and PageBulletinItem.
Maybe headerViews should be moved into ActionBulletinItem to be consistent?
Other than that, I think this is very good.

from bulletinboard.

alexisakers avatar alexisakers commented on May 10, 2024

That's definitely an important missing feature. Thanks for requesting it!

I've been testing several ways to implement it, and I've pushed what I think is the easiest solution on the master branch (f8f7657).

I've created a base class ActionBulletinItem that handles creating the buttons and recognizing the taps. It has an open method named makeContentViews(interfaceBuilder:) that you can override to return the elements displayed above the buttons. PageBulletinItem builds on top of this class now.

@eliburke You can check out the git diff of the commit to see how it makes creating custom items with buttons easier and more flexible. Tell me if you think more customization is needed.

from bulletinboard.

eliburke avatar eliburke commented on May 10, 2024

@alexaubry this is interesting. It's pretty different than what I was thinking. Customizing custom Bulletins that look like PageBulletinItem will still take a fair bit of boilerplate, but it is manageable. Customizing the buttons as in PetSelectorBulletinPage is weighty.

For kicks, I tried updating TextFieldBulletinPage to use ActionBulletinItem. It is unfortunately difficult to get the text input out cleanly with the existing API. See #35

I know it would be a departure from the current API, but what do you think about changing the actionHandler/altActionHandler to call a single closure with an enum and perhaps associated data?

from bulletinboard.

eliburke avatar eliburke commented on May 10, 2024

FWIW, I don't mean to sound negative about this update. It's a great improvement for modifying the stock appearance and using the standard button behavior, and also makes implementing a completely custom design much cleaner.

from bulletinboard.

alexisakers avatar alexisakers commented on May 10, 2024

@eliburke Thank you very much for you feedback! I've implemented your initial suggestion in PR #41, and it makes customization way easier and reduces the amount of boilerplate code 💯

Can I ask you to review the PR and tell me if you think some improvements are still needed?

from bulletinboard.

alexisakers avatar alexisakers commented on May 10, 2024

I will open a separate issue about callback changes for actionHandler/altActionHandler.

from bulletinboard.

eliburke avatar eliburke commented on May 10, 2024

Hi @alexaubry I'm happy to take a look. Do you want me to do a full PR review (which I think you have to initiate?) or just let you know what I think?

from bulletinboard.

eliburke avatar eliburke commented on May 10, 2024

Couple of things I've noticed:
footerViews() is not being called by ActionBulletinItem.makeContentViews()

There is a bug in BulletinInterfaceBuilder.makeTextField(). It does not honor the returnKey parameter but rather hard codes it to .default.

from bulletinboard.

alexisakers avatar alexisakers commented on May 10, 2024

Thanks for the feedback! I fixed the returnKey parameter bug.

I'm actually calling footerViews() after makeContentViews(), so I think it's good.

https://github.com/alexaubry/BulletinBoard/blob/eba896d2d33126f307b96d7f6dcaf10c8710a068/Sources/Models/ActionBulletinItem.swift#L247

Please let me know if you think other customisation options are missing for the page item, or if you think there are enough now 😄

from bulletinboard.

alexisakers avatar alexisakers commented on May 10, 2024

I thought headerViews made more sense in PageBulletinItem, because it has a title.

from bulletinboard.

alexisakers avatar alexisakers commented on May 10, 2024

These changes are now in the master branch and will ship with the next release. Thank you very much for the feature request and your help to implement it 💯

from bulletinboard.

nightfall708 avatar nightfall708 commented on May 10, 2024

Hi, in relation to this- is there a textField ready page out of the box? or should I build I myself?

from bulletinboard.

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.