Exemplo n.º 1
0
        public virtual Task <string> ActionSheetAsync(string title, string cancel, string destructive, params string[] buttons)
        {
            var tcs = new TaskCompletionSource <string>();
            var cfg = new ActionSheetConfig();

            if (title != null)
            {
                cfg.Title = title;
            }

            if (cancel != null)
            {
                cfg.SetCancel(cancel, () => tcs.TrySetResult(cancel));
            }

            if (destructive != null)
            {
                cfg.SetDestructive(destructive, () => tcs.TrySetResult(destructive));
            }

            foreach (var btn in buttons)
            {
                cfg.Add(btn, () => tcs.TrySetResult(btn));
            }

            this.ActionSheet(cfg);
            return(tcs.Task);
        }
Exemplo n.º 2
0
        public override void ActionSheet(ActionSheetConfig config)
        {
            var dlg = new AlertDialog
                .Builder(this.GetTopActivity())
                .SetCancelable(false)
                .SetTitle(config.Title);

            if (config.ItemIcon != null || config.Options.Any(x => x.ItemIcon != null)) {
                var adapter = new ActionSheetListAdapter(this.GetTopActivity(), Android.Resource.Layout.SelectDialogItem, Android.Resource.Id.Text1, config);
                dlg.SetAdapter(adapter, (s, a) => config.Options[a.Which].Action?.Invoke());
            }
            else {
                var array = config
                    .Options
                    .Select(x => x.Text)
                    .ToArray();

                dlg.SetItems(array, (s, args) => config.Options[args.Which].Action?.Invoke());
            }

            if (config.Destructive != null)
                dlg.SetNegativeButton(config.Destructive.Text, (s, a) => config.Destructive.Action?.Invoke());

            if (config.Cancel != null)
                dlg.SetNeutralButton(config.Cancel.Text, (s, a) => config.Cancel.Action?.Invoke());

            Utils.RequestMainThread(() => dlg.ShowExt());
        }
Exemplo n.º 3
0
 public override void ActionSheet(ActionSheetConfig config)
 {
     if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
         this.ShowIOS8ActionSheet(config);
     else
         this.ShowIOS7ActionSheet(config);
 }
        public virtual async Task <string> ActionSheetAsync(string title, string cancel, string destructive, CancellationToken?cancelToken = null, params string[] buttons)
        {
            var tcs = new TaskCompletionSource <string>();
            var cfg = new ActionSheetConfig();

            if (title != null)
            {
                cfg.Title = title;
            }

            // you must have a cancel option for actionsheetasync
            cfg.SetCancel(cancel, () => tcs.TrySetResult(cancel));

            if (destructive != null)
            {
                cfg.SetDestructive(destructive, () => tcs.TrySetResult(destructive));
            }

            foreach (var btn in buttons)
            {
                cfg.Add(btn, () => tcs.TrySetResult(btn));
            }

            var disp = this.ActionSheet(cfg);

            using (cancelToken?.Register(disp.Dispose))
            {
                return(await tcs.Task);
            }
        }
