public void CreateActionSheetOptionFromEnumValue()
        {
            var option = ActionSheetOption.FromOption(TestEnum.One);

            Assert.AreEqual(option.Value, TestEnum.One);
            Assert.AreEqual("One", option.Title);
        }
        public void CreateActionSheetOptionFromEnumValueWithDescription()
        {
            var option = ActionSheetOption.FromOption(TestEnum.Three);

            Assert.AreEqual(option.Value, TestEnum.Three);
            Assert.AreEqual("Tester", option.Title);
        }
Ejemplo n.º 3
0
        private UIView CreateActionItem(ActionSheetOption option)
        {
            var view = new UIStackView
            {
                Alignment        = UIStackViewAlignment.Center,
                AutoresizingMask = UIViewAutoresizing.All,
                Distribution     = UIStackViewDistribution.Fill,
                Axis             = UILayoutConstraintAxis.Horizontal
            };

            var tap = new UITapGestureRecognizer(() =>
            {
                try
                {
                    option.Action();
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("ActionSheet in action (" + option.Text + ") exception: " + e);
                }
                finally
                {
                    this.DismissController();
                }
            });

            view.AddGestureRecognizer(tap);

            if (option.ItemIcon != null)
            {
                var image = UIImage.FromImage(option.ItemIcon.ToNative().CGImage);

                var imageView = new UIImageView
                {
                    Image              = image,
                    BackgroundColor    = UIColor.Clear,
                    ContentMode        = UIViewContentMode.Center,
                    ContentScaleFactor = 2
                };

                imageView.HeightAnchor.ConstraintEqualTo(RowHeight).Active = true;
                imageView.WidthAnchor.ConstraintEqualTo(RowHeight).Active  = true;

                view.AddArrangedSubview(imageView);
            }

            var textView = new UILabel
            {
                Text            = option.Text,
                BackgroundColor = UIColor.Clear,
                TextColor       = MainTextUiColor,
                TextAlignment   = UITextAlignment.Left
            };

            textView.HeightAnchor.ConstraintEqualTo(RowHeight).Active = true;

            view.AddArrangedSubview(textView);

            return(view);
        }
Ejemplo n.º 4
0
        private UIView CreateCancelView(ActionSheetOption option = null)
        {
            var button = new UIButton(UIButtonType.Custom)
            {
                BackgroundColor     = UIColor.Clear,
                AutoresizingMask    = UIViewAutoresizing.All,
                HorizontalAlignment = UIControlContentHorizontalAlignment.Right,
                TitleEdgeInsets     = new UIEdgeInsets(0, 0, 0, 30)
            };

            button.SetTitle(string.IsNullOrEmpty(option?.Text) ? "Cancel" : option.Text, UIControlState.Normal);
            button.SetTitleColor(ButtonTextUiColor, UIControlState.Normal);
            button.AddTarget((x, y) =>
            {
                try
                {
                    option?.Action?.Invoke();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                finally
                {
                    DismissController();
                }
            }, UIControlEvent.TouchUpInside);

            button.HeightAnchor.ConstraintEqualTo(RowHeight).Active = true;

            return(button);
        }
Ejemplo n.º 5
0
        private void TouchedPicture()
        {
            IUserDialogs             userDialogs = UserDialogs.Instance;
            ActionSheetConfig        config      = new ActionSheetConfig();
            List <ActionSheetOption> Options     = new List <ActionSheetOption>();

            Options.Add(new ActionSheetOption(AppResource.pick_at_gallery, OpenGallery, ListOfNames.pictureForFolder));
            Options.Add(new ActionSheetOption(AppResource.take_photo_with_camera, TakePhoto, ListOfNames.pictureForCamera));
            ActionSheetOption cancel = new ActionSheetOption(AppResource.cancel.ToUpper(), null, null);

            config.Options = Options;
            config.Cancel  = cancel;
            userDialogs.ActionSheet(config);
        }
        protected virtual void AddActionSheetOption(ActionSheetOption opt, UIAlertController controller, UIAlertActionStyle style, IBitmap image = null)
        {
            var alertAction = UIAlertAction.Create(opt.Text, style, x => opt.Action?.Invoke());

            if (opt.ItemIcon == null && image != null)
            {
                opt.ItemIcon = image;
            }

            if (opt.ItemIcon != null)
            {
                alertAction.SetValueForKey(opt.ItemIcon.ToNative(), new NSString("image"));
            }

            controller.AddAction(alertAction);
        }
        public void ActionSheet(JsValue title, JsValue options, JsValue callback)
        {
            var config = new ActionSheetConfig();

            config.Title = title.AsString();

            List <ActionSheetOption> choices = new List <ActionSheetOption>();

            foreach (var option in options.AsArray())
            {
                var choice = new ActionSheetOption(option.AsString(), () => callback.Invoke(option.AsString()));
                choices.Add(choice);
            }

            config.Options = choices;

            Acr.UserDialogs.UserDialogs.Instance.ActionSheet(config);
        }
        protected virtual View CreateRow(ActionSheetOption action, bool isDestructive)
        {
            var row = new LinearLayout(this.Activity)
            {
                Clickable        = true,
                Orientation      = Orientation.Horizontal,
                LayoutParameters = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, this.DpToPixels(48))
            };

            if (action.ItemIcon != null)
            {
                row.AddView(this.GetIcon(action.ItemIcon));
            }

            row.AddView(this.GetText(action.Text, isDestructive));
            row.Click += (sender, args) =>
            {
                action.Action?.Invoke();
                this.Dismiss();
            };
            return(row);
        }
Ejemplo n.º 9
0
 public void AddCancel(string title)
 {
     Cancel = new ActionSheetOption(title, () => ActionSheetSelected(default(T)));
 }
        public override void Execute(object param = null)
        {
            ActionSheetOption actionSheetOption = (ActionSheetOption)param;

            m_BotMessenger.SendMessageAsync(null, actionSheetOption.message);
        }