Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update iOS to use modern UIAlertController. Switch to .NET7. #4

Merged
merged 5 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion UserInteractionDemo/AppShell.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="UserInteractionDemo.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
Expand All @@ -11,4 +11,5 @@
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" />


</Shell>
2 changes: 2 additions & 0 deletions UserInteractionDemo/AppShell.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ public partial class AppShell : Shell
public AppShell()
{
InitializeComponent();

Routing.RegisterRoute($"{nameof(Child1Page)}", typeof(Child1Page));
}
}
47 changes: 47 additions & 0 deletions UserInteractionDemo/Child1Page.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:userInteractionDemo="clr-namespace:UserInteractionDemo"
x:Class="UserInteractionDemo.Child1Page"
x:DataType="userInteractionDemo:Child1ViewModel"
Title="UserInteraction Demo">
<ContentPage.BindingContext>
<userInteractionDemo:MainViewModel />
</ContentPage.BindingContext>
<ContentPage.Resources>
<Color x:Key="Accent">#96d1ff</Color>
<Style TargetType="Label">
<Setter Property="TextColor" Value="Black" />
</Style>
<Style TargetType="Button">
<Setter Property="BackgroundColor" Value="{StaticResource Primary}"/>
<Setter Property="TextColor" Value="White"/>
</Style>
</ContentPage.Resources>


<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackLayout BackgroundColor="{StaticResource Accent}" VerticalOptions="FillAndExpand" HorizontalOptions="Fill">
<StackLayout Orientation="Horizontal" HorizontalOptions="Center" VerticalOptions="Center">
<ContentView Padding="0,20,0,20" VerticalOptions="FillAndExpand">
<Label Text="UserInteraction Demo" FontSize="Title" />
</ContentView>
</StackLayout>
</StackLayout>
<ScrollView Grid.Row="1">
<StackLayout Padding="30,24,30,24" Spacing="10">
<Button Text="Alert" Command="{Binding AlertCommand}" />
<Button Text="Menu" Command="{Binding MenuCommand}" />
<Button Text="Toast" Command="{Binding ToastCommand}" />
<Button Text="Confirm" Command="{Binding ConfirmCommand}" />
<Button Text="Confirm 3 buttons" Command="{Binding Confirm3Command}" />
<Button Text="Wait indicator" Command="{Binding WaitIndicatorCommand}" />
</StackLayout>
</ScrollView>
</Grid>

</ContentPage>
9 changes: 9 additions & 0 deletions UserInteractionDemo/Child1Page.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace UserInteractionDemo;

public partial class Child1Page : ContentPage
{
public Child1Page()
{
InitializeComponent();
}
}
76 changes: 76 additions & 0 deletions UserInteractionDemo/Child1ViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System.Windows.Input;
using Vapolia.UserInteraction;

namespace UserInteractionDemo;

