Skip to content

Commit

Permalink
[UIKit] Inline the UITraitChangeObservable protocol into the classes …
Browse files Browse the repository at this point in the history
…that implement it. Fixes #20265. (#21676)

This also required fixing:

* A bug in the static registrar where we'd ignore the generic parameters
in a method
  when looking for methods implementing an interface.

* A bug in the generator where we'd throw
You_Should_Not_Call_base_In_This_Method()
  in some cases where we shouldn't.

Also:

* Enable nullability and fix any resulting issues.
* Clean up some legacy code we don't need anymore.

Ref:
#19410 (comment)

Fixes #20265.

---------

Co-authored-by: GitHub Actions Autoformatter <[email protected]>
  • Loading branch information
rolfbjarne and GitHub Actions Autoformatter authored Nov 26, 2024
1 parent 3fcb5b3 commit 2a6e75b
Show file tree
Hide file tree
Showing 9 changed files with 770 additions and 118 deletions.
119 changes: 119 additions & 0 deletions src/UIKit/UIPresentationController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using System;
using System.Runtime.InteropServices;

using Foundation;
using ObjCRuntime;

#nullable enable

namespace UIKit {
public partial class UIPresentationController {
#region Inlined from the UITraitChangeObservable protocol
/// <summary>
/// Registers a callback handler that will be executed when one of the specified traits changes.
/// </summary>
/// <param name="traits">The traits to observe.</param>
/// <param name="handler">The callback to execute when any of the specified traits changes.</param>
/// <returns>A token that can be used to unregister the callback by calling <see cref="M:UnregisterForTraitChanges" />.</returns>
public IUITraitChangeRegistration RegisterForTraitChanges (Type [] traits, Action<IUITraitEnvironment, UITraitCollection> handler)
{
return IUITraitChangeObservable._RegisterForTraitChanges (this, traits, handler);
}

/// <summary>
/// Registers a callback handler that will be executed when one of the specified traits changes.
/// </summary>
/// <param name="traits">The traits to observe.</param>
/// <param name="handler">The callback to execute when any of the specified traits changes.</param>
/// <returns>A token that can be used to unregister the callback by calling <see cref="M:UnregisterForTraitChanges" />.</returns>
public unsafe IUITraitChangeRegistration RegisterForTraitChanges (Action<IUITraitEnvironment, UITraitCollection> handler, params Type [] traits)
{
// Add an override with 'params', unfortunately this means reordering the parameters.
return IUITraitChangeObservable._RegisterForTraitChanges (this, handler, traits);
}

/// <summary>
/// Registers a callback handler that will be executed when the specified trait changes.
/// </summary>
/// <typeparam name="T">The trait to observe.</typeparam>
/// <param name="handler">The callback to execute when any of the specified traits changes.</param>
/// <returns>A token that can be used to unregister the callback by calling <see cref="M:UnregisterForTraitChanges" />.</returns>
public unsafe IUITraitChangeRegistration RegisterForTraitChanges<T> (Action<IUITraitEnvironment, UITraitCollection> handler)
where T : IUITraitDefinition
{
return IUITraitChangeObservable._RegisterForTraitChanges<T> (this, handler);
}

/// <summary>
/// Registers a callback handler that will be executed when any of the specified traits changes.
/// </summary>
/// <typeparam name="T1">A trait to observe</typeparam>
/// <typeparam name="T2">A trait to observe</typeparam>
/// <param name="handler">The callback to execute when any of the specified traits changes.</param>
/// <returns>A token that can be used to unregister the callback by calling <see cref="M:UnregisterForTraitChanges" />.</returns>
public unsafe IUITraitChangeRegistration RegisterForTraitChanges<T1, T2> (Action<IUITraitEnvironment, UITraitCollection> handler)
where T1 : IUITraitDefinition
where T2 : IUITraitDefinition
{
return IUITraitChangeObservable._RegisterForTraitChanges<T1, T2> (this, handler);
}

/// <summary>
/// Registers a callback handler that will be executed when any of the specified traits changes.
/// </summary>
/// <typeparam name="T1">A trait to observe</typeparam>
/// <typeparam name="T2">A trait to observe</typeparam>
/// <typeparam name="T3">A trait to observe</typeparam>
/// <param name="handler">The callback to execute when any of the specified traits changes.</param>
/// <returns>A token that can be used to unregister the callback by calling <see cref="M:UnregisterForTraitChanges" />.</returns>
public unsafe IUITraitChangeRegistration RegisterForTraitChanges<T1, T2, T3> (Action<IUITraitEnvironment, UITraitCollection> handler)
where T1 : IUITraitDefinition
where T2 : IUITraitDefinition
where T3 : IUITraitDefinition
{
return IUITraitChangeObservable._RegisterForTraitChanges<T1, T2, T3> (this, handler);
}

/// <summary>
/// Registers a callback handler that will be executed when any of the specified traits changes.
/// </summary>
/// <typeparam name="T1">A trait to observe</typeparam>
/// <typeparam name="T2">A trait to observe</typeparam>
/// <typeparam name="T3">A trait to observe</typeparam>
/// <typeparam name="T4">A trait to observe</typeparam>
/// <param name="handler">The callback to execute when any of the specified traits changes.</param>
/// <returns>A token that can be used to unregister the callback by calling <see cref="M:UnregisterForTraitChanges" />.</returns>
public unsafe IUITraitChangeRegistration RegisterForTraitChanges<T1, T2, T3, T4> (Action<IUITraitEnvironment, UITraitCollection> handler)
where T1 : IUITraitDefinition
where T2 : IUITraitDefinition
where T3 : IUITraitDefinition
where T4 : IUITraitDefinition
{
return IUITraitChangeObservable._RegisterForTraitChanges<T1, T2, T3, T4> (this, handler);
}

/// <summary>
/// Registers a selector that will be called on the specified object when any of the specified traits changes.
/// </summary>
/// <param name="traits">The traits to observe.</param>
/// <param name="target">The object whose specified selector will be called.</param>
/// <param name="action">The selector to call on the specified object.</param>
/// <returns>A token that can be used to unregister the callback by calling <see cref="M:UnregisterForTraitChanges" />.</returns>
public IUITraitChangeRegistration RegisterForTraitChanges (Type [] traits, NSObject target, Selector action)
{
return IUITraitChangeObservable._RegisterForTraitChanges (this, traits, target, action);
}

/// <summary>
/// Registers a selector that will be called on the current object when any of the specified traits changes.
/// </summary>
/// <param name="traits">The traits to observe.</param>
/// <param name="action">The selector to call on the current object.</param>
/// <returns>A token that can be used to unregister the callback by calling <see cref="M:UnregisterForTraitChanges" />.</returns>
public IUITraitChangeRegistration RegisterForTraitChanges (Type [] traits, Selector action)
{
return IUITraitChangeObservable._RegisterForTraitChanges (this, traits, action);
}
#endregion
}
}
Loading

6 comments on commit 2a6e75b

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.