Skip to content

Commit

Permalink
Bugfix: MvxFragmentPresentationAttribute.FragmentContentId misses "An…
Browse files Browse the repository at this point in the history
…droid.Resource.Id.Content" (#4587)

* set Android.Resource.Id.Content

* revert global nullable enable
  • Loading branch information
evgenyvalavin committed Apr 28, 2023
1 parent 1a16210 commit 7d47d32
Show file tree
Hide file tree
Showing 8 changed files with 402 additions and 434 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,22 @@
// The .NET Foundation licenses this file to you under the MS-PL license.
// See the LICENSE file in the project root for more information.

using System;
using Android.OS;
using MvvmCross.Presenters.Attributes;

namespace MvvmCross.Platforms.Android.Presenters.Attributes
{
namespace MvvmCross.Platforms.Android.Presenters.Attributes;

#nullable enable
[AttributeUsage(AttributeTargets.Class)]
public class MvxActivityPresentationAttribute : MvxBasePresentationAttribute
[AttributeUsage(AttributeTargets.Class)]
public class MvxActivityPresentationAttribute : MvxBasePresentationAttribute
{
public MvxActivityPresentationAttribute()
{
public MvxActivityPresentationAttribute()
{
}
}

public static Bundle? DefaultExtras { get; }
public static Bundle? DefaultExtras { get; }

/// <summary>
/// Add extras to the Intent that will be started for this Activity
/// </summary>
public Bundle? Extras { get; set; } = DefaultExtras;
}
#nullable restore
/// <summary>
/// Add extras to the Intent that will be started for this Activity
/// </summary>
public Bundle? Extras { get; set; } = DefaultExtras;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,34 @@
// The .NET Foundation licenses this file to you under the MS-PL license.
// See the LICENSE file in the project root for more information.

using System;
using System.Linq;
using Android.App;
using MvvmCross.Presenters;

namespace MvvmCross.Platforms.Android.Presenters.Attributes
{
namespace MvvmCross.Platforms.Android.Presenters.Attributes;

#nullable enable
public static class MvxAndroidPresentationAttributeExtensions
public static class MvxAndroidPresentationAttributeExtensions
{
public static bool IsFragmentCacheable(this Type fragmentType, Type fragmentActivityParentType)
{
public static bool IsFragmentCacheable(this Type fragmentType, Type fragmentActivityParentType)
{
if (!fragmentType.HasBasePresentationAttribute())
return false;
if (!fragmentType.HasBasePresentationAttribute())
return false;

var fragmentAttributes =
fragmentType.GetBasePresentationAttributes()
.Select(baseAttribute => baseAttribute as MvxFragmentPresentationAttribute)
.Where(fragmentAttribute => fragmentAttribute != null);
var fragmentAttributes =
fragmentType.GetBasePresentationAttributes()
.Select(baseAttribute => baseAttribute as MvxFragmentPresentationAttribute)
.Where(fragmentAttribute => fragmentAttribute != null);

var currentAttribute = fragmentAttributes.FirstOrDefault(
fragmentAttribute => fragmentAttribute != null &&
fragmentAttribute.ActivityHostViewModelType == fragmentActivityParentType);
var currentAttribute = fragmentAttributes.FirstOrDefault(
fragmentAttribute => fragmentAttribute != null &&
fragmentAttribute.ActivityHostViewModelType == fragmentActivityParentType);

return currentAttribute?.IsCacheableFragment == true;
}

public static PopBackStackFlags ToNativePopBackStackFlags(this MvxPopBackStack mvxPopBackStack)
{
switch (mvxPopBackStack)
{
case MvxPopBackStack.None:
return PopBackStackFlags.None;
case MvxPopBackStack.Inclusive:
return PopBackStackFlags.Inclusive;
default:
throw new ArgumentOutOfRangeException(nameof(mvxPopBackStack), mvxPopBackStack, $"No matching {nameof(PopBackStackFlags)} enum is defined");
}
}
return currentAttribute?.IsCacheableFragment == true;
}
#nullable restore

public static PopBackStackFlags ToNativePopBackStackFlags(this MvxPopBackStack mvxPopBackStack) => mvxPopBackStack switch
{
MvxPopBackStack.None => PopBackStackFlags.None,
MvxPopBackStack.Inclusive => PopBackStackFlags.Inclusive,
_ => throw new ArgumentOutOfRangeException(nameof(mvxPopBackStack), mvxPopBackStack, $"No matching {nameof(PopBackStackFlags)} enum is defined"),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,70 @@
// The .NET Foundation licenses this file to you under the MS-PL license.
// See the LICENSE file in the project root for more information.

using System;
namespace MvvmCross.Platforms.Android.Presenters.Attributes;

namespace MvvmCross.Platforms.Android.Presenters.Attributes
{
#nullable enable
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class MvxDialogFragmentPresentationAttribute : MvxFragmentPresentationAttribute
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class MvxDialogFragmentPresentationAttribute : MvxFragmentPresentationAttribute
{
public MvxDialogFragmentPresentationAttribute()
{
public MvxDialogFragmentPresentationAttribute()
{
}
}

public MvxDialogFragmentPresentationAttribute(
bool cancelable = true,
Type? activityHostViewModelType = null,
bool addToBackStack = false,
int enterAnimation = int.MinValue,
int exitAnimation = int.MinValue,
int popEnterAnimation = int.MinValue,
int popExitAnimation = int.MinValue,
int transitionStyle = int.MinValue,
bool isCacheableFragment = false)
: base(
activityHostViewModelType,
int.MinValue,
addToBackStack,
enterAnimation,
exitAnimation,
popEnterAnimation,
popExitAnimation,
transitionStyle,
null,
isCacheableFragment)
{
Cancelable = cancelable;
}
public MvxDialogFragmentPresentationAttribute(
bool cancelable = true,
Type? activityHostViewModelType = null,
bool addToBackStack = false,
int enterAnimation = int.MinValue,
int exitAnimation = int.MinValue,
int popEnterAnimation = int.MinValue,
int popExitAnimation = int.MinValue,
int transitionStyle = int.MinValue,
bool isCacheableFragment = false)
: base(
activityHostViewModelType,
int.MinValue,
addToBackStack,
enterAnimation,
exitAnimation,
popEnterAnimation,
popExitAnimation,
transitionStyle,
null,
isCacheableFragment)
{
Cancelable = cancelable;
}

public MvxDialogFragmentPresentationAttribute(
bool cancelable = true,
Type? activityHostViewModelType = null,
bool addToBackStack = false,
string? enterAnimation = null,
string? exitAnimation = null,
string? popEnterAnimation = null,
string? popExitAnimation = null,
string? transitionStyle = null,
bool isCacheableFragment = false)
: base(
activityHostViewModelType,
null,
addToBackStack,
enterAnimation,
exitAnimation,
popEnterAnimation,
popExitAnimation,
transitionStyle,
null,
isCacheableFragment)
{
Cancelable = cancelable;
}
public MvxDialogFragmentPresentationAttribute(
bool cancelable = true,
Type? activityHostViewModelType = null,
bool addToBackStack = false,
string? enterAnimation = null,
string? exitAnimation = null,
string? popEnterAnimation = null,
string? popExitAnimation = null,
string? transitionStyle = null,
bool isCacheableFragment = false)
: base(
activityHostViewModelType,
null,
addToBackStack,
enterAnimation,
exitAnimation,
popEnterAnimation,
popExitAnimation,
transitionStyle,
null,
isCacheableFragment)
{
Cancelable = cancelable;
}

public static bool DefaultCancelable { get; } = true;
public static bool DefaultCancelable { get; } = true;

/// <summary>
/// Indicates if the dialog can be canceled
/// </summary>
public bool Cancelable { get; set; }
}
#nullable restore
/// <summary>
/// Indicates if the dialog can be canceled
/// </summary>
public bool Cancelable { get; set; }
}

0 comments on commit 7d47d32

Please sign in to comment.