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

Impossible to reorder/insert new layers at runtime #25

Open
jacobtabak opened this issue Aug 7, 2020 · 1 comment
Open

Impossible to reorder/insert new layers at runtime #25

jacobtabak opened this issue Aug 7, 2020 · 1 comment

Comments

@jacobtabak
Copy link

It seems that the current API of this library makes it impossible to reorder the layers (or insert new layers) to ParallaxLayerLayout at runtime.

For example, consider this XML pseudocode:

<ParallaxLayerLayout>
  <ImageView/>
  <ImageView/>
</ParallaxLayerLayout>

I want to insert another view at index 0, 1, or 2, depending on how the layers are ordered.

val layerIndex = data.layerIndex
parallaxLayerLayout.addChild(myView, layerIndex)

The newly added layer will not have any parallax effect.

This is because ParallaxLayerLayout.computeOffsets is only called once after inflate - and it is a private method. Since the view has already been inflated, the offsets are never computed for the newly added layer, and it has no parallax effect.

Workaround:
Use reflection to call ParallaxLayerLayout.computeOffsets() after adding the new view.

Proposed permanent fixes:

  • ParallaxLayerLayout.LayoutParams.customIndex should be public - if this field can be modified via XML, there should be no reason not to allow it to be modified programmatically.
  • Override addChild methods to automatically update the layout params of all the other children to allow seamless, automatic insertion of new layers.
@Sloy
Copy link
Member

Sloy commented Aug 7, 2020

Hi @jacobtabak!
Your proposed fix sound reasonable.

We're not using this library in our app anymore, so we're not actively maintaining it. But if you want to open a Pull Request we'll be happy to merge it and release an update :)

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

No branches or pull requests

2 participants