Skip to content
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

EpoxyModelGroup with ViewStub #672

Closed
eboudrant opened this issue Feb 1, 2019 · 3 comments · Fixed by #676
Closed

EpoxyModelGroup with ViewStub #672

eboudrant opened this issue Feb 1, 2019 · 3 comments · Fixed by #676

Comments

@eboudrant
Copy link
Contributor

eboudrant commented Feb 1, 2019

I am trying to layout a model group using ViewStub, here the xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <!-- First element -->
    <ViewStub
        android:layout_width="60dp"
        android:layout_height="60dp" />

    <!-- Elastic space -->
    <View
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" />

    <!-- And up to 3 elements -->
    <ViewStub
        android:layout_width="60dp"
        android:layout_height="60dp" />
    <ViewStub
        android:layout_width="60dp"
        android:layout_height="60dp" />
    <ViewStub
        android:layout_width="60dp"
        android:layout_height="60dp" />

</LinearLayout>

I am expecting :

screen shot 2019-02-01 at 1 45 34 pm

But I am seeing this :

screen shot 2019-02-01 at 1 46 19 pm

Is there any issue with EpoxyModelGroup / ViewStub or is it a miss-use from me ?

Full code is here : eboudrant#9

@eboudrant eboudrant changed the title EpoxyModelGroup with ViewStup EpoxyModelGroup with ViewStub Feb 1, 2019
@eboudrant
Copy link
Contributor Author

eboudrant commented Feb 1, 2019

Looks like the stub are removed too early from the layout :

The position passed in the ViewStubData would not allow to re-position correctly the nested model.

A quick fix would be to remove the view stub when we set the view in ViewStubData :

    fun setView(view: View, useStubLayoutParams: Boolean) {
        // Carry over the stub id manually since we aren't inflating via the stub
        val inflatedId = viewStub.inflatedId
        if (inflatedId != View.NO_ID) {
            view.id = inflatedId
        }

        if (useStubLayoutParams) {
            viewGroup.removeView(viewStub)
            viewGroup.addView(view, position, viewStub.layoutParams)
        } else {
            viewGroup.removeView(viewStub)
            viewGroup.addView(view, position)
        }
    }

But stub's discovery need to be re-written a but as it rely in stub being removed...

@elihart
Copy link
Contributor

elihart commented Feb 2, 2019

Thanks for reporting. good catch, this is definitely wrong.

I'm traveling now, but can fix it early next week - sorry for the issue!

Maybe an easy fix could be to have getNextViewStub add the count of existing stubs to the index of the newly created stub data - I think that would give the correct adjusted position while not requiring a change to the view removal - I'll have to think about it a bit more though.

@elihart
Copy link
Contributor

elihart commented Feb 5, 2019

#676

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants