Skip to content

Commit

Permalink
Implement (#10657)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfversluis authored May 15, 2020
1 parent 5253259 commit b995e20
Show file tree
Hide file tree
Showing 4 changed files with 445 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public AppThemeGallery()
GalleryBuilder.NavButton("AppTheme Code", () =>
new AppThemeCodeGallery(), Navigation),
GalleryBuilder.NavButton("AppTheme XAML", () =>
new AppThemeXamlGallery(), Navigation)
new AppThemeXamlGallery(), Navigation),
GalleryBuilder.NavButton("GetNamedColor", () =>
new NamedPlatformColorGallery(), Navigation)
}
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
using System.Collections.Generic;

namespace Xamarin.Forms.Controls.GalleryPages.AppThemeGalleries
{
public class NamedPlatformColorGallery : ContentPage
{
readonly string[] _colors;
readonly StackLayout _stackLayout = new StackLayout
{
Padding = new Thickness(10)
};

public NamedPlatformColorGallery()
{
Content = new ScrollView
{
Content = _stackLayout
};

_colors = GetPlatFormColorNames();

BuildColors();
}

protected override void OnRequestedThemeChanged(OSAppTheme newValue)
{
base.OnRequestedThemeChanged(newValue);

BuildColors();
}

void BuildColors()
{
if (_colors == null || _colors.Length == 0)
return;

_stackLayout.Children.Clear();

for (var i = 0; i < _colors.Length; i++)
{
var color = Device.GetNamedColor(_colors[i]);

var box = new Frame
{
BackgroundColor = color,
Content = new StackLayout
{
Children =
{
new Label { Text = _colors[i] },
new Label { Text = color.ToHex() }
}
},
HasShadow = false,
Margin = 10,
HeightRequest = 60
};

_stackLayout.Children.Add(box);
}
}

string[] GetPlatFormColorNames()
{
List<string> resultColors = new List<string>();

if (Device.RuntimePlatform == Device.macOS || Device.RuntimePlatform == Device.iOS)
{
resultColors.AddRange(new[] {
NamedPlatformColor.SystemBlue,
NamedPlatformColor.SystemGreen,
NamedPlatformColor.SystemIndigo,
NamedPlatformColor.SystemOrange,
NamedPlatformColor.SystemPink,
NamedPlatformColor.SystemPurple,
NamedPlatformColor.SystemRed,
NamedPlatformColor.SystemTeal,
NamedPlatformColor.SystemYellow,
NamedPlatformColor.SystemGray,
NamedPlatformColor.Label,
NamedPlatformColor.SecondaryLabel,
NamedPlatformColor.TertiaryLabel,
NamedPlatformColor.QuaternaryLabel,
NamedPlatformColor.PlaceholderText,
NamedPlatformColor.Separator,
NamedPlatformColor.Link
});
}

if (Device.RuntimePlatform == Device.iOS)
{
resultColors.AddRange(new[] {
NamedPlatformColor.SystemGray2,
NamedPlatformColor.SystemGray3,
NamedPlatformColor.SystemGray4,
NamedPlatformColor.SystemGray5,
NamedPlatformColor.SystemGray6,
NamedPlatformColor.OpaqueSeparator
});
}

if (Device.RuntimePlatform == Device.macOS)
{
resultColors.AddRange(new[] {
NamedPlatformColor.AlternateSelectedControlTextColor,
NamedPlatformColor.ControlAccent,
NamedPlatformColor.ControlBackgroundColor,
NamedPlatformColor.ControlColor,
NamedPlatformColor.ControlTextColor,
NamedPlatformColor.DisabledControlTextColor,
NamedPlatformColor.FindHighlightColor,
NamedPlatformColor.GridColor,
NamedPlatformColor.HeaderTextColor,
NamedPlatformColor.HighlightColor,
NamedPlatformColor.KeyboardFocusIndicatorColor,
NamedPlatformColor.LabelColor,
NamedPlatformColor.LinkColor,
NamedPlatformColor.PlaceholderTextColor,
NamedPlatformColor.QuaternaryLabelColor,
NamedPlatformColor.SecondaryLabelColor,
NamedPlatformColor.SelectedContentBackgroundColor,
NamedPlatformColor.SelectedControlColor,
NamedPlatformColor.SelectedControlTextColor,
NamedPlatformColor.SelectedMenuItemTextColor,
NamedPlatformColor.SelectedTextBackgroundColor,
NamedPlatformColor.SelectedTextColor,
NamedPlatformColor.SeparatorColor,
NamedPlatformColor.ShadowColor,
NamedPlatformColor.TertiaryLabelColor,
NamedPlatformColor.TextBackgroundColor,
NamedPlatformColor.TextColor,
NamedPlatformColor.UnderPageBackgroundColor,
NamedPlatformColor.UnemphasizedSelectedContentBackgroundColor,
NamedPlatformColor.UnemphasizedSelectedTextBackgroundColor,
NamedPlatformColor.UnemphasizedSelectedTextColor,
NamedPlatformColor.WindowBackgroundColor,
NamedPlatformColor.WindowFrameTextColor
});
}

if (Device.RuntimePlatform == Device.Android)
{
resultColors.AddRange(new[] {
NamedPlatformColor.BackgroundDark,
NamedPlatformColor.BackgroundLight,
NamedPlatformColor.Black,
NamedPlatformColor.DarkerGray,
NamedPlatformColor.HoloBlueBright,
NamedPlatformColor.HoloBlueDark,
NamedPlatformColor.HoloBlueLight,
NamedPlatformColor.HoloGreenDark,
NamedPlatformColor.HoloGreenLight,
NamedPlatformColor.HoloOrangeDark,
NamedPlatformColor.HoloOrangeLight,
NamedPlatformColor.HoloPurple,
NamedPlatformColor.HoloRedDark,
NamedPlatformColor.HoloRedLight,
NamedPlatformColor.TabIndicatorText,
NamedPlatformColor.Transparent,
NamedPlatformColor.White,
NamedPlatformColor.WidgetEditTextDark
});
}

if (Device.RuntimePlatform == Device.UWP)
{
resultColors.AddRange(new[] {
NamedPlatformColor.SystemAltLowColor,
NamedPlatformColor.SystemAltMediumColor,
NamedPlatformColor.SystemAltMediumHighColor,
NamedPlatformColor.SystemAltMediumLowColor,
NamedPlatformColor.SystemBaseHighColor,
NamedPlatformColor.SystemBaseLowColor,
NamedPlatformColor.SystemBaseMediumColor,
NamedPlatformColor.SystemBaseMediumHighColor,
NamedPlatformColor.SystemBaseMediumLowColor,
NamedPlatformColor.SystemChromeAltLowColor,
NamedPlatformColor.SystemChromeBlackHighColor,
NamedPlatformColor.SystemChromeBlackLowColor,
NamedPlatformColor.SystemChromeBlackMediumLowColor,
NamedPlatformColor.SystemChromeBlackMediumColor,
NamedPlatformColor.SystemChromeDisabledHighColor,
NamedPlatformColor.SystemChromeDisabledLowColor,
NamedPlatformColor.SystemChromeHighColor,
NamedPlatformColor.SystemChromeLowColor,
NamedPlatformColor.SystemChromeMediumColor,
NamedPlatformColor.SystemChromeMediumLowColor,
NamedPlatformColor.SystemChromeWhiteColor,
NamedPlatformColor.SystemListLowColor,
NamedPlatformColor.SystemListMediumColor,
NamedPlatformColor.SystemAltHighColor
});
}

return resultColors.ToArray();
}
}
}
51 changes: 44 additions & 7 deletions Xamarin.Forms.Core/NamedPlatformColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public static class NamedPlatformColor
{
// iOS
// iOS & macOS
public const string SystemBlue = "systemBlue";
public const string SystemGreen = "systemGreen";
public const string SystemIndigo = "systemIndigo";
Expand All @@ -13,20 +13,57 @@ public static class NamedPlatformColor
public const string SystemTeal = "systemTeal";
public const string SystemYellow = "systemYellow";
public const string SystemGray = "systemGray";
public const string SystemGray2 = "systemGray2";
public const string SystemGray3 = "systemGray3";
public const string SystemGray4 = "systemGray4";
public const string SystemGray5 = "systemGray5";
public const string SystemGray6 = "systemGray6";
public const string Label = "label";
public const string SecondaryLabel = "secondaryLabel";
public const string TertiaryLabel = "tertiaryLabel";
public const string QuaternaryLabel = "quaternaryLabellabel";
public const string PlaceholderText = "placeholderText";
public const string Separator = "separator";
public const string OpaqueSeparator = "opaqueSeparator";
public const string Link = "link";

// iOS Only
public const string SystemGray2 = "systemGray2";
public const string SystemGray3 = "systemGray3";
public const string SystemGray4 = "systemGray4";
public const string SystemGray5 = "systemGray5";
public const string SystemGray6 = "systemGray6";
public const string OpaqueSeparator = "opaqueSeparator";

// macOS Only
public const string AlternateSelectedControlTextColor = "alternateSelectedControlTextColor";
public const string ControlAccent = "controlAccent";
public const string ControlBackgroundColor = "controlBackgroundColor";
public const string ControlColor = "controlColor";
public const string ControlTextColor = "controlTextColor";
public const string DisabledControlTextColor = "disabledControlTextColor";
public const string FindHighlightColor = "findHighlightColor";
public const string GridColor = "gridColor";
public const string HeaderTextColor = "headerTextColor";
public const string HighlightColor = "highlightColor";
public const string KeyboardFocusIndicatorColor = "keyboardFocusIndicatorColor";
public const string LabelColor = "labelColor";
public const string LinkColor = "linkColor";
public const string PlaceholderTextColor = "placeholderTextColor";
public const string QuaternaryLabelColor = "quaternaryLabelColor";
public const string SecondaryLabelColor = "secondaryLabelColor";
public const string SelectedContentBackgroundColor = "selectedContentBackgroundColor";
public const string SelectedControlColor = "selectedControlColor";
public const string SelectedControlTextColor = "selectedControlTextColor";
public const string SelectedMenuItemTextColor = "selectedMenuItemTextColor";
public const string SelectedTextBackgroundColor = "selectedTextBackgroundColor";
public const string SelectedTextColor = "selectedTextColor";
public const string SeparatorColor = "separatorColor";
public const string ShadowColor = "shadowColor";
public const string TertiaryLabelColor = "tertiaryLabelColor";
public const string TextBackgroundColor = " textBackgroundColor";
public const string TextColor = "textColor";
public const string UnderPageBackgroundColor = "underPageBackgroundColor";
public const string UnemphasizedSelectedContentBackgroundColor = "unemphasizedSelectedContentBackgroundColor";
public const string UnemphasizedSelectedTextBackgroundColor = "unemphasizedSelectedTextBackgroundColor";
public const string UnemphasizedSelectedTextColor = "unemphasizedSelectedTextColor";
public const string WindowBackgroundColor = "windowBackgroundColor";
public const string WindowFrameTextColor = "windowFrameTextColor";

// Android
public const string BackgroundDark = "background_dark";
public const string BackgroundLight = "background_light";
Expand Down
Loading

0 comments on commit b995e20

Please sign in to comment.