Beispiel #1
0
        public ViewModelViewHost(NSView targetView)
        {
            NSView viewLastAdded = null;

            ViewContractObservable = Observable.Return(default(string));

            var vmAndContract = Observable.CombineLatest(
                this.WhenAny(x => x.ViewModel, x => x.Value),
                this.WhenAnyObservable(x => x.ViewContractObservable),
                (vm, contract) => new { ViewModel = vm, Contract = contract, });

            vmAndContract.Subscribe(x => {
                if (viewLastAdded != null) viewLastAdded.RemoveFromSuperview();

                if (ViewModel == null) {
                    if (DefaultContent != null) targetView.AddSubview(DefaultContent.View);
                    return;
                }

                var viewLocator = ViewLocator ?? ReactiveUI.ViewLocator.Current;
                var view = viewLocator.ResolveView(x.ViewModel, x.Contract);
                view.ViewModel = x.ViewModel;

                viewLastAdded = ((NSViewController)view).View;
                targetView.AddSubview(viewLastAdded);           
            });
        }
        public ViewModelViewHost(NSView targetView)
        {
            NSView viewLastAdded = null;

            ViewContractObservable = Observable.Return(default(string));

            var vmAndContract = Observable.CombineLatest(
                this.WhenAny(x => x.ViewModel, x => x.Value),
                this.WhenAnyObservable(x => x.ViewContractObservable),
                (vm, contract) => new { ViewModel = vm, Contract = contract, });

            vmAndContract.Subscribe(x => {
                if (viewLastAdded != null)
                {
                    viewLastAdded.RemoveFromSuperview();
                }

                if (ViewModel == null)
                {
                    if (DefaultContent != null)
                    {
                        targetView.AddSubview(DefaultContent.View);
                    }
                    return;
                }

                var viewLocator = ViewLocator ?? ReactiveUI.ViewLocator.Current;
                var view        = viewLocator.ResolveView(x.ViewModel, x.Contract);
                view.ViewModel  = x.ViewModel;

                viewLastAdded = ((NSViewController)view).View;
                targetView.AddSubview(viewLastAdded);
            });
        }
        public RoutedViewHost(NSView targetView)
        {
            NSView viewLastAdded = null;
            this.WhenAny(x => x.Router.NavigationStack, x => x.Value)
                .SelectMany(x => x.CollectionCountChanged.StartWith(x.Count).Select(_ => x.LastOrDefault()))
                .Subscribe(vm => {
                    if (viewLastAdded != null) viewLastAdded.RemoveFromSuperview();

                    if (vm == null) {
                        if (DefaultContent != null) targetView.AddSubview(DefaultContent.View);
                        return;
                    }

                    var view = RxRouting.ResolveView(vm);
                    view.ViewModel = vm;

                    if (view is NSViewController) {
                        viewLastAdded = ((NSViewController)view).View;
                    } else if (view is NSView) {
                        viewLastAdded = (NSView)view;
                    } else {
                        throw new Exception(String.Format("'{0}' must be an NSViewController or NSView", view.GetType().FullName));
                    }

                    targetView.AddSubview(viewLastAdded);
                }, ex => RxApp.DefaultExceptionHandler.OnNext(ex));
        }
        public ViewModelViewHost(NSView targetView)
        {
            NSView viewLastAdded = null;

            this.WhenAny(x => x.DefaultContent, x => x.ViewModel, (c, v) => Unit.Default)
            .Subscribe(_ => {
                if (viewLastAdded != null)
                {
                    viewLastAdded.RemoveFromSuperview();
                }

                if (ViewModel == null)
                {
                    if (DefaultContent != null)
                    {
                        targetView.AddSubview(DefaultContent.View);
                    }
                    return;
                }

                var view       = RxRouting.ResolveView(ViewModel);
                view.ViewModel = ViewModel;

                viewLastAdded = ((NSViewController)view).View;
                targetView.AddSubview(viewLastAdded);
            });
        }
        public RoutedViewHost(NSView targetView)
        {
            NSView viewLastAdded = null;

            ViewContractObservable = Observable.Return(default(string));

            var vmAndContract = Observable.CombineLatest(
                this.WhenAnyObservable(x => x.Router.CurrentViewModel),
                this.WhenAnyObservable(x => x.ViewContractObservable),
                (vm, contract) => new { ViewModel = vm, Contract = contract, });

            vmAndContract.Subscribe(x => {
                if (viewLastAdded != null)
                {
                    viewLastAdded.RemoveFromSuperview();
                }

                if (x.ViewModel == null)
                {
                    if (DefaultContent != null)
                    {
                        targetView.AddSubview(DefaultContent.View);
                    }
                    return;
                }

                var viewLocator = ViewLocator ?? ReactiveUI.ViewLocator.Current;
                var view        = viewLocator.ResolveView(x.ViewModel, x.Contract) ?? viewLocator.ResolveView(x.ViewModel, null);
                view.ViewModel  = x.ViewModel;

                if (view is NSViewController)
                {
                    viewLastAdded = ((NSViewController)view).View;
                }
                else if (view is NSView)
                {
                    viewLastAdded = (NSView)view;
                }
                else
                {
                    throw new Exception(String.Format("'{0}' must be an NSViewController or NSView", view.GetType().FullName));
                }

                targetView.AddSubview(viewLastAdded);
            }, RxApp.DefaultExceptionHandler.OnNext);
        }
        public ViewModelViewHost(NSView targetView)
        {
            NSView viewLastAdded = null;
            this.WhenAny(x => x.DefaultContent, x => x.ViewModel, (c,v) => Unit.Default)
                .Subscribe(_ => {
                    if (viewLastAdded != null) viewLastAdded.RemoveFromSuperview();

                    if (ViewModel == null) {
                        if (DefaultContent != null) targetView.AddSubview(DefaultContent.View);
                        return;
                    }

                    var view = RxRouting.ResolveView(ViewModel);
                    view.ViewModel = ViewModel;

                    viewLastAdded = ((NSViewController)view).View;
                    targetView.AddSubview(viewLastAdded);
                });
        }
        public RoutedViewHost(NSView targetView)
        {
            NSView viewLastAdded = null;
            this.WhenAny(x => x.Router.NavigationStack, x => x.Value)
                .SelectMany(x => x.CollectionCountChanged.StartWith(x.Count).Select(_ => x.LastOrDefault()))
                .Subscribe(vm => {
                    if (viewLastAdded != null) viewLastAdded.RemoveFromSuperview();

                    if (vm == null) {
                        if (DefaultContent != null) targetView.AddSubview(DefaultContent.View);
                        return;
                    }

                    var view = RxRouting.ResolveView(vm);
                    view.ViewModel = vm;

                    viewLastAdded = ((NSViewController)view).View;
                    targetView.AddSubview(viewLastAdded);
                }, ex => RxApp.DefaultExceptionHandler.OnNext(ex));
        }