Exemplo n.º 5
0
        public override void ActionSheet(ActionSheetConfig config)
        {
            var dlg = new ActionSheetContentDialog();

            var vm = new ActionSheetViewModel {
                Title = config.Title,
                Cancel = new ActionSheetOptionViewModel(config.Cancel != null,config.Cancel?.Text, () => {
                    dlg.Hide();
                    config.Cancel?.Action?.Invoke();
                }),

                Destructive = new ActionSheetOptionViewModel(config.Destructive != null, config.Destructive?.Text, () => {
                    dlg.Hide();
                    config.Destructive?.Action?.Invoke();
                }),

                Options = config
                    .Options
                    .Select(x => new ActionSheetOptionViewModel(true, x.Text, () => {
                        dlg.Hide();
                        x.Action?.Invoke();
                    }))
                    .ToList()
            };

            dlg.DataContext = vm;
            dlg.ShowAsync();
        }
        public override IDisposable ActionSheet(ActionSheetConfig config)
        {
            var sheet = new CustomMessageBox
            {
                Caption = config.Title
            };

            if (config.Cancel != null)
            {
                sheet.IsRightButtonEnabled = true;
                sheet.RightButtonContent   = this.CreateButton(config.Cancel.Text, () =>
                {
                    sheet.Dismiss();
                    config.Cancel.Action?.Invoke();
                });
            }
            if (config.Destructive != null)
            {
                sheet.IsLeftButtonEnabled = true;
                sheet.LeftButtonContent   = this.CreateButton(config.Destructive.Text, () =>
                {
                    sheet.Dismiss();
                    config.Destructive.Action?.Invoke();
                });
            }

            var list = new ListBox
            {
                FontSize      = 36,
                Margin        = new Thickness(12.0),
                SelectionMode = SelectionMode.Single,
                ItemsSource   = config.Options
                                .Select(x => new TextBlock
                {
                    Text        = x.Text,
                    Margin      = new Thickness(0.0, 12.0, 0.0, 12.0),
                    DataContext = x
                })
            };

            list.SelectionChanged += (sender, args) => sheet.Dismiss();
            sheet.Content          = new ScrollViewer
            {
                Content = list
            };
            sheet.Dismissed += (sender, args) =>
            {
                var txt = list.SelectedValue as TextBlock;
                if (txt == null)
                {
                    return;
                }

                var action = txt.DataContext as ActionSheetOption;
                action?.Action?.Invoke();
            };
            return(this.DispatchWithDispose(sheet.Show, sheet.Dismiss));
        }
 public override void ActionSheet(ActionSheetConfig config)
 {
     if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
     {
         this.ShowIOS8ActionSheet(config);
     }
     else
     {
         this.ShowIOS7ActionSheet(config);
     }
 }
Exemplo n.º 8
0
        public override IDisposable ActionSheet(ActionSheetConfig config)
        {
            var sheet = new CustomMessageBox
            {
                Caption = config.Title
            };
            if (config.Cancel != null)
            {
                sheet.IsRightButtonEnabled = true;
                sheet.RightButtonContent = this.CreateButton(config.Cancel.Text, () =>
                {
                    sheet.Dismiss();
                    config.Cancel.Action?.Invoke();
                });
            }
            if (config.Destructive != null)
            {
                sheet.IsLeftButtonEnabled = true;
                sheet.LeftButtonContent = this.CreateButton(config.Destructive.Text, () =>
                {
                    sheet.Dismiss();
                    config.Destructive.Action?.Invoke();
                });
            }

            var list = new ListBox
            {
                FontSize = 36,
                Margin = new Thickness(12.0),
                SelectionMode = SelectionMode.Single,
                ItemsSource = config.Options
                    .Select(x => new TextBlock
                    {
                        Text = x.Text,
                        Margin = new Thickness(0.0, 12.0, 0.0, 12.0),
                        DataContext = x
                    })
            };
            list.SelectionChanged += (sender, args) => sheet.Dismiss();
            sheet.Content = new ScrollViewer
            {
                Content = list
            };
            sheet.Dismissed += (sender, args) =>
            {
                var txt = list.SelectedValue as TextBlock;
                if (txt == null)
                    return;

                var action = txt.DataContext as ActionSheetOption;
                action?.Action?.Invoke();
            };
            return this.DispatchWithDispose(sheet.Show, sheet.Dismiss);
        }
Exemplo n.º 9
0
        public override void ActionSheet(ActionSheetConfig config)
        {
            var sheet = new PopupMenu();
            foreach (var opt in config.Options)
                sheet.Commands.Add(new UICommand(opt.Text, x => opt.TryExecute()));

            if (config.Cancel != null)
                sheet.Commands.Add(new UICommand(config.Cancel.Text, x => config.Cancel.TryExecute()));

            if (config.Destructive != null)
                sheet.Commands.Add(new UICommand(config.Destructive.Text, x => config.Destructive.TryExecute()));

            sheet.ShowAsync(new Point(0, 0));
        }
Exemplo n.º 10
0
        public override void ActionSheet(ActionSheetConfig config)
        {
            var array = config
                        .Options
                        .Select(x => x.Text)
                        .ToArray();

            Utils.RequestMainThread(() =>
                                    new AlertDialog
                                    .Builder(this.getTopActivity())
                                    .SetTitle(config.Title)
                                    .SetItems(array, (sender, args) => config.Options[args.Which].Action())
                                    .Show()
                                    );
        }
