Skip to content

Commit 43bc450

Browse files
committed
[iOS] Fixed the Reset Color issue in CheckBox
1 parent e6bb31a commit 43bc450

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/Core/src/Platform/iOS/CheckBoxExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ public static void UpdateForeground(this MauiCheckBox platformCheckBox, ICheckBo
1616
{
1717
platformCheckBox.CheckBoxTintColor = solid.Color;
1818
}
19+
else if (check.Foreground is null)
20+
{
21+
// Color was cleared; reset to null so the view inherits the default tint color
22+
platformCheckBox.CheckBoxTintColor = null;
23+
}
1924
}
2025
}
2126
}

src/Core/tests/DeviceTests/Handlers/CheckBox/CheckBoxHandlerTests.iOS.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,31 @@ async Task ValidateColor(ICheckBox checkBoxStub, Color color, Action action = nu
6464
});
6565
Assert.Equal(expected, color);
6666
}
67+
68+
[Fact(DisplayName = "Foreground Resets to Default When Set to Null")]
69+
public async Task ForegroundResetsToDefaultWhenSetToNull()
70+
{
71+
var checkBoxStub = new CheckBoxStub
72+
{
73+
Foreground = new SolidPaint(Colors.Red),
74+
IsChecked = true
75+
};
76+
77+
await InvokeOnMainThreadAsync(() =>
78+
{
79+
var handler = CreateHandler(checkBoxStub);
80+
var native = GetNativeCheckBox(handler);
81+
82+
// Confirm that the red tint was applied initially
83+
Assert.NotNull(native.CheckBoxTintColor);
84+
85+
// Simulate a dynamic Color = null (Foreground reset to default)
86+
checkBoxStub.Foreground = null;
87+
handler.UpdateValue(nameof(ICheckBox.Foreground));
88+
89+
// After reset, the native tint must be null so iOS reverts to its inherited default
90+
Assert.Null(native.CheckBoxTintColor);
91+
});
92+
}
6793
}
6894
}

0 commit comments

Comments
 (0)