Skip to content

Commit be64db0

Browse files
CopilotAgustinBonillagithub-actions[bot]pgonzalezmorelli
authored
Add per-item LabelColor and ActiveIndicatorLabelColor support to MaterialNavigationDrawer (#120)
* Trigger workflow 3 (#104) * Add touch event on touchable views * Add touch event samples * Fix touch issue on checkbox * Create main.yml * Use Android Dialog on Snackbar * Add CharacterSpacing and LineBreakMode on iOS * Add FontAttributes * Update todo list * Update main.yml * Update main.yml * Update main.yml * Rename master pipeline name * Add develop pipeline * Set write permissions * Auto-generate docs [skip ci] * Update develop.yml * Change namespace to TouchEventArgs, ITouchableView and TouchEventType * Move LetterSpacingSpan implementation * Change pipelines * Update nuget.props * Auto-generate docs [skip ci] * trigger workflow * Add pull request trigger * Add workflow_dispatch --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Pablo González <pablo.gonzalez@horus.com.uy> * Update README.md * Update README.md * Initial plan * Add LabelColor property to MaterialNavigationDrawerItem and implement feature Co-authored-by: AgustinBonilla <15618896+AgustinBonilla@users.noreply.github.com> * Update icon tint color to consider selected state for consistency Co-authored-by: AgustinBonilla <15618896+AgustinBonilla@users.noreply.github.com> * Add ActiveIndicatorLabelColor property to MaterialNavigationDrawerItem Co-authored-by: AgustinBonilla <15618896+AgustinBonilla@users.noreply.github.com> --------- Co-authored-by: Agustin Bonilla <agustin.bonilla@horus.com.uy> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Pablo González <pablo.gonzalez@horus.com.uy> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: AgustinBonilla <15618896+AgustinBonilla@users.noreply.github.com>
1 parent 2f1ef8e commit be64db0

3 files changed

Lines changed: 54 additions & 7 deletions

File tree

samples/HorusStudio.Maui.MaterialDesignControls.Sample/ViewModels/NavigationDrawerViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ private void LoadItems(bool includeAllItems)
9999
SelectedLeadingIcon = "trash.png",
100100
LeadingIcon = "trash.png",
101101
Text = "Trash",
102+
LabelColor = Colors.Red
102103
},
103104
new()
104105
{

src/HorusStudio.Maui.MaterialDesignControls/Controls/NavigationDrawer/MaterialNavigationDrawer.cs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,15 +1155,25 @@ private void SetLabelTextColorPropertyBindings(MaterialLabel label, MaterialNavi
11551155
new Binding(nameof(item.IsSelected), source: item),
11561156
new Binding(nameof(ActiveIndicatorLabelColor), source: this),
11571157
new Binding(nameof(LabelColor), source: this),
1158-
new Binding(nameof(DisabledLabelColor), source: this)
1158+
new Binding(nameof(DisabledLabelColor), source: this),
1159+
new Binding(nameof(item.LabelColor), source: item),
1160+
new Binding(nameof(item.ActiveIndicatorLabelColor), source: item)
11591161
},
11601162
Converter = new MultiValueConverter((values, targetType, parameter, culture) =>
11611163
{
11621164
var isEnabled = (bool)values[0];
11631165
var isSelected = (bool)values[1];
1164-
var activeIndicatorLabelColor = (Color)values[2];
1165-
var labelColor = (Color)values[3];
1166+
var drawerActiveIndicatorLabelColor = (Color)values[2];
1167+
var drawerLabelColor = (Color)values[3];
11661168
var disabledLabelColor = (Color)values[4];
1169+
var itemLabelColor = values[5] as Color?;
1170+
var itemActiveIndicatorLabelColor = values[6] as Color?;
1171+
1172+
// If item has its own LabelColor, use it instead of drawer's LabelColor
1173+
var labelColor = itemLabelColor ?? drawerLabelColor;
1174+
1175+
// If item has its own ActiveIndicatorLabelColor, use it instead of drawer's ActiveIndicatorLabelColor
1176+
var activeIndicatorLabelColor = itemActiveIndicatorLabelColor ?? drawerActiveIndicatorLabelColor;
11671177

11681178
return isEnabled ? (isSelected ? activeIndicatorLabelColor : labelColor) : disabledLabelColor;
11691179
})
@@ -1177,16 +1187,30 @@ private void SetIconTintColorPropertyBindings(IconTintColorBehavior iconTintColo
11771187
Bindings = new Collection<BindingBase>
11781188
{
11791189
new Binding(nameof(item.IsEnabled), source: item),
1190+
new Binding(nameof(item.IsSelected), source: item),
1191+
new Binding(nameof(ActiveIndicatorLabelColor), source: this),
11801192
new Binding(nameof(LabelColor), source: this),
1181-
new Binding(nameof(DisabledLabelColor), source: this)
1193+
new Binding(nameof(DisabledLabelColor), source: this),
1194+
new Binding(nameof(item.LabelColor), source: item),
1195+
new Binding(nameof(item.ActiveIndicatorLabelColor), source: item)
11821196
},
11831197
Converter = new MultiValueConverter((values, targetType, parameter, culture) =>
11841198
{
11851199
var isEnabled = (bool)values[0];
1186-
var labelColor = (Color)values[1];
1187-
var disabledLabelColor = (Color)values[2];
1200+
var isSelected = (bool)values[1];
1201+
var drawerActiveIndicatorLabelColor = (Color)values[2];
1202+
var drawerLabelColor = (Color)values[3];
1203+
var disabledLabelColor = (Color)values[4];
1204+
var itemLabelColor = values[5] as Color?;
1205+
var itemActiveIndicatorLabelColor = values[6] as Color?;
1206+
1207+
// If item has its own LabelColor, use it instead of drawer's LabelColor
1208+
var labelColor = itemLabelColor ?? drawerLabelColor;
1209+
1210+
// If item has its own ActiveIndicatorLabelColor, use it instead of drawer's ActiveIndicatorLabelColor
1211+
var activeIndicatorLabelColor = itemActiveIndicatorLabelColor ?? drawerActiveIndicatorLabelColor;
11881212

1189-
return isEnabled ? labelColor : disabledLabelColor;
1213+
return isEnabled ? (isSelected ? activeIndicatorLabelColor : labelColor) : disabledLabelColor;
11901214
})
11911215
});
11921216
}

