rename from Pixiview to Gallery

This commit is contained in:
2021-08-03 19:16:54 +08:00
parent 98676ce8b2
commit c41282a4b7
206 changed files with 7900 additions and 7891 deletions

View File

@ -1,107 +0,0 @@
using Foundation;
using Pixiview.iOS.Renderers;
using Pixiview.UI;
using Pixiview.Utils;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(AdaptedPage), typeof(AdaptedPageRenderer))]
namespace Pixiview.iOS.Renderers
{
public class AdaptedPageRenderer : PageRenderer
{
UIDeviceOrientation lastOrientation;
NSObject observer;
public override void ViewDidLoad()
{
base.ViewDidLoad();
if (Element is AdaptedPage page)
{
//var mode = ForPage.GetLargeTitleDisplay(page);
//NavigationItem.LargeTitleDisplayMode = UINavigationItemLargeTitleDisplayMode.Automatic;
//lastOrientation = UIDevice.CurrentDevice.Orientation;
//var landscape =
// lastOrientation == UIDeviceOrientation.LandscapeLeft ||
// lastOrientation == UIDeviceOrientation.LandscapeRight;
//page.OnOrientationChanged(landscape);
page.OnLoad();
}
}
protected override void Dispose(bool disposing)
{
if (Element is AdaptedPage page)
{
page.OnUnload();
}
base.Dispose(disposing);
}
public override void ViewDidAppear(bool animated)
{
base.ViewDidAppear(animated);
var element = Element;
if (element != null)
{
var style = EnvironmentService.ConvertStyle(Screen.GetStatusBarStyle(element));
EnvironmentService.SetStatusBarStyle(style);
}
observer = UIDevice.Notifications.ObserveOrientationDidChange(ChangeOrientation);
ChangeOrientation(null, null);
}
public override void ViewWillDisappear(bool animated)
{
if (observer != null)
{
observer.Dispose();
observer = null;
}
base.ViewWillDisappear(animated);
}
void ChangeOrientation(object sender, NSNotificationEventArgs e)
{
var current = UIDevice.CurrentDevice.Orientation;
if (current == UIDeviceOrientation.FaceUp || current == UIDeviceOrientation.FaceDown)
{
//current = UIDeviceOrientation.Portrait;
return;
}
if (lastOrientation != current)
{
lastOrientation = current;
if (current == UIDeviceOrientation.Portrait && UIApplication.SharedApplication.StatusBarHidden)
{
var style = EnvironmentService.ConvertStyle(Screen.GetStatusBarStyle(Element));
if (style != UIStatusBarStyle.BlackOpaque)
{
UIApplication.SharedApplication.SetStatusBarHidden(false, true);
}
}
if (Element is AdaptedPage page)
{
AppShell.Current?.SetStatusBarHeight(
NavigationController?.NavigationBar.Frame.Height ?? 0,
UIApplication.SharedApplication.StatusBarFrame.Height);
var landscape =
lastOrientation == UIDeviceOrientation.LandscapeLeft ||
lastOrientation == UIDeviceOrientation.LandscapeRight;
if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
{
landscape |= lastOrientation == UIDeviceOrientation.PortraitUpsideDown;
}
page.OnOrientationChanged(landscape);
}
}
}
}
}

View File