Beispiel #8
0
        public RoutedViewHost(NSView targetView)
        {
            NSView viewLastAdded = null;

            this.WhenAny(x => x.Router.NavigationStack, x => x.Value)
            .SelectMany(x => x.CollectionCountChanged.StartWith(x.Count).Select(_ => x.LastOrDefault()))
            .Subscribe(vm => {
                if (viewLastAdded != null)
                {
                    viewLastAdded.RemoveFromSuperview();
                }

                if (vm == null)
                {
                    if (DefaultContent != null)
                    {
                        targetView.AddSubview(DefaultContent.View);
                    }
                    return;
                }

                var view       = RxRouting.ResolveView(vm);
                view.ViewModel = vm;

                if (view is NSViewController)
                {
                    viewLastAdded = ((NSViewController)view).View;
                }
                else if (view is NSView)
                {
                    viewLastAdded = (NSView)view;
                }
                else
                {
                    throw new Exception(String.Format("'{0}' must be an NSViewController or NSView", view.GetType().FullName));
                }

                targetView.AddSubview(viewLastAdded);
            }, ex => RxApp.DefaultExceptionHandler.OnNext(ex));
        }
Beispiel #9
0
        public RoutedViewHost(NSView targetView)
        {
            NSView viewLastAdded = null;

            ViewContractObservable = Observable.Return(default(string));
                        
            var vmAndContract = Observable.CombineLatest(
                this.WhenAnyObservable(x => x.Router.CurrentViewModel),
                this.WhenAnyObservable(x => x.ViewContractObservable),
                (vm, contract) => new { ViewModel = vm, Contract = contract, });

            vmAndContract.Subscribe(x => {
                if (viewLastAdded != null)
                    viewLastAdded.RemoveFromSuperview();

                if (x.ViewModel == null) {
                    if (DefaultContent != null)
                        targetView.AddSubview(DefaultContent.View);
                    return;
                }

                var viewLocator = ViewLocator ?? ReactiveUI.ViewLocator.Current;
                var view = viewLocator.ResolveView(x.ViewModel, x.Contract) ?? viewLocator.ResolveView(x.ViewModel, null);
                view.ViewModel = x.ViewModel;

                if (view is NSViewController) {
                    viewLastAdded = ((NSViewController)view).View;
                } else if (view is NSView) {
                    viewLastAdded = (NSView)view;
                } else {
                    throw new Exception(String.Format("'{0}' must be an NSViewController or NSView", view.GetType().FullName));
                }

                targetView.AddSubview(viewLastAdded);           
            }, RxApp.DefaultExceptionHandler.OnNext);
        }
