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

IUIContentConfiguration.MakeContentView() result fails to cast to UIView #21738

Open
Uncommon opened this issue Dec 2, 2024 · 2 comments
Open
Labels
api-bindings bug If an issue is a bug or a pull request a bug fix
Milestone

Comments

@Uncommon
Copy link

Uncommon commented Dec 2, 2024

Apple platform

iOS

Framework version

net8.0-*

Affected platform version

.NET 8.0.100 18.0.8303

Description

The return type of IUIContentConfiguration.MakeContentView() is simply IUIContentView. By contrast, in Swift it is UIView & UIContentView (and similarly in Objective-C), so we're missing the idea that the return type is not just an object that conforms to UIContentView, but it's specifically a UIView. Attempting to cast the result of MakeContentView() to UIView fails, which is also incorrect. This makes the composability aspect of content configurations unusable in C#: you can't take one configuration's view and embed it inside another.

Steps to Reproduce

  1. Attempt to cast the result of a MakeContentView() call to UIView.
  2. The result is null, which is incorrect. The result is always a UIView.

Did you find any workaround?

I haven't tried it yet, but I could make a subclass of UIView that implements IUIContentView, and return that from my custom content configurations. I think that would get around the casting issue for those cases, but it would not help for when I want to embed a system content configuration inside a custom one.

Relevant log output

No response

@rolfbjarne
Copy link
Member

I'm not sure this is possible to bind correctly in C# without some ugly workarounds, because it's not possible to express in C# that a return type is both of a specific type and implements an interface.

Something like this might be an option, where you get two variables:

interface IUIContentConfiguration {
	public void MakeContentView (out UIView view, out IUIContentView contentView)
	{
		// ...
	}
}

Depending on your use case, it might be possible to work around it by doing this:

using ObjCRuntime;

UIContentConfiguration conf = ...;
var view = conf.MakeContentView ();
var uiView = Runtime.GetNSObject<UIView> (view.Handle, false);

However, can you explain a bit more how you want to use the return value, that might give me more ideas on how to bind it? If possible with some actual code samples.

@rolfbjarne rolfbjarne added this to the Future milestone Dec 3, 2024
@rolfbjarne rolfbjarne added the bug If an issue is a bug or a pull request a bug fix label Dec 3, 2024
@Uncommon
Copy link
Author

Uncommon commented Dec 3, 2024

The goal is to use content configurations compositionally. For example, to take a standard cell content view such as from UIListContentConfiguration.ValueCellConfiguration and add an error/info message below it.

I tried out Runtime.GetNSObject and it does seem to work. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-bindings bug If an issue is a bug or a pull request a bug fix
Projects
None yet
Development

No branches or pull requests

2 participants