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

fix: add pattern matching for ios support #187

Merged
merged 3 commits into from
Jul 7, 2023

Conversation

nwestfall
Copy link
Contributor

Fixes #186

Instead of using dynamic in GetActiveEventHandlers, we can detect if it's a callback using pattern matching. This is allowed in iOS.

https://learn.microsoft.com/en-us/xamarin/ios/internals/limitations#systemreflectionemit

I tested using the Server and WASM projects, all events still show.
image

@@ -2264,19 +2264,31 @@ protected List<string> GetActiveEventHandlers()

foreach (PropertyInfo callbackInfo in callbacks)
{
dynamic? callback = callbackInfo.GetValue(this);
object? callback = callbackInfo.GetValue(this);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nwestfall this is great! I have a few suggestions on how we can make it more streamlined.

  • On line 2260, we could actually pull the EventCallbacks and Funcs separately as propertyInfos, instead of together. This would eliminate the need to check if it's a Func later.
  • There is an interface, IEventCallback that all the EventCallbacks and EventCallback<T>s inherit from. I think we could just cast to that instead of each return type. This would make it more extensible, as with the current version, if we add new EventCallbacks with different types, we have to remember to update this method.

I think I'd like to see a refactor using one or both of these ideas before we merge. Let me know if you would like me to implement that myself, or you are welcome to update this branch and PR.

Thanks again for finding this and working on it!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TimPurdum I'll look at your first point. For the second point, I actually tried this but it's an internal interface.

https://github.com/dotnet/aspnetcore/blob/1fbe264736d62fab1c37f0986df2e90fd4ab33b3/src/Components/Components/src/IEventCallback.cs#L7

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I missed that. Bummer!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can't find a way around enumerating the callback Ts, I'm ok with keeping it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only way I could think of doing it (and maybe this is longer term), is if all the GeoBlazor Events (ClickEvent, BlurEvent), implemented an interface. Would have to test, but maybe then you could do EventCallback<IGeoBlazorEvent> to catch all of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like you can :(, so I don't have any other ideas at this time.

@TimPurdum TimPurdum merged commit 4700bad into dymaptic:develop Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

iOS Release Builds: Unable to GetActiveEventHandlers due to JIT limitation
2 participants