src/HorusStudio.Maui.MaterialDesignControls/Controls/NavigationDrawer/MaterialNavigationDrawerItem.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class MaterialNavigationDrawerItem : INotifyPropertyChanged
2222
private bool _isSelected;
2323
private bool _isEnabled = true;
2424
private string _automationId = null!;
25+
private Color? _labelColor;
26+
private Color? _activeIndicatorLabelColor;
2527

2628
#endregion Attributes
2729

@@ -149,6 +151,26 @@ public string AutomationId
149151
set => SetProperty(ref _automationId, value);
150152
}
151153

154+
/// <summary>
155+
/// Gets or sets the label color for this item. If null, falls back to the MaterialNavigationDrawer's LabelColor.
156+
/// This color is also applied to the leading and trailing icons when ApplyLeadingIconTintColor or ApplyTrailingIconTintColor is true.
157+
/// </summary>
158+
public Color? LabelColor
159+
{
160+
get => _labelColor;
161+
set => SetProperty(ref _labelColor, value);
162+
}
163+
164+
/// <summary>
165+
/// Gets or sets the active indicator label color for this item when selected. If null, falls back to the MaterialNavigationDrawer's ActiveIndicatorLabelColor.
166+
/// This color is also applied to the leading and trailing icons when the item is selected and ApplyLeadingIconTintColor or ApplyTrailingIconTintColor is true.
167+
/// </summary>
168+
public Color? ActiveIndicatorLabelColor
169+
{
170+
get => _activeIndicatorLabelColor;
171+
set => SetProperty(ref _activeIndicatorLabelColor, value);
172+
}
173+
152174
/// <inheritdoc />
153175
public event PropertyChangedEventHandler? PropertyChanged;
154176

0 commit comments

Comments
 (0)