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

Fix Switch Off Track Color - Fixes #10099 #10758

Merged
merged 28 commits into from
Apr 3, 2023
Merged
Changes from 3 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
786613e
Add a default color to the track in the off position
Oct 11, 2022
0292d5d
Merge remote-tracking branch 'origin/main' into FixSwitchTrackColor
Oct 17, 2022
ee176d7
remove unneeded using statement
Oct 17, 2022
8b91c27
Use UIColor to handle dark mode
Oct 20, 2022
890ddd5
remove noise
Oct 20, 2022
614cc22
Merge remote-tracking branch 'origin/main' into FixSwitchTrackColor
Oct 31, 2022
60ea991
Merge remote-tracking branch 'origin/main' into FixSwitchTrackColor
Nov 8, 2022
47b8af2
Add tests and add null checks for getting subviews
Nov 9, 2022
6bf4edf
add new lines
Nov 9, 2022
6defdbe
Merge branch 'main' into FixSwitchTrackColor
tj-devel709 Nov 11, 2022
bf7d903
Merge remote-tracking branch 'origin/main' into FixSwitchTrackColor
Nov 14, 2022
feb48a7
Move the tests into the iOS Test
Nov 14, 2022
11db0f9
remove UIKit on the shared file
Nov 14, 2022
dbfb115
- fix checkbox test
PureWeen Nov 16, 2022
cd6f4b4
fix style
Nov 18, 2022
f0c1b46
Merge remote-tracking branch 'origin/main' into FixSwitchTrackColor
Nov 18, 2022
e366576
removing the few unneeded changes
Nov 21, 2022
84b29ff
move the code from the mapper to the extensions
Nov 22, 2022
c887721
Merge branch 'main' into FixSwitchTrackColor
PureWeen Dec 1, 2022
34743d5
move from extension to mapper and use FirstOrDefault
Mar 29, 2023
f8a41d2
Merge remote-tracking branch 'TJ/FixSwitchTrackColor' into FixSwitchT…
Mar 29, 2023
d210eff
Merge remote-tracking branch 'origin/main' into FixSwitchTrackColor
Mar 29, 2023
de13bee
Auto-format source code
Mar 29, 2023
b2eae95
change test name and make color a static var
Mar 29, 2023
daf8876
Merge remote-tracking branch 'TJ/FixSwitchTrackColor' into FixSwitchT…
Mar 29, 2023
92bc1f9
use Manuels NoLink alternative
Mar 31, 2023
f34cc10
move to arrayExtensions and use different implementation
Mar 31, 2023
50fbc8f
allow param to be null
Apr 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions src/Core/src/Platform/iOS/SwitchExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ namespace Microsoft.Maui.Platform
{
public static class SwitchExtensions
{
static UIColor? OffTrackColor;
static bool HasSwitched;

public static void UpdateIsOn(this UISwitch uiSwitch, ISwitch view)
{
uiSwitch.SetState(view.IsOn, true);
Expand All @@ -17,17 +20,26 @@ public static void UpdateTrackColor(this UISwitch uiSwitch, ISwitch view)
if (view == null)
return;

if (view.TrackColor != null)
uiSwitch.OnTintColor = view.TrackColor.ToPlatform();
UpdateOffTrackColor(uiSwitch);

UIView uIView;
if (OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsTvOSVersionAtLeast(13))
uIView = uiSwitch.Subviews[0].Subviews[0];
else
uIView = uiSwitch.Subviews[0].Subviews[0].Subviews[0];
var uIView = GetTrackSubview(uiSwitch);

if (!view.IsOn)
uIView.BackgroundColor = OffTrackColor;

if (view.TrackColor != null)
else if (view.TrackColor is not null) {
uiSwitch.OnTintColor = view.TrackColor.ToPlatform ();
uIView.BackgroundColor = uiSwitch.OnTintColor;
}
}

static void UpdateOffTrackColor (UISwitch uiSwitch)
{
if (!HasSwitched)
{
OffTrackColor = uiSwitch.GetOffTrackColor();
HasSwitched = true;
}
}

public static void UpdateThumbColor(this UISwitch uiSwitch, ISwitch view)
Expand All @@ -42,13 +54,10 @@ public static void UpdateThumbColor(this UISwitch uiSwitch, ISwitch view)

internal static UIView GetTrackSubview(this UISwitch uISwitch)
{
UIView uIView;
if (OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsTvOSVersionAtLeast(13))
uIView = uISwitch.Subviews[0].Subviews[0];
return uISwitch.Subviews[0].Subviews[0];
else
uIView = uISwitch.Subviews[0].Subviews[0].Subviews[0];

return uIView;
return uISwitch.Subviews[0].Subviews[0].Subviews[0];
}

internal static UIColor? GetOffTrackColor(this UISwitch uISwitch)
Expand Down