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

Allow specifying which axes are included in the final measurement when using ElementContent(measuring:) #474

Closed
wants to merge 1 commit into from

Conversation

kyleve
Copy link
Collaborator

@kyleve kyleve commented Dec 8, 2023

When using ElementContent(measuring:) to create essentially a smart "Spacer" based on the size of an element, it's desirable to include in the final size on only one of the measurement dimensions. Thus, expose an Axes type you can optionally pass to the initializer to control this.

@kyleve kyleve requested a review from a team as a code owner December 8, 2023 00:06
@square square deleted a comment from robmaceachern Dec 8, 2023
@@ -279,8 +279,23 @@ extension ElementContent {
///
/// This is useful if you are placing the element in a nested `BlueprintView`, for example (eg
/// to create a stateful element) and just need this element to be correctly sized.
public init(measuring element: Element) {
storage = MeasureElementStorage(child: element)
Copy link
Collaborator Author

@kyleve kyleve Dec 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posting here for posterity: We could expose a method like

extension Element {
   func asSpacer(along axes: MeasuringAxes = .both) -> Element { ... } 
}

So that you could use any ol' element as a dynamic spacer – which has been an infrequent but not uncommon or unreasonable ask. I think for now, I'm not going to add this, but this would make it easier for some of these cases. I might put a call out in #market-ios to see if anyone would find this helpful.

@kyleve
Copy link
Collaborator Author

kyleve commented Dec 11, 2023

@watt pointed out I can wrap this up in another element and then just ignore one of the measurements, which makes a lot more sense! I entirely missed that last week when I had been trying to figure out how to do that.

@kyleve kyleve closed this Dec 11, 2023
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 this pull request may close these issues.

1 participant