Percent values not settable through YogaKit #371
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi! I looked through #258 and it looks like SetXPercent functions were added to the C API, and the iOS bindings were discussed but never implemented? Is anyone working on this right now? If not, I could take a stab and open a PR, but there are a lot of possible ways to write the API so I'd want to make sure I went down the right path. (Copy the C API exactly, create new properties, go for a breaking change and replace the CGFloat properties with some sort of unit type, etc.)
@dshahidehpour Have you thought about how we want to add this to the API?
@emilsjolander I haven't, actually.
@jconst if you have the time, and you're interested, take a stab at it! I'd be happy to review. Shouldn't be too much plumbing.
@hartbit Have any ideas about the API ideas for this?
I would down with going down the line of
view.yoga.widthPercentage = .4
,but I'm not sure what value should be returned when you accessview.yoga.width
after setting a percentage.I've know for a while what I want for Swift:
For Objective-C, I think
view.yoga.widthPercentage = .4
is the way forward. And I thinkview.yoga.width
after setting a percentage should returnYGUndefined
.@jconst I don't mind writing the PR btw if you want :)
@hartbit Could you explore using
YGValue
directly? This would make the getter return value more meaningful and reduce the number of properties needed. I like the syntactic sugar suggested for swift!@emilsjolander Here are a few ideas off the top of my head, from most to least verbose & idiomatic:
Two points:
view.yoga.width = 10
.pixel
instead ofpoint
in a world where different platforms are moving rapidly away from pixel measurements and more towards dynamic DPI (especially on iOS). But I don't know if we should try to hide the term pixel on iOS only or also modify the C implementation.Regarding pixel vs point. I'm fine with changing the
YGUnit
name to be point instead of pixel. That should be a separate PR though.I agree that loosing
view.yoga.width = 10
would be sad. However if it was as easy asview.yoga.width = pt(10)
then maybe that's ok. I agree thatview.yoga.width = YGValueMake(10, YGUnitPoint)
orview.yoga.width = YGPointMake(10)
would be more idiomatic though.I'm fairly confident that I would like
view.yoga.width
to return aYGValue
though. This means we won't have undefined return values and it would automatically handleYGUnitAuto
added in https://github.com/facebook/yoga/pull/357.Will submit a PR with this change first of all then. This evening probably (GMT+1).
Now that I think more about it, I don't like
YGPointMake(10)
andYGPercentMake(40)
. It seems as if you're "making" a point/pixel, which you're not, you're creating a value with those units. That means this is what we're left with:Yeah, I agree, it has to be a
YGValue
property. By the way, here's how we could do auto in Swift by surfacingYGValue
as aValue
enum with associated values:/drool
That swift code looks amazing
+1 on the swift code, great idea @hartbit!
Yeah, I think this is the right move for YogaKit.
So did we ever come to conclusion about the getter values?
.width
will now return aYGValue
? I don't really see this being a big deal. I don't think I've used a getter a single time since I've started converting views, and it looks like we have a great solution for Setters.@hartbit What do you think about this for Objective-C syntax?
Yeah, sounds good to me.
I think that's a good compromise. I'll go forward with that. Anyway, who uses Objective-C nowadays (joking :p)
I posted the PR that renames
YGUnitPixel
toYGUnitPoint
: #375. Once it's merged I'll get the PR up for percent support.Looks like this was resolved by https://github.com/facebook/yoga/pull/390