Exemplo n.º 11
0
        public override IDisposable ActionSheet(ActionSheetConfig config)
        {
            var dlg = new TaskDialog
            {
                WindowTitle = config.Title,
                Content     = config.Message,
                Buttons     =
                {
                    new TaskDialogButton(config.OkText)
                }
            };

            dlg.ShowDialog();
            return(new DisposableAction(dlg.Dispose));
        }
        public override IDisposable ActionSheet(ActionSheetConfig config)
        {
            var activity = this.TopActivityFunc();

            if (activity is AppCompatActivity)
            {
                return(this.ShowDialog <ActionSheetAppCompatDialogFragment, ActionSheetConfig>((AppCompatActivity)activity, config));
            }

            if (activity is FragmentActivity)
            {
                return(this.ShowDialog <ActionSheetDialogFragment, ActionSheetConfig>((FragmentActivity)activity, config));
            }

            return(this.Show(activity, ActionSheetBuilder.Build(activity, config)));
        }
Exemplo n.º 13
0
        public override IDisposable ActionSheet(ActionSheetConfig config)
        {
            var activity = this.TopActivityFunc();

            if (activity is AppCompatActivity act)
            {
                if (config.UseBottomSheet)
                {
                    return(this.ShowDialog <Fragments.BottomSheetDialogFragment, ActionSheetConfig>(act, config));
                }

                return(this.ShowDialog <ActionSheetAppCompatDialogFragment, ActionSheetConfig>(act, config));
            }

            return(this.Show(activity, () => new ActionSheetBuilder().Build(activity, config)));
        }
Exemplo n.º 14
0
        public override IDisposable ActionSheet(ActionSheetConfig config)
        {
            var sheet = UIAlertController.Create(config.Title, null, UIAlertControllerStyle.ActionSheet);

            if (config.Destructive != null)
                this.AddActionSheetOption(config.Destructive, sheet, UIAlertActionStyle.Destructive);

            config
                .Options
                .ToList()
                .ForEach(x => this.AddActionSheetOption(x, sheet, UIAlertActionStyle.Default, config.ItemIcon));

            if (config.Cancel != null)
                this.AddActionSheetOption(config.Cancel, sheet, UIAlertActionStyle.Cancel);

            return this.Present(sheet);
        }
Exemplo n.º 15
0
        public virtual Task<string> ActionSheetAsync(string title, string cancel, string destructive, params string[] buttons) {
            var tcs = new TaskCompletionSource<string>();
            var cfg = new ActionSheetConfig();
            if (title != null)
                cfg.Title = title;

            if (cancel != null)
                cfg.SetCancel(cancel, () => tcs.TrySetResult(cancel));

            if (destructive != null)
                cfg.SetDestructive(destructive, () => tcs.TrySetResult(destructive));

            foreach (var btn in buttons)
                cfg.Add(btn, () => tcs.TrySetResult(btn));

			this.ActionSheet(cfg);
            return tcs.Task;
        }
Exemplo n.º 16
0
        public override IDisposable ActionSheet(ActionSheetConfig config)
        {
            var alert = new NSAlert
            {
                MessageText = config.Message
            };

            foreach (var opt in config.Options)
            {
                var btn = alert.AddButton(opt.Text);
                //if (opt.ItemIcon != null)
                //    btn.Image = opt.ItemIcon.ToNative();
            }
            var actionIndex = alert.RunSheetModal(null); // TODO: get top NSWindow

            config.Options[(int)actionIndex].Action?.Invoke();
            return(alert);
        }
Exemplo n.º 17
0
        /// <summary> Gets action sheet configuration. </summary>
        /// <exception cref="ArgumentNullException"> Thrown when one or more required arguments are null. </exception>
        /// <param name="config"> The configuration. </param>
        /// <returns> The action sheet configuration. </returns>
        private AcrDialogs.ActionSheetConfig GetActionSheetConfig(UserDialogActionSheetConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var result = new AcrDialogs.ActionSheetConfig();

            if (config.Title != null)
            {
                result.Title = config.Title;
            }
            if (config.Message != null)
            {
                result.Message = config.Message;
            }
            if (config.Cancel != null)
            {
                result.Cancel = GetActionSheetOption(config.Cancel);
            }
            if (config.Destructive != null)
            {
                result.Destructive = GetActionSheetOption(config.Destructive);
            }
            if (config.Options != null)
            {
                result.Options = config.Options.Select(GetActionSheetOption).ToList();
            }
            if (config.AndroidStyleId != null)
            {
                result.AndroidStyleId = config.AndroidStyleId;
            }
            if (config.UseBottomSheet != null)
            {
                result.UseBottomSheet = config.UseBottomSheet.Value;
            }
            if (config.ItemIcon != null)
            {
                result.ItemIcon = config.ItemIcon;
            }

            return(result);
        }
