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

PlatformEffects does not work with Frame on Android #3548

Closed
rodja opened this issue Aug 12, 2018 · 6 comments

Comments

@rodja
Copy link

commented Aug 12, 2018

Description

Adding an Effect to an Xamarin.Forms Frame does not call OnAttached().

Steps to Reproduce

  1. implement a simple PlattformEffect on Android
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

[assembly: ResolutionGroupName("EffectOnFrame")]
[assembly: ExportEffect(typeof(EffectOnFrame.Droid.DemoEffectDroid), "DemoEffect")]
namespace EffectOnFrame.Droid
{
    public class DemoEffectDroid : PlatformEffect
    {
        protected override void OnAttached() => System.Console.WriteLine("Attached");
        protected override void OnDetached() => System.Console.WriteLine("Detached");
    }
}
  1. Add Effect to a Frame:
using System;
using Xamarin.Forms;

namespace EffectOnFrame
{
    public class App : Application
    {
        public App()
        {
            var view = new Frame();
            view.Effects.Add(Effect.Resolve("EffectOnFrame.DemoEffect"));

            MainPage = new ContentPage { Content = view };
        }
    }
}

Expected Behavior

When launching the App the OnAttached() method should be called.

Actual Behavior

The Effect is not called properly when view is a Frame. If using a Label, StackLayout or ContentView the Effect is called properly.

Basic Information

  • Version with issue: Xamarin.Forms 3.1.0
  • Last known good version: ?
  • IDE: Visual Studio for Mac 7.5.4
  • Platform Target Frameworks:
    • Android: 8.1
@kingces95

This comment has been minimized.

Copy link
Member

commented Aug 16, 2018

Yep. As reported. No logging for frame but'll work for label.

@kingces95 kingces95 moved this from New to Ready For Work in Triage Aug 16, 2018

@samhouts samhouts removed this from Ready For Work in Triage Oct 15, 2018

@flchaux flchaux referenced this issue Oct 24, 2018
3 of 3 tasks complete
@flchaux

This comment has been minimized.

Copy link

commented Oct 24, 2018

I made a PR to fix this issue : #4195
Two possible workarounds :

  • Use explicitly old renderer instead of FastRenderer: create a custom renderer which extends Xamarin.Forms.Platform.Android.FrameRenderer
  • Create a customer renderer which extends Xamarin.Forms.Platform.Android.FastRenderers.FrameRenderer and add effects registering to OnElementChanged :
protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
 {
	base.OnElementChanged(e);
	VisualElement oldElement = e.OldElement;
	IElementController controller = oldElement;
	if (controller != null && controller.EffectControlProvider == this)
		controller.EffectControlProvider = null;

	controller = e.NewElement;
	if (controller != null)
		controller.EffectControlProvider = this;
}

@samhouts samhouts added this to In Progress in v3.6.0 Oct 24, 2018

@samhouts samhouts removed this from In Progress in v3.6.0 Feb 2, 2019

@mkieres

This comment has been minimized.

Copy link
Contributor

commented Mar 29, 2019

Almost a year has passed and this is still an issue...Are there any plans to fix it?

@activa

This comment has been minimized.

Copy link
Contributor

commented May 1, 2019

This is still an issue in v3.6.0.

AndreiMisiukevich added a commit to AndreiMisiukevich/Xamarin.Forms that referenced this issue Jun 4, 2019

AndreiMisiukevich added a commit to AndreiMisiukevich/Xamarin.Forms that referenced this issue Jun 11, 2019

AndreiMisiukevich added a commit to AndreiMisiukevich/Xamarin.Forms that referenced this issue Jun 11, 2019

AndreiMisiukevich added a commit to AndreiMisiukevich/Xamarin.Forms that referenced this issue Jun 11, 2019

AndreiMisiukevich added a commit to AndreiMisiukevich/Xamarin.Forms that referenced this issue Jun 11, 2019

AndreiMisiukevich added a commit to AndreiMisiukevich/Xamarin.Forms that referenced this issue Jun 11, 2019

PureWeen added a commit to AndreiMisiukevich/Xamarin.Forms that referenced this issue Jun 18, 2019

@rmarinho rmarinho closed this in ec89cba Jun 19, 2019

Android Ready For Work automation moved this from To do to Done Jun 19, 2019

@KalyanXamarin

This comment has been minimized.

Copy link

commented Aug 9, 2019

Which version can I expect this release?

@jfversluis

This comment has been minimized.

Copy link
Member

commented Aug 9, 2019

@KalyanXamarin this is already available from 4.1 onwards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
7 participants
You can’t perform that action at this time.