Compatibility: (Revised) Ported Xamarin Forms Effect registration never resolves
See original GitHub issueDescription
While testing a newly ported custom ColorPicker, I ported the control’s touch handling in ColorPickerTouchEffect, which consists of the platform-independent ColorPickerTouchRoutingEffect and the platform-specific ColorPickerTouchEffectXXXX, where XXXX is platform specific (WinUI, Droid, etc) currently being implemented.
During my testing I set breakpoints in each of the Configure… builder calls in MauiProgram and discovered that ConfigureEffects fails to register the PlatformEffect. Both ConfigureFonts and ConfigureMauiHandlers are called as expected. I confirmed that ConfigureEffects IS called because the EffectsFactory and EffectsRegistration are in the builder.
AddCompatibilityEffects, which performs assembly scanning, never resolves the PlatformEffect.
Here is the initialization code:
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder.UseMauiApp<App>();
builder.UseSkiaSharp( true );
builder.ConfigureMauiHandlers( handlers =>
{
handlers.TryAddCompatibilityRenderer( typeof( ColorCircle ), typeof( ColorCircle ) );
handlers.TryAddCompatibilityRenderer( typeof( ColorWheel ), typeof( ColorWheel ) );
handlers.TryAddCompatibilityRenderer( typeof( ColorTriangle ), typeof( ColorTriangle ) );
handlers.TryAddCompatibilityRenderer( typeof( AlphaSlider ), typeof( AlphaSlider ) );
handlers.TryAddCompatibilityRenderer( typeof( LuminositySlider ), typeof( LuminositySlider ) );
handlers.TryAddCompatibilityRenderer( typeof( RGBSliders ), typeof( RGBSliders ) );
handlers.TryAddCompatibilityRenderer( typeof( HSLSliders ), typeof( HSLSliders ) );
} );
builder.ConfigureFonts( fonts =>
{
fonts.AddFont( "OpenSans-Regular.ttf", "OpenSansRegular" );
} );
builder.ConfigureEffects( effects =>
{
var assemblies = Device.GetAssemblies();
effects.AddCompatibilityEffects( assemblies );
} );
return builder.Build();
Steps to Reproduce
- Port an XF application that includes an Effect
- Add builder.ConfigureEffects to MauiProgram to register Effects
- Launch the application
- Observe a NRE because the PlatformEffect was not atttached to the RoutingEffect which should occur during Effect resolution.
Version with bug
Preview 12 (current)
Last version that worked well
Unknown/Other
Affected platforms
Android, Windows, I was not able test on other platforms
Affected platform versions
Android 12 and up, Windows SDK 10.0.19041
Did you find any workaround?
Not yet, although I’m still working on it. I filed this because Shane recommended that I do so.
Subsequent debugging revealed that ConfigureEffects is working correctly. Still tracking down why the registration function, AddCompatibilityEffects, doesn’t resolve the Effect.
Relevant log output
None
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:9 (2 by maintainers)
Thanks for following up. With no movement on the issue I choose to abandon Effects and converted the code to a Behavior which uses a different (and simpler) mechanism. As the Behavior performs the requisite services perfectly, I am abandoning Effects for now.
@IndianaGary Sorry for the delay getting back to you! I’ll close this for now, but please let us know if you come across further issues. Thank you!!