Rxswift: We should add a delegate proxy to UITextField

Created on 8 Nov 2015  Â·  9Comments  Â·  Source: ReactiveX/RxSwift

I noticed that NSTextField has a convenient delegate proxy. A delegate proxy on UITextField would be very convenient on iOS. It would be especially useful when a custom subclass of UITextField wants to observe user interaction and modify it's internal state / presentation without interfering with the external delegate.

I'm pretty new to RxSwift, but I'd be happy to work towards a PR for an addition to UITextField+Rx.swift.

All 9 comments

Hi @esetnik ,

Thnx for being interested in this project.

Those delegates are kind of necessary evil since they exist and are being used for notifications, but I think that we still need to think deeply on project level to what extend do we want to support them and in what way.

This is related with https://github.com/ReactiveX/RxSwift/issues/143 .

Most problems those delegates are causing for this library are because they are used both for notifications and for behavior customization. IMHO those are two completely different things bundled into one.

Final details of that delegate APIs are still not obvious to me, but it will roughly look the same as now.

Ideally I'm trying to create minimal API surface that would satisfy most needs and be extendible for people who have some special cases.

That being said, I am not currently satisfied with how currently RxTextFieldDelegate looks :), so I'm not sure would it be a good idea to replicate it as it is right now :) (although it's not far from final IMHO)

We will ofc need help with those delegates after we establish how idiomatic delegate proxy looks like and is being implemented :)

I'll first create a PR regarding that for a couple of use cases so people can comment it publicly, and after that we need to make sure all delegates behave the same, look the same, are documented the same, and tested the same :) So there will be plenty of work there if you are interested in contributing :)

Hope this makes sense :)

That definitely makes sense and I'm happy to help where I can. I think that
the ideal situation would be real delegate observation functions but I
understand how large this would make the api surface.

Right now the delegates seem to support only a subset of behaviors that are
needed to expose the primary RxCocoa binding. For example in the case of
UITextField all we can observe is the text. In reality there are a whole
host of potential cocoa observables for interactions on a text field.
On Sun, Nov 8, 2015 at 6:23 AM Krunoslav Zaher [email protected]
wrote:

Hi @esetnik https://github.com/esetnik ,

Thnx for being interested in this project.

Those delegates are kind of necessary evil since they exist and are being
used for notifications, but I think that we still need to think deeply on
project level to what extend do we want to support them and in what way.

This is related with #143
https://github.com/ReactiveX/RxSwift/issues/143 .

Most problems those delegates are causing for this library are because
they are used both for notifications and for behavior customization. IMHO
those are two completely different things bundled into one.

Final details of that delegate APIs are still not obvious to me, but it
will roughly look the same as now.

Ideally I'm trying to create minimal API surface that would satisfy most
needs and be extendible for people who have some special cases.

That being said, I am not currently satisfied with how currently
RxTextFieldDelegate looks :), so I'm not sure would it be a good idea to
replicate it as it is right now :) (although it's not far from final IMHO)

We will ofc need help with those delegates after we establish how
idiomatic delegate proxy looks like and is being implemented :)

I'll first create a PR regarding that for a couple of use cases so people
can comment it publicly, and after that we need to make sure all delegates
behave the same, look the same, are documented the same, and tested the
same :) So there will be plenty of work there if you are interested in
contributing :)

Hope this makes sense :)

—
Reply to this email directly or view it on GitHub
https://github.com/ReactiveX/RxSwift/issues/239#issuecomment-154807586.

Hi @esetnik ,

I think this has same answer like https://github.com/ReactiveX/RxSwift/issues/361 .

It's probably not realistic to wrap all possible cocoa APIs ¯_(ツ)_/¯ .

I've taken a look at UITextField delegate and didn't find much value in wrapping it ¯_(ツ)_/¯
Hope it make sense.

I would like to close this for now, but we can reopen this if necessary.

I'm surprised you don't feel it would be valuable to wrap. Two way binding of inputs is really popular in other frameworks. Consider ng-model in angular for instance. I feel like that level of power brought to UITextField combined with some neat swift language features could really make RxSwift shine for binding user entered data to models.

I do agree with you that we should wrap text of UITextField.

We already have two way binding for UITextField. We just don't need delegate to do that ;)

I think you've maybe misunderstood what I was trying to say :)

We use target action pattern to get text change notifications instead of delegate mechanism :)

Ok I misunderstood. That makes sense. I guess it's a pipe dream to be able to easily react to textFieldDidEndEditing.

@esetnik

There is a set of notifications that get fired

public let UITextFieldTextDidBeginEditingNotification: String
public let UITextFieldTextDidEndEditingNotification: String
public let UITextFieldTextDidChangeNotification: String

and we do wrap NSNotification center :)

I guess that works just as well. I can understand not wanting to support
and maintain a large API footprint.
On Thu, Dec 31, 2015 at 5:48 PM Krunoslav Zaher [email protected]
wrote:

@esetnik https://github.com/esetnik

There is a set of notifications that get fired

public let UITextFieldTextDidBeginEditingNotification: Stringpublic let UITextFieldTextDidEndEditingNotification: Stringpublic let UITextFieldTextDidChangeNotification: String

and we do wrap NSNotification center :)

—
Reply to this email directly or view it on GitHub
https://github.com/ReactiveX/RxSwift/issues/239#issuecomment-168257038.

A use case I am seeing right now is to restrict the textField to a maxLength.

Right now I have a two-way binding to the viewModel property:

        (nameTextField.rx.textInput <-> viewModel.name).disposed(by: disposeBag)

And now I want to set my own delegate to restrict length

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lyricsboy picture lyricsboy  Â·  3Comments

RafaelPlantard picture RafaelPlantard  Â·  3Comments

RobinFalko picture RobinFalko  Â·  3Comments

gekitz picture gekitz  Â·  3Comments

jaumard picture jaumard  Â·  3Comments