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

Layout breaks view arrangements #1232

Closed
mohpor opened this issue May 21, 2019 · 6 comments
Closed

Layout breaks view arrangements #1232

mohpor opened this issue May 21, 2019 · 6 comments

Comments

@mohpor
Copy link
Contributor

mohpor commented May 21, 2019

Hi,

In Material 2.x when we used Layout, we considered the child as free and the layout function would add it to the parent, and it is done through addSubview, there were cases that this was not the desired effect, for example when I add a blur view in my code, I want it to be at the bottom, so, first I would've inserted the child at 0, and then lay it out:

parent.insertSubview(child, at: 0)
parent.layout(child).edges()

Material 3 breaks this simple rule and adds the child to super view, without checking to see if the child already has a parent, and therefore breaks the arrangement the developer might have desired.

There is workaround for this, you can simply arrange the view afterwards, but now I have to look for every instance I've done it! This is a breaking change.

P.S.: I did the Material 2's Layout, although it has been erased from git's history due to restructuring.

@mohpor
Copy link
Contributor Author

mohpor commented May 21, 2019

This is a serious problem.
I'm sure many developers would see views that has been laid out using Layout out of order, without being able to detect why this is happening!

@OrkhanAlikhanov
Copy link
Contributor

OrkhanAlikhanov commented May 21, 2019

So the problem is that order of inserted view changes? The reason might be we don't check if the view is already child.

func layout(_ child: UIView) -> Layout {
addSubview(child)
child.translatesAutoresizingMaskIntoConstraints = false
return child.layout
}

@mohpor
Copy link
Contributor Author

mohpor commented May 21, 2019

Exactly,
In the previous versions, in the layout function, we added the subview ONLY if the parent was missing!

@OrkhanAlikhanov
Copy link
Contributor

I submitted PR for this. Thank you for reporting 💪

@OrkhanAlikhanov
Copy link
Contributor

OrkhanAlikhanov commented May 21, 2019

Btw, you could workaround it by:

parent.insertSubview(child, at: 0)
child.translatesAutoresizingMaskIntoConstraints = false
child.layout.edges()

:)

@daniel-jonathan
Copy link
Member

daniel-jonathan commented May 21, 2019

@mohpor please find your fix here and thank you for bringing this to our attention: https://github.com/CosmicMind/Material/releases/tag/3.1.2, thank you @OrkhanAlikhanov :)

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

No branches or pull requests

3 participants