Beispiel #10
0
        public ViewModelViewHost(NSView targetView)
        {
            if (targetView == null) throw new ArgumentNullException("targetView");

            NSView viewLastAdded = null;
            ViewContractObservable = Observable.Return(default(string));

            var vmAndContract = Observable.CombineLatest(
                this.WhenAny(x => x.ViewModel, x => x.Value),
                this.WhenAnyObservable(x => x.ViewContractObservable),
                (vm, contract) => new { ViewModel = vm, Contract = contract, });

            vmAndContract.Subscribe(x => {
                if (viewLastAdded != null) viewLastAdded.RemoveFromSuperview();

                if (ViewModel == null) {
                    if (DefaultContent != null) targetView.AddSubview(DefaultContent.View);
                    return;
                }

                // get an instance of the view controller for the supplied VM + Contract
                var viewLocator = ViewLocator ?? ReactiveUI.ViewLocator.Current;
                var viewController = viewLocator.ResolveView(x.ViewModel, x.Contract);

                // if not found, throw
                if (viewController == null) {
                    var message = String.Format("Unable to resolve view for \"{0}\"", x.ViewModel.GetType());

                    if (x.Contract != null) {
                        message += String.Format(" and contract \"{1}\"", x.Contract.GetType());
                    }

                    message += ".";
                    throw new Exception(message);
                }

                // set the VM on the controller and stash a copy of the added view
                viewController.ViewModel = x.ViewModel;
                viewLastAdded = ((NSViewController)viewController).View;

                // sanity check, view controllers are expect to have a view
                if (viewLastAdded == null) {
                    var message = string.Format("No view associated with view controller {0}.", viewController.GetType());
                    throw new Exception(message);
                }

                if (AddAutoLayoutConstraintsToSubView) {
                    // see https://developer.apple.com/library/ios/documentation/userexperience/conceptual/AutolayoutPG/AdoptingAutoLayout/AdoptingAutoLayout.html
                    viewLastAdded.TranslatesAutoresizingMaskIntoConstraints = false;
                }

                targetView.AddSubview(viewLastAdded);

                if (AddAutoLayoutConstraintsToSubView) {
                    // Add edge constraints so that subview trails changes in parent
                    addEdgeConstraint(NSLayoutAttribute.Left,  targetView, viewLastAdded);
                    addEdgeConstraint(NSLayoutAttribute.Right, targetView, viewLastAdded);
                    addEdgeConstraint(NSLayoutAttribute.Top, targetView, viewLastAdded);
                    addEdgeConstraint(NSLayoutAttribute.Bottom,  targetView, viewLastAdded);
                }
            });
        }
        public ViewModelViewHost(NSView targetView)
        {
            if (targetView == null)
            {
                throw new ArgumentNullException("targetView");
            }

            NSView viewLastAdded = null;

            ViewContractObservable = Observable.Return(default(string));

            var vmAndContract = Observable.CombineLatest(
                this.WhenAny(x => x.ViewModel, x => x.Value),
                this.WhenAnyObservable(x => x.ViewContractObservable),
                (vm, contract) => new { ViewModel = vm, Contract = contract, });

            vmAndContract.Subscribe(x => {
                if (viewLastAdded != null)
                {
                    viewLastAdded.RemoveFromSuperview();
                }

                if (ViewModel == null)
                {
                    if (DefaultContent != null)
                    {
                        targetView.AddSubview(DefaultContent.View);
                    }
                    return;
                }

                // get an instance of the view controller for the supplied VM + Contract
                var viewLocator    = ViewLocator ?? ReactiveUI.ViewLocator.Current;
                var viewController = viewLocator.ResolveView(x.ViewModel, x.Contract);

                // if not found, throw
                if (viewController == null)
                {
                    var message = String.Format("Unable to resolve view for \"{0}\"", x.ViewModel.GetType());

                    if (x.Contract != null)
                    {
                        message += String.Format(" and contract \"{0}\"", x.Contract.GetType());
                    }

                    message += ".";
                    throw new Exception(message);
                }

                // set the VM on the controller and stash a copy of the added view
                viewController.ViewModel = x.ViewModel;
                viewLastAdded            = ((NSViewController)viewController).View;

                // sanity check, view controllers are expect to have a view
                if (viewLastAdded == null)
                {
                    var message = string.Format("No view associated with view controller {0}.", viewController.GetType());
                    throw new Exception(message);
                }

                if (AddAutoLayoutConstraintsToSubView)
                {
                    // see https://developer.apple.com/library/ios/documentation/userexperience/conceptual/AutolayoutPG/AdoptingAutoLayout/AdoptingAutoLayout.html
                    viewLastAdded.TranslatesAutoresizingMaskIntoConstraints = false;
                }

                targetView.AddSubview(viewLastAdded);

                if (AddAutoLayoutConstraintsToSubView)
                {
                    // Add edge constraints so that subview trails changes in parent
                    addEdgeConstraint(NSLayoutAttribute.Left, targetView, viewLastAdded);
                    addEdgeConstraint(NSLayoutAttribute.Right, targetView, viewLastAdded);
                    addEdgeConstraint(NSLayoutAttribute.Top, targetView, viewLastAdded);
                    addEdgeConstraint(NSLayoutAttribute.Bottom, targetView, viewLastAdded);
                }
            });
        }