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

Support FrameLayout #11

Open
pocmo opened this issue Sep 15, 2020 · 10 comments
Open

Support FrameLayout #11

pocmo opened this issue Sep 15, 2020 · 10 comments
Assignees
Labels
enhancement New feature or request view Issues about supporting specific vews

Comments

@pocmo
Copy link
Owner

pocmo commented Sep 15, 2020

View:
https://developer.android.com/reference/android/widget/FrameLayout

Composable:
Maybe we can just translate it to a Box() with children?

@pocmo pocmo added enhancement New feature or request view Issues about supporting specific vews labels Sep 15, 2020
@jerryOkafor
Copy link
Contributor

Hi, @pocmo I am thinking that Stack would be a better option here especially for FrameLayout with children.
https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/package-summary#stack

@jerryOkafor
Copy link
Contributor

looks like all good first start issues have finished for, I might be interested in working on this one.

@pocmo
Copy link
Owner Author

pocmo commented Oct 1, 2020

Yes, you are right, Stack looks like a great fit! I'll assign you to the issue. :)

@jerryOkafor
Copy link
Contributor

@pocmo I need help here. How would you suggest I handle a case of android:gravity="top|start" where we have two raw values separated by |?.

I have verified that the gravity is added as Modifier to any View or ViewGroup. so if I have top|start, it should recompose to Alignment.TopStart for gravity modifier.

@pocmo
Copy link
Owner Author

pocmo commented Oct 1, 2020

Here's an idea...

Android uses bit masks internally.

So top|start is equivalent to Gravity.TOP or Gravity.START in Kotlin code.

Gravity.TOP is 0x00000030
Gravity.START is 0x00800003 (which is actually LEFT or RELATIVE_LAYOUT_DIRECTION)

So the combined value is 0x00800033 (Gravity.TOP or Gravity.START`).

If we map the parsed gravity values to their actual values in the Gravity class and if we map the available Alignment values to the same combined values, then we should be able to translate between them, e.g.:

Gravity.TOP (0x00000030) or Gravity.START is 0x00800003 = Alignment.TopStart (0x00800033).

Does this make sense? We would need to keep a map from gravity to Int and from Int to Alignment. Do you think that could work?

@Foso
Copy link
Contributor

Foso commented Oct 1, 2020

FYI: Jetpack Compose 1.0.0-alpha04 just got released,

Stack was renamed to Box. The previously existing Box will be deprecated in favor of the new Box in compose.foundation.layout. The behavior of the new Box is to stack children one on top of another when it has multiple children - this is different from the previous Box, which was behaving similar to a Column

@jerryOkafor
Copy link
Contributor

Thanks for the heads up. I will check out the new Box then.

@jerryOkafor
Copy link
Contributor

Here's an idea...

Android uses bit masks internally.

So top|start is equivalent to Gravity.TOP or Gravity.START in Kotlin code.

Gravity.TOP is 0x00000030
Gravity.START is 0x00800003 (which is actually LEFT or RELATIVE_LAYOUT_DIRECTION)

So the combined value is 0x00800033 (Gravity.TOP or Gravity.START`).

If we map the parsed gravity values to their actual values in the Gravity class and if we map the available Alignment values to the same combined values, then we should be able to translate between them, e.g.:

Gravity.TOP (0x00000030) or Gravity.START is 0x00800003 = Alignment.TopStart (0x00800033).

Does this make sense? We would need to keep a map from gravity to Int and from Int to Alignment. Do you think that could work?

Yes, this could work. I observed that gravity attributes: android:gravity and android:layout_gravity can be used in any View or ViewGroup as necessary. I suppose we have to add it as a View/ViewGroup attribute so that it can apply for FrameLayout with multiple children.

Also, I observed that when you have a known ViewGroup as the root of the XML to be parsed, the ViewGroup attribute is not parsed while that of the children is parsed.

@jerryOkafor
Copy link
Contributor

I found out why the observed issue in the last paragraph was happening, I did not add val rowModifier = ModifierBuilder(node) to the function visiting FrameLayout. It is fine now.

pocmo pushed a commit that referenced this issue Oct 2, 2020
@pocmo
Copy link
Owner Author

pocmo commented Oct 2, 2020

Since we added basic support for FrameLayout I am going to close this issue and will open a new one for adding support for gravity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request view Issues about supporting specific vews
Projects
None yet
Development

No branches or pull requests

3 participants