Exemplo n.º 18
0
        public override async void ActionSheet(ActionSheetConfig config)
        {
            var input = new InputDialog {
                ButtonsPanelOrientation = Orientation.Vertical
            };

            var buttons = config
                          .Options
                          .Select(x => x.Text)
                          .ToArray();

            var choice = await input.ShowAsync(config.Title, null, buttons);

            var opt = config.Options.SingleOrDefault(x => x.Text == choice);

            if (opt != null && opt.Action != null)
            {
                opt.Action();
            }
        }
        protected virtual void ShowIOS8ActionSheet(ActionSheetConfig config)
        {
            var sheet = UIAlertController.Create(config.Title, null, UIAlertControllerStyle.ActionSheet);

            config
            .Options
            .ToList()
            .ForEach(x => this.AddActionSheetOption(x, sheet, UIAlertActionStyle.Default, config.ItemIcon));

            if (config.Destructive != null)
            {
                this.AddActionSheetOption(config.Destructive, sheet, UIAlertActionStyle.Destructive);
            }

            if (config.Cancel != null)
            {
                this.AddActionSheetOption(config.Cancel, sheet, UIAlertActionStyle.Cancel);
            }

            this.Present(sheet);
        }
Exemplo n.º 20
0
        public override void ActionSheet(ActionSheetConfig config)
        {
            var sheet = new PopupMenu();

            foreach (var opt in config.Options)
            {
                sheet.Commands.Add(new UICommand(opt.Text, x => opt.TryExecute()));
            }

            if (config.Cancel != null)
            {
                sheet.Commands.Add(new UICommand(config.Cancel.Text, x => config.Cancel.TryExecute()));
            }

            if (config.Destructive != null)
            {
                sheet.Commands.Add(new UICommand(config.Destructive.Text, x => config.Destructive.TryExecute()));
            }

            sheet.ShowAsync(new Point(0, 0));
        }
Exemplo n.º 21
0
        protected virtual UIAlertController CreateNativeActionSheet(ActionSheetConfig config)
        {
            var sheet = UIAlertController.Create(config.Title, config.Message, UIAlertControllerStyle.ActionSheet);

            if (config.Destructive != null)
            {
                this.AddActionSheetOption(config.Destructive, sheet, UIAlertActionStyle.Destructive);
            }

            config
            .Options
            .ToList()
            .ForEach(x => this.AddActionSheetOption(x, sheet, UIAlertActionStyle.Default, config.ItemIcon));

            if (config.Cancel != null)
            {
                this.AddActionSheetOption(config.Cancel, sheet, UIAlertActionStyle.Cancel);
            }

            return(sheet);
        }
        public override IDisposable ActionSheet(ActionSheetConfig config)
        {
            var sheet = UIAlertController.Create(config.Title, null, UIAlertControllerStyle.ActionSheet);

            if (config.Destructive != null)
            {
                this.AddActionSheetOption(config.Destructive, sheet, UIAlertActionStyle.Destructive);
            }

            config
            .Options
            .ToList()
            .ForEach(x => this.AddActionSheetOption(x, sheet, UIAlertActionStyle.Default, config.ItemIcon));

            if (config.Cancel != null)
            {
                this.AddActionSheetOption(config.Cancel, sheet, UIAlertActionStyle.Cancel);
            }

            return(this.Present(sheet));
        }
        public override void ActionSheet(ActionSheetConfig config)
        {
            var activity = this.GetTopActivity();
            var dlg      = new AlertDialog
                           .Builder(activity)
                           .SetCancelable(false)
                           .SetTitle(config.Title);

            //.SetCustomTitle(new TextView(activity) {
            //    Text = config.Title,
            //    TextSize = 18.0f
            //});

            if (config.ItemIcon != null || config.Options.Any(x => x.ItemIcon != null))
            {
                var adapter = new ActionSheetListAdapter(this.GetTopActivity(), Android.Resource.Layout.SelectDialogItem, Android.Resource.Id.Text1, config);
                dlg.SetAdapter(adapter, (s, a) => config.Options[a.Which].Action?.Invoke());
            }
            else
            {
                var array = config
                            .Options
                            .Select(x => x.Text)
                            .ToArray();

                dlg.SetItems(array, (s, args) => config.Options[args.Which].Action?.Invoke());
            }

            if (config.Destructive != null)
            {
                dlg.SetNegativeButton(config.Destructive.Text, (s, a) => config.Destructive.Action?.Invoke());
            }

            if (config.Cancel != null)
            {
                dlg.SetNeutralButton(config.Cancel.Text, (s, a) => config.Cancel.Action?.Invoke());
            }

            Utils.RequestMainThread(() => dlg.ShowExt());
        }
        protected virtual void ShowIOS7ActionSheet(ActionSheetConfig config)
        {
            var view   = UIApplication.SharedApplication.GetTopView();
            var action = new UIActionSheet(config.Title);

            config.Options.ToList().ForEach(x => action.AddButton(x.Text));
            var index = config.Options.Count - 1;

            if (config.Destructive != null)
            {
                index++;
                action.AddButton(config.Destructive.Text);
                action.DestructiveButtonIndex = index;
            }

            if (config.Cancel != null)
            {
                index++;
                action.AddButton(config.Cancel.Text);
                action.CancelButtonIndex = index;
            }

            action.Dismissed += (sender, btn) => {
                if (btn.ButtonIndex == action.DestructiveButtonIndex)
                {
                    config.Destructive.Action?.Invoke();
                }

                else if (btn.ButtonIndex == action.CancelButtonIndex)
                {
                    config.Cancel.Action?.Invoke();
                }

                else if (btn.ButtonIndex > -1)
                {
                    config.Options[(int)btn.ButtonIndex].Action?.Invoke();
                }
            };
            UIApplication.SharedApplication.InvokeOnMainThread(() => action.ShowInView(view));
        }