public class Child1ViewModel
{
public ICommand AlertCommand { get; }
public ICommand MenuCommand { get; }
public ICommand ToastCommand { get; }
public ICommand ConfirmCommand { get; }
public ICommand Confirm3Command { get; }
public ICommand WaitIndicatorCommand { get; }

public Child1ViewModel()
{
AlertCommand = new Command(async () =>
{
await UserInteraction.Alert("This is a message", "Optional title", "OK");
});

MenuCommand = new Command(async () =>
{
var result = await UserInteraction.Menu("Optional title", "Optional description", "Cancel", "Delete", "Option 1", "Option 2", "Option 3");
var text = result switch
{
0 => "Cancelled",
1 => "Deleted !",
2 => "Option 1",
3 => "Option 2",
4 => "Option 3",
_ => throw new NotSupportedException()
};

await UserInteraction.Alert(text, "Selected item is:", "Close");
});

ToastCommand = new Command(async () =>
{
await UserInteraction.Toast("This is a message", ToastStyle.Warning, ToastDuration.Normal, ToastPosition.Bottom, 100);
});

ConfirmCommand = new Command(async () =>
{
var ok = await UserInteraction.Confirm("Are you sure you want to do that?", "Really do that?", okButton: "Yes", cancelButton: "No");
await UserInteraction.Toast(ok ? "OK, Done" : "Cancelled", ToastStyle.Notice);
});

Confirm3Command = new Command(async () =>
{
var ok = await UserInteraction.ConfirmThreeButtons("Are you sure you want to do that?", "Really do that?", "I'm sure", "No!", "I don't know");
var text = ok switch
{
ConfirmThreeButtonsResponse.Negative => "Cancelled",
ConfirmThreeButtonsResponse.Positive => "Done!",
ConfirmThreeButtonsResponse.Neutral => "I'll ask you later!",
_ => throw new NotSupportedException()
};
await UserInteraction.Toast(text, ToastStyle.Notice);
});

WaitIndicatorCommand = new Command(async () =>
{
var dismiss = new CancellationTokenSource();
var wi = UserInteraction.WaitIndicator(dismiss.Token, "Wait 3 seconds", displayAfterSeconds: 0, userCanDismiss: false);

await Task.Delay(1000);
wi.Body = "Wait 2 seconds";
await Task.Delay(1000);
wi.Body = "Wait 1 second";
await Task.Delay(1000);

dismiss.Cancel();
});
}
}
2 changes: 2 additions & 0 deletions UserInteractionDemo/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
<Button Text="Toast" Command="{Binding ToastCommand}" />
<Button Text="Confirm" Command="{Binding ConfirmCommand}" />
<Button Text="Confirm 3 buttons" Command="{Binding Confirm3Command}" />
<Button Text="Wait indicator" Command="{Binding WaitIndicatorCommand}" />
<Button Text="Try from child page" Command="{Binding GoToChild1Command}" />
</StackLayout>
</ScrollView>
</Grid>
Expand Down
41 changes: 35 additions & 6 deletions UserInteractionDemo/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ public class MainViewModel
{
public ICommand AlertCommand { get; }
public ICommand MenuCommand { get; }
public object ToastCommand { get; }
public object ConfirmCommand { get; }
public object Confirm3Command { get; }
public ICommand ToastCommand { get; }
public ICommand ConfirmCommand { get; }
public ICommand Confirm3Command { get; }
public ICommand WaitIndicatorCommand { get; }
public ICommand GoToChild1Command { get; }

public MainViewModel()
{
AlertCommand = new Command(async () => { await UserInteraction.Alert("This is a message", "Optional title", "OK"); });
AlertCommand = new Command(async () =>
{
await UserInteraction.Alert("This is a message", "Optional title", "OK");
});

MenuCommand = new Command(async () =>
{
Expand All @@ -25,12 +30,16 @@ public MainViewModel()
2 => "Option 1",
3 => "Option 2",
4 => "Option 3",
_ => throw new NotSupportedException()
};

await UserInteraction.Alert(text, "Selected item is:", "Close");
});

ToastCommand = new Command(async () => { await UserInteraction.Toast("This is a message", ToastStyle.Warning, ToastDuration.Normal, ToastPosition.Bottom, 100); });
ToastCommand = new Command(async () =>
{
await UserInteraction.Toast("This is a message", ToastStyle.Warning, ToastDuration.Normal, ToastPosition.Bottom, 100);
});

ConfirmCommand = new Command(async () =>
{
Expand All @@ -45,9 +54,29 @@ public MainViewModel()
{
ConfirmThreeButtonsResponse.Negative => "Cancelled",
ConfirmThreeButtonsResponse.Positive => "Done!",
ConfirmThreeButtonsResponse.Neutral => "I'll ask you later!"
ConfirmThreeButtonsResponse.Neutral => "I'll ask you later!",
_ => throw new NotSupportedException()
};
await UserInteraction.Toast(text, ToastStyle.Notice);
});

WaitIndicatorCommand = new Command(async () =>
{
var dismiss = new CancellationTokenSource();
var wi = UserInteraction.WaitIndicator(dismiss.Token, "Wait 3 seconds", displayAfterSeconds: 0, userCanDismiss: false);

await Task.Delay(1000);
wi.Body = "Wait 2 seconds";
await Task.Delay(1000);
wi.Body = "Wait 1 second";
await Task.Delay(1000);

dismiss.Cancel();
});

GoToChild1Command = new Command(async () =>
{
await Shell.Current.GoToAsync("Child1Page");
});
}
}
5 changes: 4 additions & 1 deletion UserInteractionDemo/UserInteractionDemo.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0-android;net6.0-ios</TargetFrameworks>
<TargetFrameworks>net7.0-android;net7.0-ios</TargetFrameworks>
<OutputType>Exe</OutputType>
<RootNamespace>UserInteractionDemo</RootNamespace>
<UseMaui>true</UseMaui>
Expand All @@ -23,6 +23,9 @@
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">26.0</SupportedOSPlatformVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net7.0-ios|AnyCPU'">
<CreatePackage>false</CreatePackage>
</PropertyGroup>
<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
Expand Down
33 changes: 16 additions & 17 deletions Vapolia.UserInteraction/IWaitIndicator.shared.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
using System.Threading;

namespace Vapolia.UserInteraction
namespace Vapolia.UserInteraction;

public interface IWaitIndicator
{
public interface IWaitIndicator
{
/// <summary>
/// cancelled if the indicator is dismissed by the user (if userCanDismiss is true)
/// </summary>
CancellationToken UserDismissedToken { get; }
/// <summary>
/// cancelled if the indicator is dismissed by the user (if userCanDismiss is true)
/// </summary>
CancellationToken UserDismissedToken { get; }

/// <summary>
/// Update the title text while displayed
/// </summary>
string Title { set; }
/// <summary>
/// Update the title text while displayed
/// </summary>
string Title { set; }

/// <summary>
/// Update the body text while displayed
/// </summary>
string Body { set; }
}
}
/// <summary>
/// Update the body text while displayed
/// </summary>
string Body { set; }
}
14 changes: 6 additions & 8 deletions Vapolia.UserInteraction/InputResponse.shared.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
namespace Vapolia.UserInteraction
{
public class InputResponse
{
public bool Ok { get; set; }
public string? Text { get; set;}
}
}
namespace Vapolia.UserInteraction;

public class InputResponse
{
public bool Ok { get; set; }
public string? Text { get; set;}
}
15 changes: 7 additions & 8 deletions Vapolia.UserInteraction/ToastDuration.shared.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
namespace Vapolia.UserInteraction
namespace Vapolia.UserInteraction;

public enum ToastDuration
{
public enum ToastDuration
{
Short = 1000,
Normal = 2500,
Long = 8000
}
}
Short = 1000,
Normal = 2500,
Long = 8000
}
29 changes: 8 additions & 21 deletions Vapolia.UserInteraction/ToastStyle.shared.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
namespace Vapolia.UserInteraction
{
public enum ToastStyle
{
Custom,
Info,
Notice,
Warning,
Error
}
namespace Vapolia.UserInteraction;

public static class Constants
{
public static Color[] ToastStyleBackgroundTint =
{
null,
null,
null,
Colors.Orange,
Colors.Red,
};
}
public enum ToastStyle
{
Custom,
Info,
Notice,
Warning,
Error
}
Loading