public static UIBarButtonItem ToBarButtonItem(this IReactiveCommand @this, UIBarButtonSystemItem item) { var button = new UIBarButtonItem(item, (s, e) => @this.ExecuteIfCan()); button.EnableIfExecutable(@this); return(button); }
public static UIBarButtonItem ToBarButtonItem(this IReactiveCommand @this, UIBarButtonSystemItem item) { if (@this == null) return null; var button = new UIBarButtonItem(item, (s, e) => @this.ExecuteIfCan(s)); button.EnableIfExecutable(@this); return button; }
public override void ViewDidLoad() { base.ViewDidLoad(); var centerButton = new CenterButton(); centerButton.TouchUpInside += (s, e) => { //TableView.ScrollRectToVisible(new CGRect(0, 0, 1, 1), false); ViewModel.StumbleCommand.ExecuteIfCan(); }; var stumbleButton = new UIBarButtonItem(centerButton) { Enabled = false }; stumbleButton.EnableIfExecutable(ViewModel.StumbleCommand.CanExecuteObservable); ToolbarItems = new [] { new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace), DislikeButton, new UIBarButtonItem(UIBarButtonSystemItem.FixedSpace) { Width = 40 }, stumbleButton, new UIBarButtonItem(UIBarButtonSystemItem.FixedSpace) { Width = 40 }, LikeButton, new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace), }; ViewModel.StumbleCommand.CanExecuteObservable.Subscribe(x => centerButton.Disabled = !x); DislikeButton.EnableIfExecutable(ViewModel.StumbleCommand.CanExecuteObservable); LikeButton.EnableIfExecutable(ViewModel.StumbleCommand.CanExecuteObservable); ViewModel.DislikeCommand.Subscribe(_ => DisplayResponse(Images.ThumbDownFilled)); ViewModel.LikeCommand.Subscribe(_ => DisplayResponse(Images.ThumbUpFilled)); ViewModel.StumbleCommand.ExecuteIfCan(); }
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); }); }
public static UIBarButtonItem WithCommand(this UIBarButtonItem @this, IReactiveCommand command) { @this.Clicked += (sender, e) => command.ExecuteIfCan(); @this.EnableIfExecutable(command.CanExecuteObservable); return(@this); }