Help needed on BACK functionality(in iOS) from barcode scan page using Zxing.Net

sujithmsujithm Member ✭✭

I have added barcode scanning functionality(as below) to one of my viewmodel(following mvvm architecture). I have added it as a modal page from my view model.
I am struggling on how to add BACK functionality as there is no default back option on iOS.
It is ok in android as it will have its default device back button so that the user can go back to previous page. I having some trouble in finding the right answer on how i need to add a custom back functionality.

public ICommand CaptureBarcodeCommand => new Command(OnCaptureBarcodeCommand);
private async void OnCaptureBarcodeCommand(object obj)
{
var scanPage = new ZXingScannerPage();

scanPage.OnScanResult += (result) => 
{
    // Stop scanning
    scanPage.IsScanning = false;

    // Pop the page and show the result
    Device.BeginInvokeOnMainThread (async () => 
    {
        await _navigationService.PopModalAsync();
        var barcode = result.Text;
        if (IsBarcodePartOfOrder(barcode))
        {
            UpdateBarcodePickedQty(barcode);
        }
        else
        {
            await _dialogService.ShowDialog(string.Format(AppResources.rejectpopupinvalidbarcode, barcode), AppResources.invalid, AppResources.ok);
        }
    });
};
await _navigationService.PushModalAsync(scanPage)

}

And in NavigationService:

public async Task PushModalAsync(Page page)
{
if (CurrentApplication.MainPage is MainView mainPage)
{
await mainPage.Detail.Navigation.PushModalAsync(page);
}
}

public async Task PopModalAsync()
{
if (CurrentApplication.MainPage is MainView mainPage)
{
await mainPage.Detail.Navigation.PopModalAsync();
}
}

I can add this ZXing scanner page as a new page instead of modal, but if i add it as a new page then how do i pass scanned data back to the previous page?. Please assist on above. Hope i have given all the info needed.

Sign In or Register to comment.