When the size of thumb or track changes, the it should update the position of the thumb properly.
And to prevent unnecessary switch state updating while applying style, upgrade styleApplying flag to int type.
Signed-off-by: Jiyun Yang <ji.yang@samsung.com>
private EventHandler<StateChangedEventArgs> stateChangeHandler;
private bool isPressed = false;
- private bool styleApplying = false;
+ internal int styleApplying = 0;
/// <summary>
/// Gets accessibility name.
[EditorBrowsable(EditorBrowsableState.Never)]
protected void UpdateState()
{
- if (styleApplying) return;
+ if (styleApplying > 0) return;
ControlState sourceState = ControlState;
ControlState targetState;
{
Debug.Assert(buttonIcon != null && buttonText != null);
- styleApplying = true;
+ styleApplying++;
base.ApplyStyle(viewStyle);
}
}
- styleApplying = false;
+ styleApplying--;
+
UpdateState();
}
}
}
+ /// <inheritdoc/>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override ImageView OnCreateTrack(Switch switchButton, ImageView track)
+ {
+ base.OnCreateTrack(switchButton, track);
+ track.Relayout += (s, e) => {
+ switchButton.Thumb.PositionX = switchButton.IsSelected ? switchButton.Track.Size.Width - switchButton.Thumb.Size.Width : 0;
+ };
+ return track;
+ }
+
+ /// <inheritdoc/>
+ public override ImageView OnCreateThumb(Switch switchButton, ImageView thumb)
+ {
+ base.OnCreateThumb(switchButton, thumb);
+ thumb.Relayout += (s, e) => {
+ thumb.PositionX = switchButton.IsSelected ? switchButton.Track.Size.Width - thumb.Size.Width : 0;
+ };
+ return thumb;
+ }
[EditorBrowsable(EditorBrowsableState.Never)]
protected virtual void Dispose(bool disposing)
[EditorBrowsable(EditorBrowsableState.Never)]
public override void ApplyStyle(ViewStyle viewStyle)
{
+ styleApplying++;
+
+ base.ApplyStyle(viewStyle);
+
if (viewStyle is SwitchStyle switchStyle)
{
if (Extension is SwitchExtension extension)
Thumb.ApplyStyle(switchStyle.Thumb);
}
}
+ styleApplying--;
- base.ApplyStyle(viewStyle);
+ UpdateState();
}
/// <summary>