Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Xamarin.Forms.Platform.Android/AppCompat/ImageButtonRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,15 @@ void IVisualElementRenderer.SetElement(VisualElement element)
UpdateInputTransparent();
UpdatePadding();

ElementChanged?.Invoke(this, new VisualElementChangedEventArgs(oldElement, ImageButton));
OnElementChanged(new ElementChangedEventArgs<ImageButton>(oldElement, ImageButton));
ImageButton?.SendViewInitialized(Control);
}

protected virtual void OnElementChanged(ElementChangedEventArgs<ImageButton> e)
Copy link
Member

Choose a reason for hiding this comment

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

it's better to keep the virtual void OnElementChanged empty and invokes it after firing the event

Copy link
Contributor Author

@PureWeen PureWeen Nov 21, 2018

Choose a reason for hiding this comment

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

I mainly did it like this because this is how VisualElementRenderer does it
https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.Android/VisualElementRenderer.cs#L305

So I just copied that one for the sake of consistency

Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose it's possible for someone to want to control when (or whether) to invoke ElementChanged when they override OnElementChanged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the record I do agree with @StephaneDelcroix

But I did it this way because this is the same way we do it literally everywhere that I could find. So I feel like at this point consistency should be the winner

https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.iOS/Renderers/WkWebViewRenderer.cs#L126

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, agreed. Consistency is best. :/

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, agreed. Consistency is best. :/

disagreed, but I'm not going to die on this hill

{
ElementChanged?.Invoke(this, new VisualElementChangedEventArgs(e.OldElement, e.NewElement));
}

public override void Draw(Canvas canvas)
{
if (ImageButton == null)
Expand Down Expand Up @@ -258,8 +263,7 @@ void UpdateInputTransparent()
_inputTransparent = ImageButton.InputTransparent;
}

// Image related
void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
protected virtual void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == VisualElement.InputTransparentProperty.PropertyName)
UpdateInputTransparent();
Expand Down