@ -1,93 +0,0 @@
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Pixiview.iOS.Renderers;
using Pixiview.iOS.Renderers.AppShellSection;
using Pixiview.Utils;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(Shell), typeof(AppShellRenderer))]
namespace Pixiview.iOS.Renderers
{
public class AppShellRenderer : ShellRenderer
{
public override bool PrefersHomeIndicatorAutoHidden => Screen.GetHomeIndicatorAutoHidden(Element);
protected override IShellSectionRenderer CreateShellSectionRenderer(ShellSection shellSection)
{
var renderer = base.CreateShellSectionRenderer(shellSection); // new AppShellSectionRenderer(this);
if (renderer is ShellSectionRenderer sr && Element is AppShell shell)
{
shell.SetNavigationBarHeight(sr.NavigationBar.Frame.Height);
shell.SetStatusBarHeight(
sr.NavigationBar.Frame.Height,
UIApplication.SharedApplication.StatusBarFrame.Height);
}
return renderer;
}
protected override IShellItemTransition CreateShellItemTransition()
{
return new AppShellItemTransition();
}
protected override IShellTabBarAppearanceTracker CreateTabBarAppearanceTracker()
{
return new AppShellTabBarAppearanceTracker();
}
protected override IShellNavBarAppearanceTracker CreateNavBarAppearanceTracker()
{
return new AppShellNavBarAppearanceTracker();
}
protected override void UpdateBackgroundColor()
{
NativeView.BackgroundColor = Color.Transparent.ToUIColor();
}
}
public class AppShellItemTransition : IShellItemTransition
{
[SuppressMessage("Code Notifications", "XI0001:Notifies you with advices on how to use Apple APIs", Justification = "<Pending>")]
public Task Transition(IShellItemRenderer oldRenderer, IShellItemRenderer newRenderer)
{
var task = new TaskCompletionSource<bool>();
var oldView = oldRenderer.ViewController.View;
var newView = newRenderer.ViewController.View;
newView.Alpha = 0;
newView.Superview.InsertSubviewAbove(newView, oldView);
UIView.Animate(0.2, 0, UIViewAnimationOptions.BeginFromCurrentState, () => newView.Alpha = 1, () => task.TrySetResult(true));
return task.Task;
}
}
public class AppShellSectionRenderer : ShellSectionRenderer
{
public AppShellSectionRenderer(IShellContext context) : base(context)
{
}
protected override IShellSectionRootRenderer CreateShellSectionRootRenderer(ShellSection shellSection, IShellContext shellContext)
{
return new AppShellSectionRootRenderer(shellSection, shellContext);
}
}
public class AppShellSectionRootRenderer : ShellSectionRootRenderer
{
public AppShellSectionRootRenderer(ShellSection shellSection, IShellContext shellContext) : base(shellSection, shellContext)
{
}
protected override IShellSectionRootHeader CreateShellSectionRootHeader(IShellContext shellContext)
{
return new AppShellSectionRootHeader(shellContext);
}
}
}

View File