Exemplo n.º 25
0
        public override IDisposable ActionSheet(ActionSheetConfig config)
        {
            var dlg = new ActionSheetContentDialog();

            var vm = new ActionSheetViewModel
            {
                Title   = config.Title,
                Message = config.Message,
                Cancel  = new ActionSheetOptionViewModel(config.Cancel != null, config.Cancel?.Text, () =>
                {
                    dlg.Hide();
                    config.Cancel?.Action?.Invoke();
                }),

                Destructive = new ActionSheetOptionViewModel(config.Destructive != null, config.Destructive?.Text, () =>
                {
                    dlg.Hide();
                    config.Destructive?.Action?.Invoke();
                }),

                Options = config
                          .Options
                          .Select(x => new ActionSheetOptionViewModel(true, x.Text, () =>
                {
                    dlg.Hide();
                    x.Action?.Invoke();
                }, x.ItemIcon ?? config.ItemIcon))
                          .ToList()
            };

            dlg.DataContext = vm;
            IAsyncOperation <ContentDialogResult> dialogTask = null;

            return(this.DispatchAndDispose(
                       //config.UwpSubmitOnEnterKey,
                       //config.UwpCancelOnEscKey,
                       () => dialogTask = dlg.ShowAsync(),
                       () => dialogTask?.Cancel()
                       ));
        }
Exemplo n.º 26
0
        public override void ActionSheet(ActionSheetConfig config)
        {
            var array = config
                .Options
                .Select(x => x.Text)
                .ToArray();

            var dlg = new AlertDialog
                .Builder(this.getTopActivity())
                .SetCancelable(false)
                .SetTitle(config.Title);

            dlg.SetItems(array, (sender, args) => config.Options[args.Which].Action.TryExecute());

            if (config.Destructive != null)
                dlg.SetNegativeButton(config.Destructive.Text, (sender, e) => config.Destructive.Action.TryExecute());

            if (config.Cancel != null)
                dlg.SetNeutralButton(config.Cancel.Text, (sender, e) => config.Cancel.Action.TryExecute());

            Utils.RequestMainThread(() => dlg.Show());
        }
        public override IDisposable ActionSheet(ActionSheetConfig config)
        {
            var dlg = new TaskDialog {
                AllowDialogCancellation = config.Cancel != null,
                WindowTitle             = config.Title
            };

            config
            .Options
            .ToList()
            .ForEach(x =>
                     dlg.Buttons.Add(new TaskDialogButton(x.Text)
                                     ));

            dlg.ButtonClicked += (sender, args) =>
            {
                var action = config.Options.First(x => x.Text.Equals(args.Item.Text));
                action.Action();
            };
            dlg.ShowDialog();
            return(new DisposableAction(dlg.Dispose));
        }
