Exemplo n.º 1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            _tapGesture = new UITapGestureRecognizer();
            _tapGesture.ShouldReceiveTouch            = (r, t) => t.TapCount == 1;
            _tapGesture.ShouldRecognizeSimultaneously = (a, b) => true;
            _tapGesture.ShouldRequireFailureOf        = (a, b) =>
            {
                var targetTap = b as UITapGestureRecognizer;
                if (targetTap != null)
                {
                    return(targetTap.NumberOfTapsRequired == 2);
                }
                return(false);
            };
            Web.AddGestureRecognizer(_tapGesture);
            _tapGesture.AddTarget(() =>
            {
                _fullScreen = !_fullScreen;
                UIApplication.SharedApplication.SetStatusBarHidden(_fullScreen, UIStatusBarAnimation.Slide);
                NavigationController.SetNavigationBarHidden(_fullScreen, true);
                NavigationController.SetToolbarHidden(_fullScreen, true);
            });

            ViewModel.WhenAnyValue(x => x.Theme)
            .Select(x => new { Theme = x, ViewModel.SourceItem })
            .Skip(1)
            .Where(x => x != null && x.SourceItem != null && !x.SourceItem.IsBinary)
            .Subscribe(x => LoadContent(x.SourceItem.FilePath));

            ViewModel.WhenAnyValue(x => x.SourceItem)
            .Where(x => x != null)
            .Subscribe(x =>
            {
                if (x.IsBinary)
                {
                    LoadFile(x.FilePath);
                }
                else
                {
                    LoadContent(x.FilePath);
                }
            });

            ViewModel.WhenAnyObservable(x => x.NextItemCommand.CanExecuteObservable, x => x.PreviousItemCommand.CanExecuteObservable)
            .Where(x => x)
            .Subscribe(_ =>
            {
                var previousButton = new UIBarButtonItem(Xamarin.Utilities.Images.Images.BackChevron,
                                                         UIBarButtonItemStyle.Plain, (s, e) => ViewModel.PreviousItemCommand.ExecuteIfCan());
                previousButton.EnableIfExecutable(ViewModel.PreviousItemCommand.CanExecuteObservable);

                var nextButton = new UIBarButtonItem(Xamarin.Utilities.Images.Images.ForwardChevron,
                                                     UIBarButtonItemStyle.Plain, (s, e) => ViewModel.NextItemCommand.ExecuteIfCan());
                nextButton.EnableIfExecutable(ViewModel.NextItemCommand.CanExecuteObservable);

                ToolbarItems = new []
                {
                    new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace),
                    previousButton,
                    new UIBarButtonItem(UIBarButtonSystemItem.FixedSpace)
                    {
                        Width = 80f
                    },
                    nextButton,
                    new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace),
                };

                NavigationController.SetToolbarHidden(false, true);
            });
        }