@ -1,171 +0,0 @@
using System.Diagnostics.CodeAnalysis;
using CoreGraphics;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
namespace Pixiview.iOS.Renderers.AppShellSection
{
public class AppShellNavBarAppearanceTracker : IShellNavBarAppearanceTracker
{
UIColor _defaultBarTint;
UIColor _defaultTint;
UIStringAttributes _defaultTitleAttributes;
float _shadowOpacity = float.MinValue;
CGColor _shadowColor;
public void ResetAppearance(UINavigationController controller)
{
if (_defaultTint != null)
{
var navBar = controller.NavigationBar;
navBar.TintColor = _defaultBarTint;
navBar.TintColor = _defaultTint;
navBar.TitleTextAttributes = _defaultTitleAttributes;
}
}
public void SetAppearance(UINavigationController controller, ShellAppearance appearance)
{
var background = appearance.BackgroundColor;
var foreground = appearance.ForegroundColor;
var titleColor = appearance.TitleColor;
var navBar = controller.NavigationBar;
if (_defaultTint == null)
{
_defaultBarTint = navBar.BarTintColor;
_defaultTint = navBar.TintColor;
_defaultTitleAttributes = navBar.TitleTextAttributes;
}
if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
{
navBar.TintColor = UIColor.SecondaryLabelColor;
}
else
{
if (!background.IsDefault)
navBar.BarTintColor = background.ToUIColor();
if (!foreground.IsDefault)
navBar.TintColor = foreground.ToUIColor();
if (!titleColor.IsDefault)
{
navBar.TitleTextAttributes = new UIStringAttributes
{
ForegroundColor = titleColor.ToUIColor()
};
}
}
}
public void SetHasShadow(UINavigationController controller, bool hasShadow)
{
var navigationBar = controller.NavigationBar;
if (_shadowOpacity == float.MinValue)
{
// Don't do anything if user hasn't changed the shadow to true
if (!hasShadow)
return;
_shadowOpacity = navigationBar.Layer.ShadowOpacity;
_shadowColor = navigationBar.Layer.ShadowColor;
}
if (hasShadow)
{
navigationBar.Layer.ShadowColor = UIColor.Black.CGColor;
navigationBar.Layer.ShadowOpacity = 1.0f;
}
else
{
navigationBar.Layer.ShadowColor = _shadowColor;
navigationBar.Layer.ShadowOpacity = _shadowOpacity;
}
}
public void Dispose()
{
}
public void UpdateLayout(UINavigationController controller)
{
}
}
public class AppShellTabBarAppearanceTracker : IShellTabBarAppearanceTracker
{
UIColor _defaultBarTint;
UIColor _defaultTint;
UIColor _defaultUnselectedTint;
public void ResetAppearance(UITabBarController controller)
{
if (_defaultTint == null)
return;
var tabBar = controller.TabBar;
tabBar.BarTintColor = _defaultBarTint;
tabBar.TintColor = _defaultTint;
tabBar.UnselectedItemTintColor = _defaultUnselectedTint;
}
public void SetAppearance(UITabBarController controller, ShellAppearance appearance)
{
IShellAppearanceElement appearanceElement = appearance;
var backgroundColor = appearanceElement.EffectiveTabBarBackgroundColor;
var unselectedColor = appearanceElement.EffectiveTabBarUnselectedColor;
var tintColor = appearanceElement.EffectiveTabBarForegroundColor; // appearanceElement.EffectiveTabBarTitleColor;
var tabBar = controller.TabBar;
if (_defaultTint == null)
{
_defaultBarTint = tabBar.BarTintColor;
_defaultTint = tabBar.TintColor;
_defaultUnselectedTint = tabBar.UnselectedItemTintColor;
}
if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
{
tabBar.TintColor = UIColor.LabelColor;
//tabBar.UnselectedItemTintColor = UIColor.TertiaryLabelColor;
}
else
{
if (!backgroundColor.IsDefault)
tabBar.BarTintColor = backgroundColor.ToUIColor();
if (!tintColor.IsDefault)
tabBar.TintColor = tintColor.ToUIColor();
if (!unselectedColor.IsDefault)
tabBar.UnselectedItemTintColor = unselectedColor.ToUIColor();
}
}
public void Dispose()
{
}
[SuppressMessage("Code Notifications", "XI0001:Notifies you with advices on how to use Apple APIs", Justification = "<Pending>")]
public void UpdateLayout(UITabBarController controller)
{
var tabBar = controller.TabBar;
if (tabBar != null && tabBar.Items != null && tabBar.Items.Length == 4)
{
var tabUser = tabBar.Items[0];
tabUser.Image = UIImage.FromBundle("IconUserRegular");
tabUser.SelectedImage = UIImage.FromBundle("IconUser");
var tabRecommend = tabBar.Items[1];
tabRecommend.Image = UIImage.FromBundle("IconSparklesRegular");
tabRecommend.SelectedImage = UIImage.FromBundle("IconSparkles");
var tabRank = tabBar.Items[2];
tabRank.Image = UIImage.FromBundle("IconSortRegular");
tabRank.SelectedImage = UIImage.FromBundle("IconSort");
var tabFavorite = tabBar.Items[3];
tabFavorite.Image = UIImage.FromBundle("IconBookmarkRegular");
tabFavorite.SelectedImage = UIImage.FromBundle("IconBookmark");
}
}
}
}

View File

