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
Broken TextInputLayout with support library 24.2.0 #81
Comments
That's where a beautiful abstraction over Android Views leaks :( Any update on this one? |
@jakubkulhan Did you check if xml and withId will make any difference?
|
using withId will work as I have it working on my code but the problem with using XML layout is it has a bug when calling Anvil.render() see: issue 83 |
Well, this is a bugger. I don't see how Anvil can nicely handle this. Support Library developers have broken too many things here - they're injecting views, in the unexpected order, and they've overridden addView() behavior, mess with LayoutParams, and to make it even worse - they've overridden one particular Still, Anvil is a cool little library that allows to work this around (even with no xmls): textInputLayout(() -> {
size(FILL, WRAP);
init(() -> {
ViewGroup layout = Anvil.currentView();
TextInputEditText editText = new TextInputEditText(getContext());
editText.setId(123);
layout.addView(editText, layout.getChildCount(),
new LinearLayout.LayoutParams(FILL, WRAP));
});
withId(123, () -> {
size(FILL, WRAP);
textSize(sip(24));
});
hint("Some hint");
skip();
}); Here I'm creating a child view directly using its constructor. Then I assign some ID to it (it may not be unique, but it should be unique within the TextInputLayout). Then I find that edit text view by ID, set the rest of its attributes as one would normally do with Anvil, finally, I skip all the child views that were not created by Anvil. This brings the expected results. However, I have to agree, that if the view is designed to be used exclusively from XML - there is no reason to make it even more painful. I would agree with the suggestion to use an XML layout for this view hierarchy specifically. By the way, there is a good chance that existing XML-related issues are all gone, you may check the most recent marser branch - I've rewritten too much to describe it here, but you may look at #99 for a bigger picture. |
Thank you all for support! In the end, we settled for parts of our views (incompatible with latest support library) being written in XML and then bound using |
is the still getting this error with anvil 0.5.1 |
@adelnizamutdinov I'm afraid so. Unless google developers override all "addView()" methods (or remove the current particular override) I don't see how TextInputLayout can be used without XMLs or without the workround above. Perhaps moving TextInputLayout to a separate XML could give you a cleaner abstraction from its ugly internals than init(). |
here's the hack I came up with to solve this typealias IdRes = Int
inline fun textInputEditHack(id: IdRes, crossinline f: () -> Unit) {
init {
val v = Anvil.currentView<TextInputLayout>()
v.addView(TextInputEditText(v.context).also { it.id = id },
v.childCount,
LinearLayout.LayoutParams(MATCH, WRAP))
}
withId(id) {
f()
}
} |
Android support library 24.2.0 introduced these changes to
TextInputLayout
:Anvil's rendering breaks
TextInputLayout
as it always tries to replaceFrameLayout
inside withEditText
. I really like Anvil's reactive views approach, however, I'd like to also use latest stable support library. Any suggestions how to overcome this? Thank you.The text was updated successfully, but these errors were encountered: