* Pixiview/Pixiview.projitems: * Pixiview/Utils/IllustData.cs: * Pixiview/Utils/HttpUtility.cs: * Pixiview/Utils/IllustLegacy.cs: * Pixiview/Illust/ViewIllustPage.xaml: * Pixiview/Illust/ViewIllustPage.xaml.cs: feature: view animate * Pixiview/Illust/FavoritesPage.xaml.cs: lazy load favorites page * Pixiview/UI/CardView.cs: * Pixiview/UI/AdaptedPage.cs: * Pixiview/Utils/Converters.cs: * Pixiview/UI/StyleDefinition.cs: * Pixiview/UI/Theme/ThemeBase.cs: * Pixiview/Illust/RankingPage.xaml: * Pixiview/Illust/RankingPage.xaml.cs: * Pixiview/Resources/Languages/zh-CN.xml: * Pixiview/Illust/IllustCollectionPage.cs: * Pixiview.iOS/Renderers/SegmentedControlRenderer.cs: feature: filter ranking * Pixiview.iOS/Info.plist: * Pixiview.iOS/Pixiview.iOS.csproj: * Pixiview.iOS.OpenExtension/Info.plist: * Pixiview.Android/Pixiview.Android.csproj: * Pixiview.Android/Properties/AndroidManifest.xml: version update
156 lines
5.0 KiB
C#
156 lines
5.0 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using Pixiview.iOS.Renderers;
|
|
using Pixiview.UI;
|
|
using UIKit;
|
|
using Xamarin.Forms;
|
|
using Xamarin.Forms.Platform.iOS;
|
|
|
|
[assembly: ExportRenderer(typeof(SegmentedControl), typeof(SegmentedControlRenderer))]
|
|
namespace Pixiview.iOS.Renderers
|
|
{
|
|
[SuppressMessage("Code Notifications", "XI0002:Notifies you from using newer Apple APIs when targeting an older OS version", Justification = "<Pending>")]
|
|
public class SegmentedControlRenderer : ViewRenderer<SegmentedControl, UISegmentedControl>
|
|
{
|
|
private UISegmentedControl nativeControl;
|
|
|
|
protected override void OnElementChanged(ElementChangedEventArgs<SegmentedControl> e)
|
|
{
|
|
base.OnElementChanged(e);
|
|
|
|
var element = Element;
|
|
if (Control == null && element != null)
|
|
{
|
|
nativeControl = new UISegmentedControl();
|
|
|
|
for (var i = 0; i < element.Children.Count; i++)
|
|
{
|
|
nativeControl.InsertSegment(element.Children[i].Text, i, false);
|
|
}
|
|
|
|
nativeControl.Enabled = element.IsEnabled;
|
|
nativeControl.BackgroundColor = element.BackgroundColor.ToUIColor();
|
|
nativeControl.SelectedSegmentTintColor = GetTintColor(element);
|
|
SetTextColor();
|
|
nativeControl.SelectedSegment = element.SelectedSegmentIndex;
|
|
|
|
SetNativeControl(nativeControl);
|
|
}
|
|
|
|
if (e.OldElement != null)
|
|
{
|
|
if (nativeControl != null)
|
|
{
|
|
nativeControl.ValueChanged -= NativeControl_ValueChanged;
|
|
}
|
|
}
|
|
|
|
if (e.NewElement != null)
|
|
{
|
|
nativeControl.ValueChanged += NativeControl_ValueChanged;
|
|
}
|
|
}
|
|
|
|
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
|
|
{
|
|
base.OnElementPropertyChanged(sender, e);
|
|
|
|
var element = Element;
|
|
if (nativeControl == null || element == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
switch (e.PropertyName)
|
|
{
|
|
case "Renderer":
|
|
element.SendValueChanged();
|
|
break;
|
|
|
|
case nameof(element.BackgroundColor):
|
|
nativeControl.BackgroundColor = element.BackgroundColor.ToUIColor();
|
|
break;
|
|
|
|
case nameof(element.SelectedSegmentIndex):
|
|
nativeControl.SelectedSegment = element.SelectedSegmentIndex;
|
|
break;
|
|
|
|
case nameof(element.TintColor):
|
|
nativeControl.SelectedSegmentTintColor = GetTintColor(element);
|
|
break;
|
|
|
|
case nameof(element.IsEnabled):
|
|
nativeControl.Enabled = element.IsEnabled;
|
|
nativeControl.SelectedSegmentTintColor = GetTintColor(element);
|
|
break;
|
|
|
|
case nameof(element.SelectedTextColor):
|
|
SetTextColor();
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void SetTextColor()
|
|
{
|
|
var color = Element.SelectedTextColor;
|
|
UIColor c = color == default ? UIColor.LabelColor : color.ToUIColor();
|
|
var attribute = new UITextAttributes
|
|
{
|
|
TextColor = c
|
|
};
|
|
nativeControl.SetTitleTextAttributes(attribute, UIControlState.Selected);
|
|
attribute = new UITextAttributes
|
|
{
|
|
TextColor = c.ColorWithAlpha(.6f)
|
|
};
|
|
nativeControl.SetTitleTextAttributes(attribute, UIControlState.Normal);
|
|
}
|
|
|
|
private UIColor GetTintColor(SegmentedControl element)
|
|
{
|
|
if (element.IsEnabled)
|
|
{
|
|
var tintColor = element.TintColor;
|
|
if (tintColor == default)
|
|
{
|
|
return UIColor.SystemGray6Color;
|
|
}
|
|
else
|
|
{
|
|
return tintColor.ToUIColor().ColorWithAlpha(.3f);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var disabledColor = element.DisabledColor;
|
|
if (disabledColor == default)
|
|
{
|
|
return UIColor.SecondaryLabelColor;
|
|
}
|
|
else
|
|
{
|
|
return disabledColor.ToUIColor();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void NativeControl_ValueChanged(object sender, EventArgs e)
|
|
{
|
|
Element.SelectedSegmentIndex = (int)nativeControl.SelectedSegment;
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (nativeControl != null)
|
|
{
|
|
nativeControl.ValueChanged -= NativeControl_ValueChanged;
|
|
nativeControl.Dispose();
|
|
nativeControl = null;
|
|
}
|
|
|
|
base.Dispose(disposing);
|
|
}
|
|
}
|
|
}
|