[NUI] Fix CustomView.GetNaturalSize() to return Size2D set by user
authorJaehyun Cho <jae_hyun.cho@samsung.com>
Wed, 20 Apr 2022 02:35:49 +0000 (11:35 +0900)
committerJaehyun Cho <jaehyun0cho@gmail.com>
Thu, 21 Apr 2022 10:39:37 +0000 (19:39 +0900)
commit247ce4876305cc87b5c60d258067f6dffee25711
tree7295db6938d219131fcc3839c90f4f3549653e86
parentf49655713258a3677dd8eade3cb5dc9ac8debf0e
[NUI] Fix CustomView.GetNaturalSize() to return Size2D set by user

Originally, CustomView.GetNaturalSize() returned size set by user
explicitly.

It was changed by https://github.com/Samsung/TizenFX/pull/2515.
By the above PR, CustomView.GetNaturalSize() returned Size2D which can
be set by both user and Layout.

Since the current CustomView.GetNaturalSize() cannot distinguish the
size set by user from the size set by Layout, the size set by Layout
previously can be preserved incorrectly and the size is not updated
incorrectly.

To resolve the above issue, CustomView.GetNaturalSize() returns Size2D
set by user explicitly to make Layout preserve the size only set by user
explicitly.

e.g. problem case
var window = NUIApplication.GetDefaultWindow();

var parent = new Control()
{
    Layout = new AbsoluteLayout(),
    WidthSpecification = LayoutParamPolicies.MatchParent,
    HeightSpecification = LayoutParamPolicies.WrapContent,
    BackgroundColor = Color.Red,
};
window.Add(parent);

var child = new Control()
{
    WidthSpecification = LayoutParamPolicies.MatchParent,
    HeightSpecification = 200,
    BackgroundColor = Color.Blue,
};
parent.Add(child);

var timer = new Timer(1000);
timer.Tick += (object sender, Timer.TickEventArgs args) =>
{
    child.HeightSpecification = 100;
    return false;
};
timer.Start();
src/Tizen.NUI/src/public/BaseComponents/CustomView.cs
src/Tizen.NUI/src/public/BaseComponents/ViewBindableProperty.cs