CustomActionIos.cs 1.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
using System;
using System.Diagnostics;
using Foundation;
using ObjCRuntime;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using XAMARINCustomAction.iOS;

[assembly: Dependency(typeof(CustomActionIos))]
namespace XAMARINCustomAction.iOS
{
    public class CustomActionIos : ICustomAction
    {
        MainPage mainpage;

        public void initAccessibility(MainPage page)
        {
            mainpage = page;
            var iospage = page.GetRenderer().ViewController;

22 23
            UIAccessibilityCustomAction up = new UIAccessibilityCustomAction("Increment", actionHandler: Increment);
            UIAccessibilityCustomAction down = new UIAccessibilityCustomAction("Decrement", actionHandler: Decrement);
24
            iospage.AccessibilityCustomActions = new UIAccessibilityCustomAction[2] { up, down };
25
            Debug.WriteLine($"PIPPO: DS, counter = {MainPage.counter.Text}");
26 27 28

        }

29 30
        private bool Increment(UIAccessibilityCustomAction customAction)
        {
31 32
            int n = Int32.Parse(MainPage.counter.Text);
            n++;
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
            Debug.WriteLine("PIPPO: clicked increment");
            MainPage.counter.Text = "" + (n);
            return true;
        }

        private bool Decrement(UIAccessibilityCustomAction customAction)
        {
            int n = Int32.Parse(MainPage.counter.Text);
            if (n <= 0)
            {
                return false;
            }
            Debug.WriteLine("PIPPO: clicked decrement");
            n--;
            MainPage.counter.Text = "" + (n);
            return true;
        }

51 52
    }
}