/// <summary> /// Finds window corresponding to specified view model. /// </summary> private static Window FindOwnerWindow(INotifyPropertyChanged viewModel) { IView?view = DialogServiceViews.Views.SingleOrDefault( registeredView => registeredView.Source.IsLoaded && ReferenceEquals(registeredView.DataContext, viewModel)); if (view == null) { string message = $"View model of type '{viewModel.GetType()}' is not present as data context on any registered view. Please register the view by setting DialogServiceViews.IsRegistered=\"True\" in your XAML."; throw new ViewNotRegisteredException(message); } // Get owner window Window?owner = view.GetOwner(); if (owner == null) { throw new InvalidOperationException($"View of type '{view.GetType()}' is not registered."); } return(owner); }
public static void UpdateTransformation(this UIView nativeView, IView?view) { CALayer?layer = nativeView.Layer; CGPoint?originalAnchor = layer?.AnchorPoint; nativeView.UpdateTransformation(view, layer, originalAnchor); }
public virtual void NavigateTo(NavigationRequest args) { IReadOnlyList <IView> newPageStack = args.NavigationStack; var previousNavigationStack = NavigationStack; var previousNavigationStackCount = previousNavigationStack.Count; bool initialNavigation = NavigationStack.Count == 0; // User has modified navigation stack but not the currently visible page // So we just sync the elements in the stack if (!initialNavigation && newPageStack[newPageStack.Count - 1] == previousNavigationStack[previousNavigationStackCount - 1]) { SyncBackStackToNavigationStack(newPageStack); NavigationStack = new List <IView>(newPageStack); NavigationView?.NavigationFinished(NavigationStack); return; } NavigationTransitionInfo?transition = GetNavigationTransition(args); _currentPage = newPageStack[newPageStack.Count - 1]; if (previousNavigationStack.Count < args.NavigationStack.Count) { Type destinationPageType = GetDestinationPageType(); NavigationStack = new List <IView>(newPageStack); NavigationFrame.Navigate(destinationPageType, null, transition); } else { NavigationStack = new List <IView>(newPageStack); NavigationFrame.GoBack(transition); } }
public static void CheckHandlers(this IView?view) { if (view?.Handler == null) { return; } //So we can be smart and keep all old handlers //However with the Old Legacy Shim layouts, this causes issues. //So for now I am just going to kill all handlers, so everything needs rebuilt //var handlerType = handlerServiceProvider.GetHandlerType(view.GetType()); //if (handlerType != view.Handler.GetType()){ // view.Handler = null; //} view.Handler = null; if (view is IContentView p) { CheckHandlers(p.PresentedContent); } if (view is IContainer layout) { foreach (var v in layout) { CheckHandlers(v); } } }
public int Compare(IView?x, IView?y) { if (x == null || y == null) { return(0); } return(x.ZIndex.CompareTo(y.ZIndex)); }
public static void UpdateContent(this MauiScrollView scrollView, IView?content, IMauiContext context) { var nativeContent = content == null ? null : content.ToNative(context); scrollView.RemoveAllViews(); if (nativeContent != null) { scrollView.SetContent(nativeContent); } }
public void UpdateContent(IView?content, IMauiContext?mauiContext) { _contentView?.RemoveFromParent(); if (content != null && mauiContext != null) { _contentView = content.ToPlatform(mauiContext); var layoutParams = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent); AddView(_contentView, layoutParams); } }
/// <summary> /// Gets the main monitor. /// </summary> /// <returns>The main monitor.</returns> public static IMonitor GetMainMonitor(IView?view) { foreach (var platform in Window.Platforms) { if (view is null ? platform.IsApplicable : platform.IsSourceOfView(view)) { return(platform.GetMainMonitor()); } } throw Window.NoPlatformException; }
public void UpdateContent(IView?content, IMauiContext?mauiContext) { if (_refreshControlParent != null) { TryRemoveRefresh(_refreshControlParent); } _contentView?.RemoveFromSuperview(); if (content != null && mauiContext != null) { _contentView = content.ToNative(mauiContext); this.AddSubview(_contentView); TryInsertRefresh(_contentView); } }
// TODO ezhart This method is no longer used internally; we can't delete it right now because that'd be a breaking change public static void UpdateContent(this UIScrollView scrollView, IView?content, IMauiContext context) { var nativeContent = content == null ? null : content.ToPlatform(context); if (scrollView.Subviews.Length > 0 && scrollView.Subviews[0] == nativeContent) { return; } if (scrollView.Subviews.Length > 0) { // TODO ezhart Are we sure this is always the correct index? The scroll indicators might be in here, too. scrollView.Subviews[0].RemoveFromSuperview(); } if (nativeContent != null) { scrollView.AddSubview(nativeContent); } }
public static void UpdateTransformation(this EvasObject platformView, IView?view) { if (view == null) { return; } // prepare the EFL effect structure Rect geometry = platformView.Geometry; EvasMap map = new EvasMap(4); map.PopulatePoints(geometry, 0); bool changed = false; view.ApplyScale(map, geometry, ref changed); view.ApplyRotation(platformView, map, geometry, ref changed); view.ApplyTranslation(map, geometry, ref changed); platformView.IsMapEnabled = changed; if (changed) { platformView.EvasMap = map; if (!s_movedHandlers.ContainsKey(platformView)) { // not registered moved handler s_movedHandlers[platformView] = () => platformView.UpdateTransformation(view); platformView.Moved += OnMoved; } } else { if (s_movedHandlers.ContainsKey(platformView)) { // need to unregister moved handler platformView.Moved -= OnMoved; s_movedHandlers.Remove(platformView); } } }
public void InjectView(IView view) { View = view; }
internal static IWindow?GetHostedWindow(this IView?view) => null;
public static void UpdateTransformation(this UIView nativeView, IView?view, CALayer?layer, CGPoint?originalAnchor) { if (view == null) { return; } var anchorX = (float)view.AnchorX; var anchorY = (float)view.AnchorY; var translationX = (float)view.TranslationX; var translationY = (float)view.TranslationY; var rotationX = (float)view.RotationX; var rotationY = (float)view.RotationY; var rotation = (float)view.Rotation; var scale = (float)view.Scale; var scaleX = (float)view.ScaleX * scale; var scaleY = (float)view.ScaleY * scale; var width = (float)view.Frame.Width; var height = (float)view.Frame.Height; var x = (float)view.Frame.X; var y = (float)view.Frame.Y; void Update() { var shouldUpdate = width > 0 && height > 0 && view.Parent != null; if (!shouldUpdate) { return; } const double epsilon = 0.001; var transform = CATransform3D.Identity; // Position is relative to anchor point if (Math.Abs(anchorX - .5) > epsilon) { transform = transform.Translate((anchorX - .5f) * width, 0, 0); } if (Math.Abs(anchorY - .5) > epsilon) { transform = transform.Translate(0, (anchorY - .5f) * height, 0); } if (Math.Abs(translationX) > epsilon || Math.Abs(translationY) > epsilon) { transform = transform.Translate(translationX, translationY, 0); } // Not just an optimization, iOS will not "pixel align" a view which has m34 set if (Math.Abs(rotationY % 180) > epsilon || Math.Abs(rotationX % 180) > epsilon) { transform.m34 = 1.0f / -400f; } if (Math.Abs(rotationX % 360) > epsilon) { transform = transform.Rotate(rotationX * (float)Math.PI / 180.0f, 1.0f, 0.0f, 0.0f); } if (Math.Abs(rotationY % 360) > epsilon) { transform = transform.Rotate(rotationY * (float)Math.PI / 180.0f, 0.0f, 1.0f, 0.0f); } transform = transform.Rotate(rotation * (float)Math.PI / 180.0f, 0.0f, 0.0f, 1.0f); if (Math.Abs(scaleX - 1) > epsilon || Math.Abs(scaleY - 1) > epsilon) { transform = transform.Scale(scaleX, scaleY, scale); } if (Foundation.NSThread.IsMain) { if (layer != null) { layer.AnchorPoint = new PointF(anchorX, anchorY); layer.Transform = transform; } } else { CoreFoundation.DispatchQueue.MainQueue.DispatchAsync(() => { if (layer != null) { layer.AnchorPoint = new PointF(anchorX, anchorY); layer.Transform = transform; } }); } } // TODO: Use the thread var when porting the Device class. Update(); }
internal static IWindow?GetHostedWindow(this IView?view) => GetHostedWindow(view?.Handler?.PlatformView as UIView);
void UpdateNavigationStack(IReadOnlyList <IView> newPageStack) { NavigationStack = new List <IView>(newPageStack); _currentPage = NavigationStack[NavigationStack.Count - 1]; }
internal static IWindow?GetHostedWindow(this IView?view) => GetHostedWindow(view?.Handler?.PlatformView as FrameworkElement);
protected BaseViewModel(IView view, IScopeFactory?scopeFactory = null) : this(scopeFactory) { _view = view; }