Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 0 additions & 7 deletions maui/src/SegmentedControl/Interface/ISegmentInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,6 @@ internal interface ISegmentItemInfo : ISegmentInfo
/// </summary>
void ClearFocusedView();

#if WINDOWS
/// <summary>
/// Update the keyboard focused view for the segmentedControl.
/// </summary>
void SetFocusVisualState(bool state);
#endif

/// <summary>
/// Updates the scroll view position to focused index for the segment item.
/// </summary>
Expand Down
12 changes: 2 additions & 10 deletions maui/src/SegmentedControl/SfSegmentedControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public SfSegmentedControl()
MinimumHeightRequest = 40;
SelectionIndicatorSettings.Parent = this;
TextStyle.Parent = this;
#if !WINDOWS
this.AddKeyboardListener(this);
#endif
}

#endregion
Expand Down Expand Up @@ -1189,16 +1191,6 @@ void ISegmentItemInfo.ClearFocusedView()
_keyNavigationView?.ClearFocusedView();
}

#if WINDOWS
void ISegmentItemInfo.SetFocusVisualState(bool state)
{
if (this.Handler != null && this.Handler.PlatformView != null && this.Handler.PlatformView is Microsoft.UI.Xaml.UIElement nativeView)
{
nativeView.UseSystemFocusVisuals = state;
}
}
#endif

/// <summary>
/// Updates the scroll view position to focused index for the segment item.
/// </summary>
Expand Down
85 changes: 83 additions & 2 deletions maui/src/SegmentedControl/Views/SegmentItemView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Syncfusion.Maui.Toolkit.SegmentedControl
/// <summary>
/// Represents a view used to display an individual segment item within a segmented control.
/// </summary>
internal partial class SegmentItemView : SfContentView, ITouchListener, ITapGestureListener
internal partial class SegmentItemView : SfContentView, ITouchListener, ITapGestureListener, IKeyboardListener
{
#region Fields

Expand Down Expand Up @@ -70,10 +70,15 @@ internal SegmentItemView(ISegmentItemInfo itemInfo, SfSegmentItem item)
InitializeEffectsView();
this.AddTouchListener(this);
this.AddGestureListener(this);
#if WINDOWS
this.AddKeyboardListener(this);
#endif
if (itemInfo?.SegmentTemplate != null)
{
CreateSegmentItemTemplateView();
}

UpdateSemantics();
}

#endregion
Expand Down Expand Up @@ -107,6 +112,7 @@ internal void UpdateSelection()
_isSelected = true;
_selectionView?.UpdateVisualState(true);
InvalidateDrawable();
UpdateSemantics();
}

/// <summary>
Expand All @@ -123,6 +129,7 @@ internal void ClearSelection()
_isSelected = false;
_selectionView.UpdateVisualState(_isSelected, false);
InvalidateDrawable();
UpdateSemantics();
}

/// <summary>
Expand Down Expand Up @@ -420,6 +427,9 @@ void InitializeImageView()
#endif
};

#if WINDOWS
AutomationProperties.SetIsInAccessibleTree(_imageView, false);
#endif
Children.Add(_imageView);
}

Expand All @@ -435,6 +445,9 @@ void InitializeSelectionView()
}

_selectionView = new SelectionView(_segmentItem, itemInfo);
#if WINDOWS
AutomationProperties.SetIsInAccessibleTree(_selectionView, false);
#endif
Children.Add(_selectionView);
}

Expand All @@ -453,6 +466,9 @@ void InitializeEffectsView()
_effectsView.ShouldIgnoreTouches = true;
_effectsView.AnimationCompleted += OnEffectsViewAnimationCompleted;
_effectsView.ClipToBounds = true;
#if WINDOWS
AutomationProperties.SetIsInAccessibleTree(_effectsView, false);
#endif
Children.Add(_effectsView);
}

Expand Down Expand Up @@ -597,6 +613,28 @@ void RemoveEffects()
_effectsView.Reset();
}

/// <summary>
/// Method to update the semantic properties.
/// </summary>
void UpdateSemantics()
{
if (_segmentItem != null)
{
if (!string.IsNullOrEmpty(SemanticProperties.GetDescription(_segmentItem)))
{
SemanticProperties.SetDescription(this, SemanticProperties.GetDescription(_segmentItem));
}
else if (!_segmentItem.IsEnabled || (itemInfo != null && !itemInfo.IsEnabled))
{
SemanticProperties.SetDescription(this, _segmentItem.Text + SfSegmentedResources.GetLocalizedString("Disabled"));
}
else
{
SemanticProperties.SetDescription(this, _isSelected ? _segmentItem.Text + SfSegmentedResources.GetLocalizedString("Selected") : _segmentItem.Text);
}
}
}