Exemplo n.º 28
0
        public override IDisposable ActionSheet(ActionSheetConfig config)
        {
            var dlg = new TaskDialog
            {
                AllowDialogCancellation = config.Cancel != null,
                WindowTitle = config.Title
            };
            config
                .Options
                .ToList()
                .ForEach(x =>
                    dlg.Buttons.Add(new TaskDialogButton(x.Text)
                ));

            dlg.ButtonClicked += (sender, args) =>
            {
                var action = config.Options.First(x => x.Text.Equals(args.Item.Text));
                action.Action();
            };
            dlg.ShowDialog();
            return new DisposableAction(dlg.Dispose);
        }
Exemplo n.º 29
0
        public override void ActionSheet(ActionSheetConfig config)
        {
            var sheet = new CustomMessageBox {
                Caption              = config.Title,
                IsLeftButtonEnabled  = false,
                IsRightButtonEnabled = false
            };
            var list = new ListBox {
                FontSize      = 36,
                Margin        = new Thickness(12.0),
                SelectionMode = SelectionMode.Single,
                ItemsSource   = config.Options
                                .Select(x => new TextBlock {
                    Text        = x.Text,
                    Margin      = new Thickness(0.0, 12.0, 0.0, 12.0),
                    DataContext = x
                })
            };

            list.SelectionChanged += (sender, args) => sheet.Dismiss();
            sheet.Content          = new ScrollViewer {
                Content = list
            };
            sheet.Dismissed += (sender, args) => {
                var txt = list.SelectedValue as TextBlock;
                if (txt == null)
                {
                    return;
                }

                var action = txt.DataContext as ActionSheetOption;
                if (action != null && action.Action != null)
                {
                    action.Action();
                }
            };
            this.Dispatch(sheet.Show);
        }
Exemplo n.º 30
0
        public override IDisposable ActionSheet(ActionSheetConfig config)
        {
            var dlg = new ActionSheetContentDialog();

            var vm = new ActionSheetViewModel
            {
                Title = config.Title,
                Message = config.Message,
                Cancel = new ActionSheetOptionViewModel(config.Cancel != null, config.Cancel?.Text, () =>
                {
                    dlg.Hide();
                    config.Cancel?.Action?.Invoke();
                }),

                Destructive = new ActionSheetOptionViewModel(config.Destructive != null, config.Destructive?.Text, () =>
                {
                    dlg.Hide();
                    config.Destructive?.Action?.Invoke();
                }),

                Options = config
                    .Options
                    .Select(x => new ActionSheetOptionViewModel(true, x.Text, () =>
                    {
                        dlg.Hide();
                        x.Action?.Invoke();
                    }, x.ItemIcon ?? config.ItemIcon))
                    .ToList()
            };

            dlg.DataContext = vm;
            IAsyncOperation<ContentDialogResult> dialogTask = null;

            return this.DispatchAndDispose(
                () => dialogTask = dlg.ShowAsync(),
                () => dialogTask?.Cancel()
            );
        }
Exemplo n.º 31
0
        protected virtual NSAlert CreateNativeActionSheet(ActionSheetConfig config)
        {
            var alert = new NSAlert
            {
                AlertStyle      = NSAlertStyle.Informational,
                MessageText     = config.Title ?? string.Empty,
                InformativeText = config.Message ?? string.Empty
            };

            if (config.Cancel != null)
            {
                alert.AddButton(config.Cancel.Text);
            }

            var extraSpace = config.Destructive == null ? 30 : 60;
            var inputView  = new NSStackView(new CGRect(0, 0, 200, (config.Options.Count * 30) + extraSpace));

            var yPos = config.Options.Count * 30 + (config.Destructive == null ? 0 : 1) * 30;

            foreach (var item in config.Options)
            {
                this.AddActionSheetOption(item, alert.Window, inputView, yPos);
                yPos -= 30;
            }

            if (config.Destructive != null)
            {
                this.AddActionSheetOption(config.Destructive, alert.Window, inputView, yPos, true);
            }

            alert.AccessoryView = inputView;
            alert.Layout();

            alert.BeginSheetForResponse(this.windowFunc(), _ => { });
            return(alert);
        }
Exemplo n.º 32
0
 public override void ActionSheet(ActionSheetConfig config)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 33
