Skip to content

Commit

Permalink
Hide zoom buttons if not zoomable (#1002)
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharykeeping authored Aug 26, 2024
1 parent b3993bc commit c7d9c21
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
15 changes: 14 additions & 1 deletion src/MobileUI/Features/Scanner/ScanPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:scanner="clr-namespace:BarcodeScanning;assembly=BarcodeScanning.Native.Maui"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
BackgroundColor="{StaticResource Background}"
x:Class="SSW.Rewards.Mobile.Pages.ScanPage"
x:Name="this">
<ContentPage.Resources>
<ResourceDictionary>
<x:Single x:Key="Threshold">1</x:Single>

<toolkit:CompareConverter
x:Key="GreaterThanOne"
ComparisonOperator="Greater"
ComparingValue="{StaticResource Threshold}" />
</ResourceDictionary>
</ContentPage.Resources>
<Grid>
<scanner:CameraView x:Name="scannerView"
<scanner:CameraView x:Name="ScannerView"
OnDetectionFinished="Handle_OnScanResult"
BarcodeSymbologies="QRCode"
ViewfinderMode="True"
Expand All @@ -32,8 +43,10 @@
<Grid VerticalOptions="End"
RowDefinitions="Auto,*">
<Grid Grid.Row="0"
x:Name="ZoomButtons"
ColumnDefinitions="Auto,Auto"
HorizontalOptions="Center"
IsVisible="{Binding MaxZoomFactor, Converter={StaticResource GreaterThanOne}, Source={x:Reference ScannerView}, Path=MaxZoomFactor}"
ColumnSpacing="40">
<Button Grid.Column="0"
CornerRadius="30"
Expand Down
20 changes: 10 additions & 10 deletions src/MobileUI/Features/Scanner/ScanPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ 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)
if (!ScannerView.CameraEnabled || e.BarcodeResults.Length == 0)
{
return;
}
Expand All @@ -43,9 +43,9 @@ protected override void OnDisappearing()
base.OnDisappearing();

// Reset zoom when exiting camera
if (scannerView.CurrentZoomFactor > -1)
if (ScannerView.CurrentZoomFactor > -1)
{
scannerView.RequestZoomFactor = scannerView.MinZoomFactor;
ScannerView.RequestZoomFactor = ScannerView.MinZoomFactor;
}

ToggleScanner(false);
Expand All @@ -69,7 +69,7 @@ public void Receive(EnableScannerMessage message)

private void ToggleScanner(bool toggleOn)
{
scannerView.CameraEnabled = toggleOn;
ScannerView.CameraEnabled = toggleOn;
}

[RelayCommand]
Expand All @@ -85,18 +85,18 @@ private async Task Dismiss()
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;
var currentZoom = Math.Max(ScannerView.CurrentZoomFactor, ScannerView.MinZoomFactor);
var maxZoom = ScannerView.MaxZoomFactor;

scannerView.RequestZoomFactor = Math.Min(currentZoom + ZoomFactorStep, maxZoom);
ScannerView.RequestZoomFactor = Math.Min(currentZoom + ZoomFactorStep, maxZoom);
}

[RelayCommand]
private void ZoomOut()
{
var currentZoom = scannerView.CurrentZoomFactor;
var minZoom = scannerView.MinZoomFactor;
var currentZoom = ScannerView.CurrentZoomFactor;
var minZoom = ScannerView.MinZoomFactor;

scannerView.RequestZoomFactor = Math.Max(currentZoom - ZoomFactorStep, minZoom);
ScannerView.RequestZoomFactor = Math.Max(currentZoom - ZoomFactorStep, minZoom);
}
}

0 comments on commit c7d9c21

Please sign in to comment.