@ -1,325 +0,0 @@
using System;
using System.Collections.Specialized;
using System.ComponentModel;
using CoreGraphics;
using Foundation;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
namespace Pixiview.iOS.Renderers.AppShellSection
{
public class AppShellSectionRootHeader : UICollectionViewController, IAppearanceObserver, IShellSectionRootHeader
{
#region IAppearanceObserver
readonly Color _defaultBackgroundColor = new Color(0.964);
readonly Color _defaultForegroundColor = Color.Black;
readonly Color _defaultUnselectedColor = Color.Black.MultiplyAlpha(0.7);
void IAppearanceObserver.OnAppearanceChanged(ShellAppearance appearance)
{
if (appearance == null)
ResetAppearance();
else
SetAppearance(appearance);
}
protected virtual void ResetAppearance()
{
SetValues(_defaultBackgroundColor, _defaultForegroundColor, _defaultUnselectedColor);
}
protected virtual void SetAppearance(ShellAppearance appearance)
{
SetValues(appearance.BackgroundColor.IsDefault ? _defaultBackgroundColor : appearance.BackgroundColor,
appearance.ForegroundColor.IsDefault ? _defaultForegroundColor : appearance.ForegroundColor,
appearance.UnselectedColor.IsDefault ? _defaultUnselectedColor : appearance.UnselectedColor);
}
void SetValues(Color backgroundColor, Color foregroundColor, Color unselectedColor)
{
CollectionView.BackgroundColor = new Color(backgroundColor.R, backgroundColor.G, backgroundColor.B, .663).ToUIColor();
_bar.BackgroundColor = foregroundColor.ToUIColor();
bool reloadData = _selectedColor != foregroundColor || _unselectedColor != unselectedColor;
_selectedColor = foregroundColor;
_unselectedColor = unselectedColor;
if (reloadData)
CollectionView.ReloadData();
}
#endregion IAppearanceObserver
static readonly NSString CellId = new NSString("HeaderCell");
readonly IShellContext _shellContext;
UIView _bar;
UIView _bottomShadow;
Color _selectedColor;
Color _unselectedColor;
bool _isDisposed;
public AppShellSectionRootHeader(IShellContext shellContext) : base(new UICollectionViewFlowLayout())
{
_shellContext = shellContext;
}
public double SelectedIndex { get; set; }
public ShellSection ShellSection { get; set; }
IShellSectionController ShellSectionController => ShellSection;
public UIViewController ViewController => this;
public override bool CanMoveItem(UICollectionView collectionView, NSIndexPath indexPath)
{
return false;
}
public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
{
var reusedCell = (UICollectionViewCell)collectionView.DequeueReusableCell(CellId, indexPath);
if (!(reusedCell is ShellSectionHeaderCell headerCell))
return reusedCell;
var selectedItems = collectionView.GetIndexPathsForSelectedItems();
var shellContent = ShellSectionController.GetItems()[indexPath.Row];
headerCell.Label.Text = shellContent.Title;
headerCell.Label.SetNeedsDisplay();
headerCell.SelectedColor = _selectedColor.ToUIColor();
headerCell.UnSelectedColor = _unselectedColor.ToUIColor();
if (selectedItems.Length > 0 && selectedItems[0].Row == indexPath.Row)
headerCell.Selected = true;
else
headerCell.Selected = false;
return headerCell;
}
public override nint GetItemsCount(UICollectionView collectionView, nint section)
{
return ShellSectionController.GetItems().Count;
}
public override void ItemDeselected(UICollectionView collectionView, NSIndexPath indexPath)
{
if (CollectionView.CellForItem(indexPath) is ShellSectionHeaderCell cell)
cell.Label.TextColor = _unselectedColor.ToUIColor();
}
public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath)
{
var row = indexPath.Row;
var item = ShellSectionController.GetItems()[row];
if (item != ShellSection.CurrentItem)
ShellSection.SetValueFromRenderer(ShellSection.CurrentItemProperty, item);
if (CollectionView.CellForItem(indexPath) is ShellSectionHeaderCell cell)
cell.Label.TextColor = _selectedColor.ToUIColor();
}
public override nint NumberOfSections(UICollectionView collectionView)
{
return 1;
}
public override bool ShouldSelectItem(UICollectionView collectionView, NSIndexPath indexPath)
{
var row = indexPath.Row;
var item = ShellSectionController.GetItems()[row];
IShellController shellController = _shellContext.Shell;
if (item == ShellSection.CurrentItem)
return true;
return shellController.ProposeNavigation(ShellNavigationSource.ShellContentChanged, (ShellItem)ShellSection.Parent, ShellSection, item, ShellSection.Stack, true);
}
public override void ViewDidLayoutSubviews()
{
if (_isDisposed)
return;
base.ViewDidLayoutSubviews();
LayoutBar();
_bottomShadow.Frame = new CGRect(0, CollectionView.Frame.Bottom, CollectionView.Frame.Width, 0.5);
}
public override void ViewDidLoad()
{
if (_isDisposed)
return;
base.ViewDidLoad();
CollectionView.ScrollsToTop = false;
CollectionView.Bounces = false;
CollectionView.AlwaysBounceHorizontal = false;
CollectionView.ShowsHorizontalScrollIndicator = false;
CollectionView.ClipsToBounds = false;
_bar = new UIView(new CGRect(0, 0, 20, 20));
_bar.Layer.ZPosition = 9001; //its over 9000!
CollectionView.AddSubview(_bar);
_bottomShadow = new UIView(new CGRect(0, 0, 10, 1))
{
BackgroundColor = Color.Black.MultiplyAlpha(0.3).ToUIColor()
};
_bottomShadow.Layer.ZPosition = 9002;
CollectionView.AddSubview(_bottomShadow);
var flowLayout = Layout as UICollectionViewFlowLayout;
flowLayout.ScrollDirection = UICollectionViewScrollDirection.Horizontal;
flowLayout.MinimumInteritemSpacing = 0;
flowLayout.MinimumLineSpacing = 0;
flowLayout.EstimatedItemSize = new CGSize(70, 35);
CollectionView.RegisterClassForCell(GetCellType(), CellId);
((IShellController)_shellContext.Shell).AddAppearanceObserver(this, ShellSection);
ShellSectionController.ItemsCollectionChanged += OnShellSectionItemsChanged;
UpdateSelectedIndex();
ShellSection.PropertyChanged += OnShellSectionPropertyChanged;
}
protected virtual Type GetCellType()
{
return typeof(ShellSectionHeaderCell);
}
protected override void Dispose(bool disposing)
{
if (_isDisposed)
return;
if (disposing)
{
((IShellController)_shellContext.Shell).RemoveAppearanceObserver(this);
ShellSectionController.ItemsCollectionChanged -= OnShellSectionItemsChanged;
ShellSection.PropertyChanged -= OnShellSectionPropertyChanged;
ShellSection = null;
_bar.RemoveFromSuperview();
RemoveFromParentViewController();
_bar.Dispose();
_bar = null;
}
_isDisposed = true;
base.Dispose(disposing);
}
protected void LayoutBar()
{
if (SelectedIndex < 0)
return;
if (ShellSectionController.GetItems().IndexOf(ShellSection.CurrentItem) != SelectedIndex)
return;
var layout = CollectionView.GetLayoutAttributesForItem(NSIndexPath.FromItemSection((int)SelectedIndex, 0));
if (layout == null)
return;
var frame = layout.Frame;
if (_bar.Frame.Height != 2)
{
_bar.Frame = new CGRect(frame.X, frame.Bottom - 2, frame.Width, 2);
}
else
{
UIView.Animate(.25, () => _bar.Frame = new CGRect(frame.X, frame.Bottom - 2, frame.Width, 2));
}
}
protected virtual void OnShellSectionPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == ShellSection.CurrentItemProperty.PropertyName)
{
UpdateSelectedIndex();
}
}
protected virtual void UpdateSelectedIndex(bool animated = false)
{
if (ShellSection.CurrentItem == null)
return;
SelectedIndex = ShellSectionController.GetItems().IndexOf(ShellSection.CurrentItem);
if (SelectedIndex < 0)
return;
LayoutBar();
CollectionView.SelectItem(NSIndexPath.FromItemSection((int)SelectedIndex, 0), false, UICollectionViewScrollPosition.CenteredHorizontally);
}
void OnShellSectionItemsChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (_isDisposed)
return;
CollectionView.ReloadData();
}
public class ShellSectionHeaderCell : UICollectionViewCell
{
public UIColor SelectedColor { get; set; }
public UIColor UnSelectedColor { get; set; }
public ShellSectionHeaderCell()
{
}
[Export("initWithFrame:")]
public ShellSectionHeaderCell(CGRect frame) : base(frame)
{
Label = new UILabel
{
TextAlignment = UITextAlignment.Center,
Font = UIFont.BoldSystemFontOfSize(14)
};
ContentView.AddSubview(Label);
}
public override bool Selected
{
get => base.Selected;
set
{
base.Selected = value;
Label.TextColor = value ? SelectedColor : UnSelectedColor;
}
}
public UILabel Label { get; }
public override void LayoutSubviews()
{
base.LayoutSubviews();
Label.Frame = Bounds;
}
public override CGSize SizeThatFits(CGSize size)
{
return new CGSize(Label.SizeThatFits(size).Width + 30, 35);
}
}
}
}

