Acr UserDialogs ActionSheet

ledragonledragon Member ✭✭✭

Hi,

I'm using an Acr UserDialog ActionSheet to display a pop up with a couple of options for user selection:

private void SpeechClicked(RFIDto rfiDto)
    {
        if (!CrossConnectivity.Current.IsConnected) //Only allow if Device has connection
        {
            _userDialog.Alert("You must have a connection to use the Speech To Text feature.", "No Connection", "OK");

            return;
        }

        var _speechRecongnitionInstance = DependencyService.Get<ISpeechToText>();

        MessagingCenter.Subscribe<IMessageSender, string>(this, "STT", (sender, args) =>
        {
            var config = new ActionSheetConfig
            {
                Cancel = new ActionSheetOption("Cancel"),
                Title = "Save Speech"
            };

            config.Add("Append", new Action(async () =>
            {
                rfiDto.Response = $"{rfiDto.Response} {args}";
                await SaveEntryText(rfiDto);
            }));

            config.Add("Replace", new Action(async () =>
            {
                rfiDto.Response = args;
                await SaveEntryText(rfiDto);
            }));

            var speechDialog = UserDialogs.Instance.ActionSheet(config);
        });

        _speechRecongnitionInstance.StartSpeechToText();
    }

I'm getting some weird behaviour whereby each time I invoke the SpeechClicked command the number of clicks required on an actionsheet option to dismiss the dialog increases incrementally.

i.e. I click the button that invokes the SpeechClicked command, then select either Append or Replace once and the dialog is dismissed.

I click the button for a second time and the Append or Replace option must be clicked twice to dismiss although the dialog although the Action is called each time I click.

I click the button for a third time and the Append or Replace option must be clicked three times to dismiss although the dialog although the Action is called each time I click.

...and so on.

Any help would be much appreciated.

Best Answers

  • GuillermoTinocoGuillermoTinoco MX ✭✭
    Accepted Answer

    I think it's because you're subscribing every time you enter the SpeechClicked method. So try unsubscribing from the messaging center before subscribing:

    MessagingCenter.Unsubscribe<IMessageSender> (this, "STT");
    
    MessagingCenter.Subscribe<IMessageSender, string>(this, "STT", (sender, args) => 
    {
        //awesome code
    });
    

Answers

  • GuillermoTinocoGuillermoTinoco MXMember ✭✭
    Accepted Answer

    I think it's because you're subscribing every time you enter the SpeechClicked method. So try unsubscribing from the messaging center before subscribing:

    MessagingCenter.Unsubscribe<IMessageSender> (this, "STT");
    
    MessagingCenter.Subscribe<IMessageSender, string>(this, "STT", (sender, args) => 
    {
        //awesome code
    });
    
  • ledragonledragon Member ✭✭✭

    Bingo! You, sirs, are both gentlemen of the highest order! Thanks muchly!

Sign In or Register to comment.