-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Mobile | Add user's QR code to scanner page (#1018)
* Move to ViewModel * Implement changes from Betty * Fix reticle * Fix camera on new launch if other tab is active
- Loading branch information
1 parent
bf0b374
commit dee5a26
Showing
7 changed files
with
280 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,29 @@ | ||
using BarcodeScanning; | ||
using CommunityToolkit.Mvvm.Input; | ||
using CommunityToolkit.Mvvm.Messaging; | ||
using Mopups.Services; | ||
using SSW.Rewards.Mobile.Messages; | ||
namespace SSW.Rewards.Mobile.Pages; | ||
|
||
namespace SSW.Rewards.Mobile.Pages; | ||
|
||
public partial class ScanPage : IRecipient<EnableScannerMessage> | ||
public partial class ScanPage | ||
{ | ||
private readonly ScanResultViewModel _viewModel; | ||
private readonly ScanViewModel _viewModel; | ||
private readonly IFirebaseAnalyticsService _firebaseAnalyticsService; | ||
private const float ZoomFactorStep = 1.0f; | ||
|
||
public ScanPage(ScanResultViewModel viewModel, IFirebaseAnalyticsService firebaseAnalyticsService) | ||
|
||
public ScanPage(ScanViewModel viewModel, IFirebaseAnalyticsService firebaseAnalyticsService) | ||
{ | ||
InitializeComponent(); | ||
_viewModel = viewModel; | ||
_viewModel.Navigation = Navigation; | ||
_firebaseAnalyticsService = firebaseAnalyticsService; | ||
} | ||
|
||
private void Handle_OnScanResult(object sender, OnDetectionFinishedEventArg e) | ||
{ | ||
// the handler is called on a thread-pool thread | ||
App.Current.Dispatcher.Dispatch(() => | ||
{ | ||
if (!ScannerView.CameraEnabled || e.BarcodeResults.Length == 0) | ||
{ | ||
return; | ||
} | ||
|
||
ToggleScanner(false); | ||
|
||
var result = e.BarcodeResults.FirstOrDefault()?.RawValue; | ||
|
||
var popup = new PopupPages.ScanResult(_viewModel, result); | ||
MopupService.Instance.PushAsync(popup); | ||
}); | ||
BindingContext = _viewModel; | ||
} | ||
|
||
protected override void OnDisappearing() | ||
{ | ||
base.OnDisappearing(); | ||
|
||
// Reset zoom when exiting camera | ||
if (ScannerView.CurrentZoomFactor > -1) | ||
{ | ||
ScannerView.RequestZoomFactor = ScannerView.MinZoomFactor; | ||
} | ||
|
||
ToggleScanner(false); | ||
WeakReferenceMessenger.Default.Unregister<EnableScannerMessage>(this); | ||
_viewModel.OnDisappearing(); | ||
} | ||
|
||
protected override void OnAppearing() | ||
{ | ||
base.OnAppearing(); | ||
_viewModel.OnAppearing(); | ||
_firebaseAnalyticsService.Log("ScanPage"); | ||
WeakReferenceMessenger.Default.Register(this); | ||
|
||
ToggleScanner(true); | ||
} | ||
|
||
|
||
public void Receive(EnableScannerMessage message) | ||
{ | ||
ToggleScanner(true); | ||
} | ||
|
||
private void ToggleScanner(bool toggleOn) | ||
{ | ||
ScannerView.CameraEnabled = toggleOn; | ||
} | ||
|
||
[RelayCommand] | ||
private async Task Dismiss() | ||
{ | ||
if (Navigation.ModalStack.Count > 0) | ||
{ | ||
await Navigation.PopModalAsync(); | ||
} | ||
} | ||
|
||
[RelayCommand] | ||
private void ZoomIn() | ||
{ | ||
// CurrentZoomFactor can default to -1, so we start at the MinZoomFactor in this case | ||
var currentZoom = Math.Max(ScannerView.CurrentZoomFactor, ScannerView.MinZoomFactor); | ||
var maxZoom = ScannerView.MaxZoomFactor; | ||
|
||
ScannerView.RequestZoomFactor = Math.Min(currentZoom + ZoomFactorStep, maxZoom); | ||
} | ||
|
||
[RelayCommand] | ||
private void ZoomOut() | ||
{ | ||
var currentZoom = ScannerView.CurrentZoomFactor; | ||
var minZoom = ScannerView.MinZoomFactor; | ||
|
||
ScannerView.RequestZoomFactor = Math.Max(currentZoom - ZoomFactorStep, minZoom); | ||
} | ||
} |
Oops, something went wrong.