View File

@ -1,87 +0,0 @@
using CoreAnimation;
using Pixiview.iOS.Renderers;
using Pixiview.UI;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(BlurryPanel), typeof(BlurryPanelRenderer))]
namespace Pixiview.iOS.Renderers
{
public class BlurryPanelRenderer : ViewRenderer<BlurryPanel, UIVisualEffectView>
{
private UIVisualEffectView nativeControl;
private CALayer bottom;
protected override void OnElementChanged(ElementChangedEventArgs<BlurryPanel> e)
{
base.OnElementChanged(e);
if (e.OldElement != null)
{
if (bottom != null)
{
if (bottom.SuperLayer != null)
{
bottom.RemoveFromSuperLayer();
}
bottom.Dispose();
bottom = null;
}
}
if (e.NewElement != null)
{
e.NewElement.BackgroundColor = Color.Default;
if (Control == null)
{
var blur = UIBlurEffect.FromStyle(UIBlurEffectStyle.SystemMaterial);
nativeControl = new UIVisualEffectView(blur)
{
Frame = Frame
};
SetNativeControl(nativeControl);
}
}
}
public override void LayoutSubviews()
{
base.LayoutSubviews();
if (nativeControl != null)
{
if (bottom == null)
{
bottom = new CALayer
{
BackgroundColor = UIColor.White.CGColor,
ShadowColor = UIColor.Black.CGColor,
ShadowOpacity = 1.0f
};
}
if (bottom.SuperLayer == null)
{
nativeControl.Layer.InsertSublayer(bottom, 0);
}
bottom.Frame = new CoreGraphics.CGRect(0, Frame.Height - 5, Frame.Width, 5);
nativeControl.Frame = Frame;
}
}
protected override void Dispose(bool disposing)
{
if (bottom != null)
{
if (bottom.SuperLayer != null)
{
bottom.RemoveFromSuperLayer();
}
bottom.Dispose();
bottom = null;
}
base.Dispose(disposing);
}
}
}

