Exemplo n.º 1
0
        public static Page AsPageWith <TPage>(this RxnPageModel model, TPage page, string title, string icon = null, Action OnAppearing = null, Action OnDisapearing = null) where TPage : Page
        {
            page.Title = title;
            page.Icon  = icon;

            Observable.FromEventPattern(a => page.Appearing += a, b => page.Appearing -= b)
            .Do(_ =>
            {
                if (OnAppearing != null)
                {
                    OnAppearing();
                }
                page.BindingContext = model;
            })
            .Until(model.OnError)
            .DisposedBy(model);

            Observable.FromEventPattern(a => page.Disappearing += a, b => page.Disappearing -= b)
            .Do(_ =>
            {
                if (OnDisapearing != null)
                {
                    OnDisapearing();
                }
                page.BindingContext = null;
            })
            .Until(model.OnError)
            .DisposedBy(model);

            return(page);
        }
Exemplo n.º 2
0
        public IObservable <bool> AutomateUserActions(Page page, RxnPageModel model, IObservable <IRxn> actions, Action <IRxn> publish)
        {
            return(RxObservable.DfrCreate <bool>(o =>
            {
                var state = new InterceptState(model, actions, publish);
                var resources = new CompositeDisposable(new DisposableAction(() => { Debug.WriteLine("<<<<Disposing of {0}>>>>>", model.GetType().Name); }));

                if (page is ContentPage)
                {
                    Observable.FromEventPattern(e => page.LayoutChanged += e, e => page.LayoutChanged -= e)
                    .Select(_ => new Unit())
                    .StartWith(new Unit())
                    .BufferFirstLast(TimeSpan.FromMilliseconds(70), false)
                    .Do(_ => o.OnNext(false))
                    .Do(_ => _dialog.ShowLoading("Loading..."))
                    .Do(_ => Debug.WriteLine("Intercepting>>> {0}", model.GetType().Name))

                    .Select(_ =>
                    {
                        return Observable.Defer(() => RxObservable.Create(() =>
                        {
                            var timer = Stopwatch.StartNew();
                            var r = FindAllCommandHolder(((ContentPage)page).Content as IViewContainer <View>, state);
                            timer.Stop();
                            Debug.WriteLine("Interception took: {0}", timer.Elapsed);

                            if (r != null)
                            {
                                resources.Add(r);
                            }
                        }));
                    })
                    .Switch()
                    .Do(_ => _dialog.HideLoading())
                    .FinallyR(() => _dialog.HideLoading())
                    .Subscribe(_ => o.OnNext(true))
                    .DisposedBy(resources);

                    return resources;
                }
                ;

                return Disposable.Empty;
            }));
        }
Exemplo n.º 3
0
 public InterceptState(RxnPageModel model, IObservable <IRxn> input, Action <IRxn> publish)
 {
     Model   = model;
     Input   = input;
     Publish = publish;
 }
Exemplo n.º 4
0
 public IObservable <bool> AutomateUserActions(Page page, RxnPageModel model, IObservable <IRxn> actions, Action <IRxn> publish)
 {
     return(new BehaviorSubject <bool>(true));
 }