0
        protected virtual UIAlertController CreateNativeActionSheet(ActionSheetConfig config)
        {
            var sheet = UIAlertController.Create(config.Title, config.Message, UIAlertControllerStyle.ActionSheet);

            if (config.Destructive != null)
                this.AddActionSheetOption(config.Destructive, sheet, UIAlertActionStyle.Destructive);

            config
                .Options
                .ToList()
                .ForEach(x => this.AddActionSheetOption(x, sheet, UIAlertActionStyle.Default, config.ItemIcon));

            if (config.Cancel != null)
                this.AddActionSheetOption(config.Cancel, sheet, UIAlertActionStyle.Cancel);

            return sheet;
        }
        public override IDisposable ActionSheet(ActionSheetConfig config)
        {
            var positive = new XButton();
            var negative = new XButton();

            var template = new DataTemplate(typeof(TextCell));

            template.SetBinding(TextCell.TextProperty, "Text");
            template.SetBinding(ImageCell.ImageSourceProperty, "ItemIcon");
            ListView lv = new ListView()
            {
                ItemsSource   = config.Options,
                ItemTemplate  = template,
                HeightRequest = 144 * config.Options.Count
            };
            var layout = new StackLayout
            {
                Children =
                {
                    lv,
                },
                Padding = 30
            };
            var dialog = new Dialog()
            {
                Title            = config.Title,
                Subtitle         = config.Message,
                Content          = layout,
                HorizontalOption = LayoutOptions.Center,
                VerticalOption   = LayoutOptions.Center,
            };

            if (config.Destructive?.Text != null)
            {
                positive.Text   = config.Destructive?.Text;
                dialog.Positive = positive;
            }
            if (config.Cancel?.Text != null)
            {
                negative.Text   = config.Cancel?.Text;
                dialog.Negative = negative;
            }
            lv.ItemSelected += (s, e) =>
            {
                if (e.SelectedItem != null)
                {
                    dialog.Hide();
                    config.Options[config.Options.IndexOf(e.SelectedItem)]?.Action?.Invoke();
                }
            };
            dialog.OutsideClicked += (s, e) =>
            {
                dialog.Hide();
            };
            positive.Clicked += (s, e) =>
            {
                dialog.Hide();
                config.Destructive?.Action?.Invoke();
            };
            negative.Clicked += (s, e) =>
            {
                dialog.Hide();
                config.Cancel?.Action?.Invoke();
            };
            dialog.Show();
            return(new DisposableAction(() =>
            {
                dialog.Hide();
                config.Cancel?.Action?.Invoke();
            }));
        }
Exemplo n.º 35
0
 public override IDisposable ActionSheet(ActionSheetConfig config) => this.Present(() => this.CreateNativeActionSheet(config));
Exemplo n.º 36
0
 public override IDisposable ActionSheet(ActionSheetConfig config)
 {
     throw new NotImplementedException ();
 }
Exemplo n.º 37
0
 public override IDisposable ActionSheet(ActionSheetConfig config)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 38
0
 public override IDisposable ActionSheet(ActionSheetConfig config)
 {
     return this.Present(() => this.CreateNativeActionSheet(config));
 }
Exemplo n.º 39
0
        private void ActionSheet() {
			var cfg = new ActionSheetConfig()
				.SetTitle("Test Title");

            for (var i = 0; i < 5; i++) {
                var display = (i + 1);
                cfg.Add(
					"Option " + display, 
					() => this.lblResult.Text = String.Format("Option {0} Selected", display)
				);
            }
			cfg.SetDestructive(action: () => this.lblResult.Text = "Destructive BOOM Selected");
			cfg.SetCancel(action: () => this.lblResult.Text = "Cancel Selected");

            UserDialogs.Instance.ActionSheet(cfg);
        }
 public ActionSheetListAdapter(Context context, int resource, int textViewResourceId, ActionSheetConfig config) : base(context, resource, textViewResourceId, config.Options)
 {
     this.config = config;
 }
Exemplo n.º 41
0
        void ActionSheet() {
			var cfg = new ActionSheetConfig()
				.SetTitle("Test Title");

            var testImage = BitmapLoader.Current.LoadFromResource("icon.png", null, null).Result;

            for (var i = 0; i < 5; i++) {
                var display = (i + 1);
                cfg.Add(
					"Option " + display,
					() => this.Result($"Option {display} Selected"),
                    testImage
                );
            }
			cfg.SetDestructive(action: () => this.Result("Destructive BOOM Selected"));
			cfg.SetCancel(action: () => this.Result("Cancel Selected"));

            UserDialogs.Instance.ActionSheet(cfg);
        }