View File

@ -1,51 +0,0 @@
using Pixiview.iOS.Renderers;
using Pixiview.UI;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(CardView), typeof(CardViewRenderer))]
namespace Pixiview.iOS.Renderers
{
public class CardViewRenderer : VisualElementRenderer<CardView>
{
protected override void OnElementChanged(ElementChangedEventArgs<CardView> e)
{
base.OnElementChanged(e);
var layer = Layer;
var element = e.NewElement;
if (layer != null && element != null)
{
var cornerRadius = element.CornerRadius;
if (cornerRadius > 0)
{
layer.CornerRadius = cornerRadius;
}
//if (element.BackgroundColor != default)
//{
// layer.BackgroundColor = element.BackgroundColor.ToCGColor();
//}
var shadowColor = element.ShadowColor;
if (shadowColor != default)
{
layer.ShadowColor = shadowColor.ToCGColor();
layer.ShadowOpacity = 1f;
var radius = element.ShadowRadius;
if (radius > 0)
{
layer.ShadowRadius = radius;
}
layer.ShadowOffset = element.ShadowOffset.ToSizeF();
}
else
{
layer.ShadowOpacity = 0f;
}
}
}
}
}

View File

@ -1,33 +0,0 @@
using Pixiview.iOS.Renderers;
using Pixiview.UI;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(CircleImage), typeof(CircleImageRenderer))]
namespace Pixiview.iOS.Renderers
{
public class CircleImageRenderer : ImageRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Image> e)
{
base.OnElementChanged(e);
var layer = Layer;
if (layer != null)
{
layer.MasksToBounds = true;
}
}
public override void LayoutSubviews()
{
base.LayoutSubviews();
var control = Control;
if (control != null)
{
control.Layer.CornerRadius = control.Frame.Size.Width / 2;
}
}
}
}

View File

@ -1,80 +0,0 @@
using System;
using Foundation;
using Pixiview.iOS.Renderers;
using Pixiview.Login;
using Pixiview.Utils;
using WebKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(HybridWebView), typeof(HybridWebViewRenderer))]
namespace Pixiview.iOS.Renderers
{
public class HybridWebViewRenderer : WkWebViewRenderer
{
public HybridWebViewRenderer() : this(new WKWebViewConfiguration())
{
}
public HybridWebViewRenderer(WKWebViewConfiguration config) : base(config)
{
}
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (e.NewElement is HybridWebView webView)
{
string url = webView.Uri;
//Configuration.SetUrlSchemeHandler
CustomUserAgent = webView.UserAgent;
NavigationDelegate = new PixivNavigationDelegate(webView);
LoadRequest(new NSUrlRequest(NSUrl.FromString(url)));
}
}
private class PixivNavigationDelegate : WKNavigationDelegate
{
private readonly HybridWebView hybridWebView;
public PixivNavigationDelegate(HybridWebView hybrid)
{
hybridWebView = hybrid;
}
public override void DecidePolicy(WKWebView webView, WKNavigationResponse navigationResponse, Action<WKNavigationResponsePolicy> decisionHandler)
{
var url = webView.Url;
if (url.Host == "www.pixiv.net" && url.Path == "/")
{
if (navigationResponse.Response is NSHttpUrlResponse response)
{
if (response.AllHeaderFields.TryGetValue(new NSString("x-userid"), out var val))
{
Configs.SetUserId(val.ToString(), true);
}
}
}
decisionHandler(WKNavigationResponsePolicy.Allow);
}
public override async void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
{
var url = webView.Url;
if (url.Host == "www.pixiv.net" && (url.Path == "/" || url.Path == "/en/"))
{
var store = webView.Configuration.WebsiteDataStore.HttpCookieStore;
var result = await Configs.RequestCookieContainer(store);
if (result && hybridWebView != null)
{
hybridWebView.OnLoginHandle();
}
}
}
}
}
}

