Example #1
0
            void OnActionSheetRequested(Page sender, ActionSheetArguments arguments)
            {
                // Verify that the page making the request is part of this activity
                if (!PageIsInThisContext(sender))
                {
                    return;
                }

                var builder = new DialogBuilder(Activity);

                builder.SetTitle(arguments.Title);
                string[] items = arguments.Buttons.ToArray();
                builder.SetItems(items, (o, args) => arguments.Result.TrySetResult(items[args.Which]));

                if (arguments.Cancel != null)
                {
                    builder.SetPositiveButton(arguments.Cancel, (o, args) => arguments.Result.TrySetResult(arguments.Cancel));
                }

                if (arguments.Destruction != null)
                {
                    builder.SetNegativeButton(arguments.Destruction, (o, args) => arguments.Result.TrySetResult(arguments.Destruction));
                }

                var dialog = builder.Create();

                builder.Dispose();
                //to match current functionality of renderer we set cancelable on outside
                //and return null
                dialog.SetCanceledOnTouchOutside(true);
                dialog.SetCancelEvent((o, e) => arguments.SetResult(null));
                dialog.Show();
            }
Example #2
0
            void OnActionSheetRequested(Page sender, ActionSheetArguments arguments)
            {
                // Verify that the page making the request is part of this activity
                if (!PageIsInThisContext(sender))
                {
                    return;
                }

                var builder = new DialogBuilder(Activity);

                builder.SetTitle(arguments.Title);
                string[] items = arguments.Buttons.ToArray();
                builder.SetItems(items, (o, args) => arguments.Result.TrySetResult(items[args.Which]));

                if (arguments.Cancel != null)
                {
                    builder.SetPositiveButton(arguments.Cancel, (o, args) => arguments.Result.TrySetResult(arguments.Cancel));
                }

                if (arguments.Destruction != null)
                {
                    builder.SetNegativeButton(arguments.Destruction, (o, args) => arguments.Result.TrySetResult(arguments.Destruction));
                }

                var dialog = builder.Create();

                builder.Dispose();
                //to match current functionality of renderer we set cancelable on outside
                //and return null
                if (arguments.FlowDirection == FlowDirection.MatchParent && sender is IVisualElementController ve)
                {
                    dialog.Window.DecorView.UpdateFlowDirection(ve);
                }
                else if (arguments.FlowDirection == FlowDirection.LeftToRight)
                {
                    dialog.Window.DecorView.LayoutDirection = LayoutDirection.Ltr;
                }
                else if (arguments.FlowDirection == FlowDirection.RightToLeft)
                {
                    dialog.Window.DecorView.LayoutDirection = LayoutDirection.Rtl;
                }

                dialog.SetCanceledOnTouchOutside(true);
                dialog.SetCancelEvent((o, e) => arguments.SetResult(null));
                dialog.Show();

                dialog.GetListView().TextDirection = GetTextDirection(sender, arguments.FlowDirection);
                LayoutDirection layoutDirection    = GetLayoutDirection(sender, arguments.FlowDirection);

                if (arguments.Cancel != null)
                {
                    ((dialog.GetButton((int)DialogButtonType.Positive).Parent) as global::Android.Views.View).LayoutDirection = layoutDirection;
                }
                if (arguments.Destruction != null)
                {
                    ((dialog.GetButton((int)DialogButtonType.Negative).Parent) as global::Android.Views.View).LayoutDirection = layoutDirection;
                }
            }