Exemplo n.º 42
0
 public abstract void ActionSheet(ActionSheetConfig config);
Exemplo n.º 43
0
 public abstract IDisposable ActionSheet(ActionSheetConfig config);
Exemplo n.º 44
0
        protected virtual void ShowIOS8ActionSheet(ActionSheetConfig config)
        {
            var sheet = UIAlertController.Create(config.Title, null, UIAlertControllerStyle.ActionSheet);
            config
                .Options
                .ToList()
                .ForEach(x => this.AddActionSheetOption(x, sheet, UIAlertActionStyle.Default, config.ItemIcon));

            if (config.Destructive != null)
                this.AddActionSheetOption(config.Destructive, sheet, UIAlertActionStyle.Destructive);

            if (config.Cancel != null)
                this.AddActionSheetOption(config.Cancel, sheet, UIAlertActionStyle.Cancel);

            this.Present(sheet);
        }
Exemplo n.º 45
0
        protected virtual void ShowIOS7ActionSheet(ActionSheetConfig config)
        {
            var view = UIApplication.SharedApplication.GetTopView();
            var action = new UIActionSheet(config.Title);
            config.Options.ToList().ForEach(x => action.AddButton(x.Text));
            var index = config.Options.Count - 1;

            if (config.Destructive != null) {
                index++;
                action.AddButton(config.Destructive.Text);
                action.DestructiveButtonIndex = index;
            }

            if (config.Cancel != null) {
                index++;
                action.AddButton(config.Cancel.Text);
                action.CancelButtonIndex = index;
            }

            action.Dismissed += (sender, btn) => {
                if (btn.ButtonIndex == action.DestructiveButtonIndex)
                    config.Destructive.Action?.Invoke();

                else if (btn.ButtonIndex == action.CancelButtonIndex)
                    config.Cancel.Action?.Invoke();

                else if (btn.ButtonIndex > -1)
                    config.Options[(int)btn.ButtonIndex].Action?.Invoke();
            };
            UIApplication.SharedApplication.InvokeOnMainThread(() => action.ShowInView(view));
        }
Exemplo n.º 46
0
 public abstract void ActionSheet(ActionSheetConfig config);
Exemplo n.º 47
0
        ICommand CreateActionSheetCommand(bool useBottomSheet, bool cancel, int items, string message = null)
        {
            return new Command(() =>
            {
                var cfg = new ActionSheetConfig()
                    .SetTitle("Test Title")
                    .SetMessage(message)
                    .SetUseBottomSheet(useBottomSheet);

                IBitmap testImage = null;
                try
                {
                    testImage = BitmapLoader.Current.LoadFromResource("icon.png", null, null).Result;
                }
                catch
                {
                    Debug.WriteLine("Could not load image");
                }

                for (var i = 0; i < items; i++)
                {
                    var display = i + 1;
                    cfg.Add(
                        "Option " + display,
                        () => this.Result($"Option {display} Selected"),
                        testImage
                    );
                }
                cfg.SetDestructive(null, () => this.Result("Destructive BOOM Selected"), testImage);
                if (cancel)
                    cfg.SetCancel(null, () => this.Result("Cancel Selected"), testImage);

                var disp = this.Dialogs.ActionSheet(cfg);
                if (this.AutoCancel)
                {
                    Task.Delay(TimeSpan.FromSeconds(3))
                        .ContinueWith(x => disp.Dispose());
                }
            });
        }
Exemplo n.º 48
0
        public override IDisposable ActionSheet(ActionSheetConfig config)
        {
            var sheet = this.CreateNativeActionSheet(config);

            return(this.Present(sheet));
        }
Exemplo n.º 49
0
        void ActionSheet() {
			var cfg = new ActionSheetConfig()
				.SetTitle("Test Title");

            for (var i = 0; i < 5; i++) {
                var display = (i + 1);
                cfg.Add(
					"Option " + display,
					() => this.Result($"Option {display} Selected")
				);
            }
			cfg.SetDestructive(action: () => this.Result("Destructive BOOM Selected"));
			cfg.SetCancel(action: () => this.Result("Cancel Selected"));

            UserDialogs.Instance.ActionSheet(cfg);
        }