View File

@ -1,22 +0,0 @@
using Pixiview.iOS.Renderers;
using Pixiview.UI;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(OptionEntry), typeof(OptionEntryRenderer))]
namespace Pixiview.iOS.Renderers
{
public class OptionEntryRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
var control = Control;
if (control != null)
{
control.BorderStyle = UIKit.UITextBorderStyle.None;
}
}
}
}

View File

@ -1,22 +0,0 @@
using Pixiview.iOS.Renderers;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(Picker), typeof(OptionPickerRenderer))]
namespace Pixiview.iOS.Renderers
{
public class OptionPickerRenderer : PickerRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
{
base.OnElementChanged(e);
var control = Control;
if (control != null)
{
control.TextAlignment = UIKit.UITextAlignment.Right;
control.BorderStyle = UIKit.UITextBorderStyle.None;
}
}
}
}

View File

@ -1,56 +0,0 @@
using CoreAnimation;
using Pixiview.iOS.Renderers;
using Pixiview.UI;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(RoundImage), typeof(RoundImageRenderer))]
namespace Pixiview.iOS.Renderers
{
public class RoundImageRenderer : ImageRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Image> e)
{
base.OnElementChanged(e);
var layer = Layer;
if (layer != null && e.NewElement is RoundImage image)
{
bool flag = false;
if (image.CornerRadius > 0)
{
layer.CornerRadius = image.CornerRadius;
flag = true;
}
var mask = image.CornerMasks;
if (mask != CornerMask.None)
{
var m = default(CACornerMask);
if ((mask & CornerMask.LeftTop) == CornerMask.LeftTop)
{
m |= CACornerMask.MinXMinYCorner;
}
if ((mask & CornerMask.RightTop) == CornerMask.RightTop)
{
m |= CACornerMask.MaxXMinYCorner;
}
if ((mask & CornerMask.LeftBottom) == CornerMask.LeftBottom)
{
m |= CACornerMask.MinXMaxYCorner;
}
if ((mask & CornerMask.RightBottom) == CornerMask.RightBottom)
{
m |= CACornerMask.MaxXMaxYCorner;
}
layer.MaskedCorners = m;
flag = true;
}
if (flag)
{
layer.MasksToBounds = true;
}
}
}
}
}

View File

@ -1,56 +0,0 @@
using System.ComponentModel;
using Pixiview.iOS.Renderers;
using Pixiview.UI;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(RoundLabel), typeof(RoundLabelRenderer))]
namespace Pixiview.iOS.Renderers
{
public class RoundLabelRenderer : LabelRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
base.OnElementChanged(e);
var layer = Layer;
if (layer != null && e.NewElement is RoundLabel label)
{
var radius = label.CornerRadius;
if (radius > 0)
{
layer.CornerRadius = radius;
//layer.MasksToBounds = true;
}
else
{
layer.CornerRadius = 0;
}
if (layer.BackgroundColor != default)
{
layer.BackgroundColor = label.BackgroundColor.ToCGColor();
}
}
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == RoundLabel.CornerRadiusProperty.PropertyName)
{
var layer = Layer;
if (layer != null && Element is RoundLabel label)
{
var radius = label.CornerRadius;
if (radius > 0)
{
layer.CornerRadius = radius;
layer.BackgroundColor = label.BackgroundColor.ToCGColor();
//layer.MasksToBounds = true;
}
}
}
}
}
}

View File

@ -1,156 +0,0 @@
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();
UIColor c = UIColor.LabelColor;
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);
}
}
}