Skip to content

Commit

Permalink
Merge pull request #5 from softlion/dev/bm/cross-maui-xamarin
Browse files Browse the repository at this point in the history
Cross compile with Xamarin.Forms compatibility
  • Loading branch information
softlion authored Apr 20, 2023
2 parents 202299c + efc6c16 commit 818b137
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
33 changes: 25 additions & 8 deletions Vapolia.UserInteraction/UserInteraction.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,32 @@
using Activity = Android.App.Activity;
using AndroidX.AppCompat.App;
using Google.Android.Material.Snackbar;
using Microsoft.Maui.Platform;
using Color = Android.Graphics.Color;
using ProgressBar = Android.Widget.ProgressBar;
#if MONOANDROID
using Color = Android.Graphics.Color;
using AlertDialog = AndroidX.AppCompat.App.AlertDialog;
using Platform = Xamarin.Essentials.Platform;
#else
using Microsoft.Maui.Platform;
#endif

namespace Vapolia.UserInteraction;


public static class Constants
{
public static Microsoft.Maui.Graphics.Color?[] ToastStyleBackgroundTint =
public static Color?[] ToastStyleBackgroundTint =
{
null,
null,
null,
#if MONOANDROID
Color.Orange,
Color.Red
#else
Colors.Orange,
Colors.Red,
#endif
};
}

Expand Down Expand Up @@ -370,7 +380,7 @@ static Task PlatformActivityIndicator(CancellationToken dismiss, double? apparit
.SetOnDismissListener(new DialogDismissListener(() => tcs.TrySetResult(0)));

//Make translucent. ThemeTranslucentNoTitleBarFullScreen does not work on wiko.
builder.SetBackground(new ColorDrawable(Color.Argb(175,255,255,255)));
builder.SetBackground(new ColorDrawable(Android.Graphics.Color.Argb(175,255,255,255)));
var dialog = builder.Show();

dismiss.Register(() =>
Expand Down Expand Up @@ -548,10 +558,17 @@ internal static Task PlatformToast(string text, ToastStyle style = ToastStyle.No
if(snackBar != null)
{
var color = Constants.ToastStyleBackgroundTint[(int)style];
if(color != null)
snackBar.SetBackgroundTint(color.ToPlatform());

var layoutParams = snackBar.View.LayoutParameters as FrameLayout.LayoutParams;
if (color != null)
{
#if MONOANDROID
var platformColor = color.Value;
#else
var platformColor = color.ToPlatform();
#endif
snackBar.SetBackgroundTint(platformColor);
}

var layoutParams = snackBar.View.LayoutParameters as FrameLayout.LayoutParams;
if (layoutParams != null)
{
layoutParams.Gravity = position == ToastPosition.Bottom ? GravityFlags.Bottom : (position == ToastPosition.Top ? GravityFlags.Top : GravityFlags.CenterVertical);
Expand Down
6 changes: 5 additions & 1 deletion Vapolia.UserInteraction/UserInteraction.ios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
using System.Text.RegularExpressions;
using UIKit;
using Microsoft.Extensions.Logging;
#if XAMARINIOS
using Cirrious.FluentLayouts.Touch;
using Xamarin.Essentials;
#else
using Vapolia.FluentLayouts;

#endif

namespace Vapolia.UserInteraction;

Expand Down
16 changes: 9 additions & 7 deletions Vapolia.UserInteraction/Vapolia.UserInteraction.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Xamarin.Legacy.Sdk/0.2.0-alpha4">

<PropertyGroup>
<!-- <TargetFrameworks>Xamarin.iOS10;MonoAndroid10.0;</TargetFrameworks>-->
<!--
When Xamarin.iOS10 is enabled:
Error MSB3644 : The reference assemblies for framework “Xamarin.iOS,Version=v1.0” were not found
-->
<TargetFrameworks>netstandard2.1;net7.0-android;net7.0-ios</TargetFrameworks>
<TargetFrameworks>Xamarin.iOS10;MonoAndroid10.0;netstandard2.1;net7.0-android;net7.0-ios</TargetFrameworks>
<AssemblyName>Vapolia.UserInteraction</AssemblyName>
<RootNamespace>Vapolia.UserInteraction</RootNamespace>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
Expand Down Expand Up @@ -47,7 +42,14 @@
<ItemGroup Condition="$(TargetFramework.StartsWith('Xamarin.iOS'))">
<PackageReference Include="Cirrious.FluentLayout" Version="3.0.0" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2401" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="Xamarin.Essentials" Version="1.7.5" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('MonoAndroid10'))">
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2401" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="Xamarin.Essentials" Version="1.7.5" />
</ItemGroup>

<!-- nuget configurable properties -->
<PropertyGroup>
Expand Down

0 comments on commit 818b137

Please sign in to comment.