/// <summary>
/// Method to remove the selection view handlers.
/// </summary>
Expand Down Expand Up @@ -746,7 +784,11 @@ protected override void OnDraw(ICanvas canvas, RectF dirtyRect)
semanticsNode.OnClick = OnSemanticsNodeClick;
}
string text = _segmentItem.Text;
if (!_segmentItem.IsEnabled || (itemInfo != null && !itemInfo.IsEnabled))
if (!string.IsNullOrEmpty(SemanticProperties.GetDescription(_segmentItem)))
{
semanticsNode.Text = SemanticProperties.GetDescription(_segmentItem);
}
else if (!_segmentItem.IsEnabled || (itemInfo != null && !itemInfo.IsEnabled))
{
semanticsNode.Text = text + SfSegmentedResources.GetLocalizedString("Disabled");
}
Expand All @@ -758,6 +800,21 @@ protected override void OnDraw(ICanvas canvas, RectF dirtyRect)
return [semanticsNode];
}

#if WINDOWS
/// <summary>
/// Raises when <see cref="SegmentItemView"/>'s handler gets changed.
/// <exclude/>
/// </summary>
protected override void OnHandlerChanged()
{
base.OnHandlerChanged();
if (this.Handler != null && this.Handler.PlatformView != null && this.Handler.PlatformView is Microsoft.UI.Xaml.UIElement nativeView)
{
nativeView.IsTabStop = true;
}
}
#endif

/// <summary>
/// Measures the size of the view's content based on the specified constraints.
/// </summary>
Expand Down Expand Up @@ -875,6 +932,30 @@ void ITapGestureListener.OnTap(Syncfusion.Maui.Toolkit.Internals.TapEventArgs e)
#endif
}

/// <summary>
/// Gets a value indicating whether the view can become the first responder to listen the keyboard actions.
/// </summary>
/// <remarks>This property will be considered only in iOS Platform.</remarks>
bool IKeyboardListener.CanBecomeFirstResponder
{
get { return true; }
}

/// <inheritdoc/>
void IKeyboardListener.OnKeyDown(KeyEventArgs e)
{
if (e.Key == KeyboardKey.Enter)
{
UpdateSelectedIndex();
}
}

/// <inheritdoc/>
void IKeyboardListener.OnKeyUp(KeyEventArgs args)
{

}

#endregion
}
}
42 changes: 0 additions & 42 deletions maui/src/SegmentedControl/Views/SegmentLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ namespace Syncfusion.Maui.Toolkit.SegmentedControl
/// <summary>
/// Represents a layout for arranging and displaying a collection of segment items.
/// </summary>
#if WINDOWS
internal partial class SegmentLayout : SfView, IKeyboardListener
#else
internal class SegmentLayout : SfView
#endif
{
#region Fields

Expand Down Expand Up @@ -50,9 +46,6 @@ internal SegmentLayout(ISegmentItemInfo itemInfo)
_itemInfo = itemInfo;
DrawingOrder = DrawingOrder.AboveContent;
InitializeSegmentItemsView();
#if WINDOWS
this.AddKeyboardListener(this);
#endif
}

#endregion
Expand Down Expand Up @@ -196,21 +189,11 @@ internal void ProcessOnKeyDown(KeyEventArgs e)
_focusedIndex = -1;
}

#if WINDOWS
if (e.Key == KeyboardKey.Left || e.Key == KeyboardKey.Right)
{
_itemInfo?.SetFocusVisualState(false);
}
#endif

if (e.Key == KeyboardKey.Tab || (e.Key == KeyboardKey.Tab && e.IsShiftKeyPressed) || e.Key == KeyboardKey.Down || e.Key == KeyboardKey.Up)
{
e.Handled = false;
_focusedIndex = -1;
_itemInfo?.ClearFocusedView();
#if WINDOWS
_itemInfo?.SetFocusVisualState(true);
#endif
return;
}

Expand Down Expand Up @@ -849,30 +832,5 @@ protected override Size ArrangeContent(Rect bounds)
}

#endregion

#region Interface implementation
#if WINDOWS
/// <summary>
/// Gets a value indicating whether the view can become the first responder to listen the keyboard actions.
/// </summary>
/// <remarks>This property will be considered only in iOS Platform.</remarks>
bool IKeyboardListener.CanBecomeFirstResponder
{
get { return true; }
}

/// <inheritdoc/>
void IKeyboardListener.OnKeyDown(KeyEventArgs e)
{
ProcessOnKeyDown(e);
}

/// <inheritdoc/>
void IKeyboardListener.OnKeyUp(KeyEventArgs e)
{

}
#endif
#endregion
}
}