-
Notifications
You must be signed in to change notification settings - Fork 498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The best way to implement forms with MvRx & Epoxy #115
Comments
This pattern looks right to me, what's the problem with recycling exactly? what is it not recycling? |
I had a problem with attaching I solved it by having
and clearing all Watchers before setting new one in my Model
It works. However I'll be greatful for your feedback @elihart . It's a pleasure to create forms with |
you can put some thing like this in your model
instead of your WatcherAwareEditText |
@qbait your solution seems fine. alternatively the textwatcher can be stored as a property in the @ModelView class - whatever you prefer if you prefer to use a more kotlin like approach and avoid needing to subclass edit text you can use extension functions instead here's a small sample I just wrote up to illustrate (this is just scratch untested code, but should give you the right idea)
@shakil807g calling |
Yes sorry my bad , i am using my model this way is there anything that could go wrong with this approach ?
|
@elihart It was working great when I had 1 big scrolling form. Now I separated sections into separate fragments, but I left single shared |
why do you have problems with separate fragments, what is the problem exactly? You've gotta give more details. sharing a viewmodel should work theoretically, but it may not make the cleanest abstraction if the fragments are unrelated. clearing the watchers seems like it would always be a good idea |
Ok, @elihart, the problem was in clearing Watchers, I was doing it like that:
I changed it to watch only when EditText has focus
I'm curious where you clear you watchers. |
@qbait Can you please share the setTextAndCursor and onChange extension or a full example? Thanks |
@qbait thanks for the update. It seems odd to me that you are needing to clear the watcher when focus changes - it seems like something else is going on here that isn't right. You should only need to clear the watcher when the view is unbound/recycled, which happens automatically with a callback prop |
I'm planning to prepare a sample code and post on Medium when I have more time. Here is the extension
Instead of |
@elihart my clear function was invoked ~2s after new fragment was created and meantime it was making a mess.
I can prepare a sample project tomorrow if you would have time to take a look. |
@elihart and @qbait I use similar solution with the approach of yours, but I ran into an issue, that for my custom EditField view, that has inputType, imeOptions, @ModelProp annotated properties, and using @AfterPropsSet to bind these properties all together to the EditText. The issue was, because setState on the text change event, and the soft keyboard is displaying, the imeAction, and inputType also changed when the bind is called resulting the changing of the soft keyboard |
hi guys - does anyone have an example now ? especially with a text field and a photo field (where we click a photo through phone camera). We are not able to figure this out properly |
Yea I'm running into the same issue with multiple fragments. It seems the edittexts are being removed and the clear isn't called immediately so if I cycle between fragments quickly I can have text in an edittext in one fragment changing text in an edittext in a a different fragment |
Could you tell me how I could improve my pattern for creating forms with MvRx?
What's the best way to fix
EditText
recycling ? Keeping allEditText
s in single view like in your ToDo sample solves the problem, but it's less scalable solution, isn't it?My
Model
is below.setTextAndCursor
is Extension fuction inspired by @elihart code airbnb/epoxy#426)onChange
is Extension function wrappingTextWatcher
Code in
Fragment
Code in
ViewModel
EditText
The text was updated successfully, but these errors were encountered: