From a0fbeeff9ba21c3a3d6dd9cfe11290d1ac23d268 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Thu, 27 Apr 2023 09:48:55 -0700 Subject: [PATCH 1/4] Deprecate Java YogaConfig.setUseLegacyStretchBehaviour() Summary: Now that our own usages are removed, mark this as deprecated to encourage users to move to the errata API. The same will be done to variants of this function on other platforms before releasing, and the functions will be removed after releasing. Differential Revision: D45300343 fbshipit-source-id: 084a6bfd295d6f68f9976280f636cd754928a175 --- java/com/facebook/yoga/YogaConfig.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/java/com/facebook/yoga/YogaConfig.java b/java/com/facebook/yoga/YogaConfig.java index 87928f02..93131359 100644 --- a/java/com/facebook/yoga/YogaConfig.java +++ b/java/com/facebook/yoga/YogaConfig.java @@ -22,7 +22,13 @@ public abstract class YogaConfig { * Yoga previously had an error where containers would take the maximum space possible instead of the minimum * like they are supposed to. In practice this resulted in implicit behaviour similar to align-self: stretch; * Because this was such a long-standing bug we must allow legacy users to switch back to this behaviour. + * + * @deprecated "setUseLegacyStretchBehaviour" will be removed in the next release. Usage should be replaced with + * "setErrata(YogaErrata.ALL)" to opt out of all future breaking conformance fixes, or + * "setErrata(YogaErrata.STRETCH_FLEX_BASIS)" to opt out of the specific conformance fix previously disabled by + * "UseLegacyStretchBehaviour". */ + @Deprecated public abstract void setUseLegacyStretchBehaviour(boolean useLegacyStretchBehaviour); public abstract void setErrata(YogaErrata errata); -- 2.50.1.windows.1 From f206f5cfcbc12fa4db5b199e281c4e890b09fd31 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Thu, 27 Apr 2023 09:48:55 -0700 Subject: [PATCH 2/4] Move YogaKit to YGErrataClassic Summary: YogaKit integrates Yoga with UIKit as a higher level framework. It does not expose config setting to users. We set YGErrataClassic for now to prioritize compatibility instead of conformance (YogaKit is relatively used in fbsource as well). I'm also tempted to remove the usage of ExperimentalWebFlexBasis since last I heard rozelle thought it was generally broken, but I am a bit afraid to if it has been enabled so long, and is used in many cases in Meta. Differential Revision: https://internalfb.com/D45298803 fbshipit-source-id: 266efce67de5bf9fb24982267ee4f4df59151a9f --- YogaKit/Source/YGLayout.m | 1 + 1 file changed, 1 insertion(+) diff --git a/YogaKit/Source/YGLayout.m b/YogaKit/Source/YGLayout.m index 1627a74f..638a81da 100644 --- a/YogaKit/Source/YGLayout.m +++ b/YogaKit/Source/YGLayout.m @@ -175,6 +175,7 @@ static YGConfigRef globalConfig; globalConfig = YGConfigNew(); YGConfigSetExperimentalFeatureEnabled( globalConfig, YGExperimentalFeatureWebFlexBasis, true); + YGConfigSetErrata(globalConfig, YGErrataClassic); YGConfigSetPointScaleFactor(globalConfig, [UIScreen mainScreen].scale); } -- 2.50.1.windows.1 From fbdd86c188c1bd06b8f7613e0683994256daefb0 Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Thu, 27 Apr 2023 09:48:55 -0700 Subject: [PATCH 3/4] Add C# bindings for Errata API Summary: Wires C ABI to C# bindings using `System.Runtime.InteropServices`. Note that we don't have a working C# build right now, but there is [effort to address that](https://github.com/facebook/yoga/pull/1207) which may get some more effort before the Yoga release, so this keeps the bindings up to date. Differential Revision: https://internalfb.com/D45297676 fbshipit-source-id: 07ca3b5c0509f18ad825029804b68ccb5c4e5522 --- csharp/Facebook.Yoga/Native.cs | 6 ++++++ csharp/Facebook.Yoga/YogaConfig.cs | 21 +++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/csharp/Facebook.Yoga/Native.cs b/csharp/Facebook.Yoga/Native.cs index 1bdc24f0..f22e5888 100644 --- a/csharp/Facebook.Yoga/Native.cs +++ b/csharp/Facebook.Yoga/Native.cs @@ -73,6 +73,12 @@ namespace Facebook.Yoga [DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] public static extern bool YGConfigGetUseLegacyStretchBehaviour(YGConfigHandle config); + [DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] + public static extern void YGConfigSetErrata(YGConfigHandle config, YogaErrata errata); + + [DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] + public static extern YogaErrata YGConfigGetErrata(YGConfigHandle config); + [DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] public static extern void YGConfigSetPointScaleFactor( YGConfigHandle config, diff --git a/csharp/Facebook.Yoga/YogaConfig.cs b/csharp/Facebook.Yoga/YogaConfig.cs index 8424401f..c4162d31 100644 --- a/csharp/Facebook.Yoga/YogaConfig.cs +++ b/csharp/Facebook.Yoga/YogaConfig.cs @@ -117,8 +117,12 @@ namespace Facebook.Yoga } } - public bool UseLegacyStretchBehaviour - { + [ObsoleteAttribute("\"UseLegacyStretchBehaviour\" will be removed in the next release. " + + "Usage should be replaced with \"Errata\" set to \"YogaErrata.All\" to opt out of all " + + "future breaking conformance fixes, or \"YogaErrata.StretchFlexBasis\" toopt out of " + + "the specific conformance fix previously disabled by \"UseLegacyStretchBehaviour\".", + true /*error*/)] + public bool UseLegacyStretchBehaviour { get { return Native.YGConfigGetUseLegacyStretchBehaviour(_ygConfig); @@ -130,6 +134,19 @@ namespace Facebook.Yoga } } + public YogaErrata Errata + { + get + { + return Native.YGConfigGetErrata(_ygConfig); + } + + set + { + Native.YGConfigSetErrata(_ygConfig, value); + } + } + public float PointScaleFactor { set -- 2.50.1.windows.1 From 265303c97b7c504ebd353b215e694c79a7c18e5a Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Thu, 27 Apr 2023 09:49:23 -0700 Subject: [PATCH 4/4] Add JavaScript bindings for Errata API (#1260) Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1260 Wire C ABI to embind to expose to JS Reviewed By: yungsters Differential Revision: D45297215 fbshipit-source-id: a13d60bc0ad82d7697564136f4d944e8f70db8ec --- javascript/src_js/wrapAsm.d.ts | 13 +++++++++ javascript/src_native/Config.cc | 12 +++++++-- javascript/src_native/Config.hh | 6 +++-- javascript/src_native/embind.cc | 2 ++ javascript/tests/YGErrataTest.test.js | 38 +++++++++++++++++++++++++++ 5 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 javascript/tests/YGErrataTest.test.js diff --git a/javascript/src_js/wrapAsm.d.ts b/javascript/src_js/wrapAsm.d.ts index 4af2cd67..022ac5f3 100644 --- a/javascript/src_js/wrapAsm.d.ts +++ b/javascript/src_js/wrapAsm.d.ts @@ -12,6 +12,7 @@ import type { Direction, Display, Edge, + Errata, ExperimentalFeature, FlexDirection, Gutter, @@ -52,8 +53,20 @@ export type Config = { enabled: boolean ): void; setPointScaleFactor(factor: number): void; + /** + * @deprecated Please use "getErrata()" + */ useLegacyStretchBehaviour(): boolean; + /** + * @deprecated "setUseLegacyStretchBehaviour" will be removed in the next + * release. Usage should be replaced with "setErrata(ERRATA_ALL)" to opt out + * of all future breaking conformance fixes, or + * "setErrata(ERRATA_STRETCH_FLEX_BASIS)" to opt out of the specific + * conformance fix previously disabled by "UseLegacyStretchBehaviour". + */ setUseLegacyStretchBehaviour(useLegacyStretchBehaviour: boolean): void; + getErrata(): Errata, + setErrata(errata: Errata): void, useWebDefaults(): boolean; setUseWebDefaults(useWebDefaults: boolean): void; }; diff --git a/javascript/src_native/Config.cc b/javascript/src_native/Config.cc index 3824f519..ebcfe44a 100644 --- a/javascript/src_native/Config.cc +++ b/javascript/src_native/Config.cc @@ -36,6 +36,10 @@ void Config::setUseLegacyStretchBehaviour(bool useLegacyStretchBehaviour) { YGConfigSetUseLegacyStretchBehaviour(m_config, useLegacyStretchBehaviour); } +void Config::setErrata(int errata) { + YGConfigSetErrata(m_config, static_cast(errata)); +} + void Config::setUseWebDefaults(bool useWebDefaults) { YGConfigSetUseWebDefaults(m_config, useWebDefaults); } @@ -45,10 +49,14 @@ bool Config::isExperimentalFeatureEnabled(int feature) const { m_config, static_cast(feature)); } -bool Config::useLegacyStretchBehaviour() { +bool Config::useLegacyStretchBehaviour() const { return YGConfigGetUseLegacyStretchBehaviour(m_config); } -bool Config::useWebDefaults() { +int Config::getErrata() const { + return static_cast(YGConfigGetErrata(m_config)); +} + +bool Config::useWebDefaults() const { return YGConfigGetUseWebDefaults(m_config); } diff --git a/javascript/src_native/Config.hh b/javascript/src_native/Config.hh index ccebfa67..5abfdd5b 100644 --- a/javascript/src_native/Config.hh +++ b/javascript/src_native/Config.hh @@ -33,12 +33,14 @@ public: // Setters void setExperimentalFeatureEnabled(int feature, bool enabled); void setPointScaleFactor(float pixelsInPoint); void setUseLegacyStretchBehaviour(bool useLegacyStretchBehaviour); + void setErrata(int errata); void setUseWebDefaults(bool useWebDefaults); public: // Getters bool isExperimentalFeatureEnabled(int feature) const; - bool useLegacyStretchBehaviour(); - bool useWebDefaults(); + bool useLegacyStretchBehaviour() const; + int getErrata() const; + bool useWebDefaults() const; private: YGConfigRef m_config; diff --git a/javascript/src_native/embind.cc b/javascript/src_native/embind.cc index a59c8e40..280d9328 100644 --- a/javascript/src_native/embind.cc +++ b/javascript/src_native/embind.cc @@ -34,10 +34,12 @@ EMSCRIPTEN_BINDINGS(YOGA_LAYOUT) { .function("setPointScaleFactor", &Config::setPointScaleFactor) .function( "setUseLegacyStretchBehaviour", &Config::setUseLegacyStretchBehaviour) + .function("setErrata", &Config::setErrata) .function("setUseWebDefaults", &Config::setUseWebDefaults) .function( "isExperimentalFeatureEnabled", &Config::isExperimentalFeatureEnabled) .function("useLegacyStretchBehaviour", &Config::useLegacyStretchBehaviour) + .function("getErrata", &Config::getErrata) .function("useWebDefaults", &Config::useWebDefaults); value_object("Layout") diff --git a/javascript/tests/YGErrataTest.test.js b/javascript/tests/YGErrataTest.test.js new file mode 100644 index 00000000..4a268151 --- /dev/null +++ b/javascript/tests/YGErrataTest.test.js @@ -0,0 +1,38 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +test("errata_all_contains_example_errata", () => { + const config = Yoga.Config.create(); + config.setErrata(Yoga.ERRATA_ALL); + + expect(config.getErrata()).toBe(Yoga.ERRATA_ALL); + expect(config.getErrata() & Yoga.ERRATA_STRETCH_FLEX_BASIS).not.toBe(0); + + config.free(); +}); + +test("errata_none_omits_example_errata", () => { + const config = Yoga.Config.create(); + config.setErrata(Yoga.ERRATA_NONE); + + expect(config.getErrata()).toBe(Yoga.ERRATA_NONE); + expect(config.getErrata() & Yoga.ERRATA_STRETCH_FLEX_BASIS).toBe(0); + + config.free(); +}); + +test("errata_is_settable", () => { + const config = Yoga.Config.create(); + + config.setErrata(Yoga.ERRATA_ALL); + expect(config.getErrata()).toBe(Yoga.ERRATA_ALL); + + config.setErrata(Yoga.ERRATA_NONE); + expect(config.getErrata()).toBe(Yoga.ERRATA_NONE); + + config.free(); +}); -- 2.50.1.windows.1