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

[android] avoid OnLayout() for Label #21291

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.microsoft.maui;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatTextView;

public class PlatformAppCompatTextView extends AppCompatTextView {
public PlatformAppCompatTextView(@NonNull Context context) {
super(context);
}

private boolean isFormatted;

/**
* Sets isFormatted=true, used for FormattedString content
* @param text
* @param type
*/
@Override
public void setText(CharSequence text, BufferType type) {
isFormatted = !(text instanceof String);
super.setText(text, type);
}
Comment on lines +20 to +24
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that calling TextView.Text = "foo" will call inside here:

The C# TextView.Text property is bound to setText(CharSequence).


@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);

if (isFormatted) {
onLayoutFormatted(changed, left, top, right, bottom);
}
}

/**
* To be overridden from C#
* @param changed
* @param left
* @param top
* @param right
* @param bottom
*/
protected void onLayoutFormatted(boolean changed, int left, int top, int right, int bottom) { }
}
6 changes: 2 additions & 4 deletions src/Core/src/Platform/Android/MauiTextView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@

namespace Microsoft.Maui.Platform
{
public class MauiTextView : AppCompatTextView
public class MauiTextView : PlatformAppCompatTextView
{
public MauiTextView(Context context) : base(context)
{
}

internal event EventHandler<LayoutChangedEventArgs>? LayoutChanged;

protected override void OnLayout(bool changed, int l, int t, int r, int b)
internal override void OnLayoutFormatted(bool changed, int l, int t, int r, int b)
{
base.OnLayout(changed, l, t, r, b);

LayoutChanged?.Invoke(this, new LayoutChangedEventArgs(l, t, r, b));
}
}
Expand Down
1 change: 0 additions & 1 deletion src/Core/src/PublicAPI/net-android/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2253,7 +2253,6 @@ override Microsoft.Maui.Platform.MauiSwipeView.DispatchTouchEvent(Android.Views.
override Microsoft.Maui.Platform.MauiSwipeView.OnAttachedToWindow() -> void
override Microsoft.Maui.Platform.MauiSwipeView.OnInterceptTouchEvent(Android.Views.MotionEvent? e) -> bool
override Microsoft.Maui.Platform.MauiSwipeView.OnTouchEvent(Android.Views.MotionEvent? e) -> bool
override Microsoft.Maui.Platform.MauiTextView.OnLayout(bool changed, int l, int t, int r, int b) -> void
override Microsoft.Maui.Platform.MauiWebChromeClient.Dispose(bool disposing) -> void
override Microsoft.Maui.Platform.MauiWebViewClient.Dispose(bool disposing) -> void
override Microsoft.Maui.Platform.MauiWebViewClient.OnPageFinished(Android.Webkit.WebView? view, string? url) -> void
Expand Down
6 changes: 6 additions & 0 deletions src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Microsoft.Maui.KeyboardAcceleratorModifiers.None = 0 -> Microsoft.Maui.KeyboardA
Microsoft.Maui.KeyboardAcceleratorModifiers.Shift = 1 -> Microsoft.Maui.KeyboardAcceleratorModifiers
Microsoft.Maui.KeyboardAcceleratorModifiers.Windows = 16 -> Microsoft.Maui.KeyboardAcceleratorModifiers
Microsoft.Maui.Layouts.FlexBasis.Equals(Microsoft.Maui.Layouts.FlexBasis other) -> bool
Microsoft.Maui.PlatformAppCompatTextView
Microsoft.Maui.PlatformAppCompatTextView.PlatformAppCompatTextView(nint javaReference, Android.Runtime.JniHandleOwnership transfer) -> void
Microsoft.Maui.Platform.IImageSourcePartSetter
Microsoft.Maui.Platform.IImageSourcePartSetter.Handler.get -> Microsoft.Maui.IElementHandler?
Microsoft.Maui.Platform.IImageSourcePartSetter.ImageSourcePart.get -> Microsoft.Maui.IImageSourcePart?
Expand Down Expand Up @@ -64,10 +66,14 @@ override Microsoft.Maui.Handlers.ShapeViewHandler.GetDesiredSize(double widthCon
override Microsoft.Maui.Layouts.FlexBasis.Equals(object? obj) -> bool
override Microsoft.Maui.Layouts.FlexBasis.GetHashCode() -> int
override Microsoft.Maui.MauiAppCompatActivity.DispatchTouchEvent(Android.Views.MotionEvent? e) -> bool
override Microsoft.Maui.PlatformAppCompatTextView.JniPeerMembers.get -> Java.Interop.JniPeerMembers!
override Microsoft.Maui.PlatformAppCompatTextView.ThresholdClass.get -> nint
override Microsoft.Maui.PlatformAppCompatTextView.ThresholdType.get -> System.Type!
override Microsoft.Maui.Platform.ContentViewGroup.GetClipPath(int width, int height) -> Android.Graphics.Path?
override Microsoft.Maui.Platform.MauiMaterialButton.IconGravity.get -> int
override Microsoft.Maui.Platform.MauiMaterialButton.IconGravity.set -> void
override Microsoft.Maui.Platform.MauiScrollView.OnMeasure(int widthMeasureSpec, int heightMeasureSpec) -> void
*REMOVED*override Microsoft.Maui.Platform.MauiTextView.OnLayout(bool changed, int l, int t, int r, int b) -> void
override Microsoft.Maui.Platform.MauiMaterialButton.OnMeasure(int widthMeasureSpec, int heightMeasureSpec) -> void
override Microsoft.Maui.Platform.NavigationViewFragment.OnDestroy() -> void
override Microsoft.Maui.PlatformContentViewGroup.JniPeerMembers.get -> Java.Interop.JniPeerMembers!
Expand Down
8 changes: 5 additions & 3 deletions src/Core/src/Transforms/Metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
<!-- Make all classes internal by default -->
<attr path="//class[@visibility='public']" name="visibility">internal</attr>
<!-- Public classes -->
<attr path="//class[@name='PlatformAppCompatTextView']" name="visibility">public</attr>
<attr path="//class[@name='PlatformContentViewGroup']" name="visibility">public</attr>
<attr path="//class[@name='PlatformWrapperView']" name="visibility">public</attr>
<attr path="//class[@name='MauiViewGroup']" name="visibility">public</attr>
<!-- Internal methods & constructors -->
<attr path="//class[@name='PlatformAppCompatTextView']/method" name="visibility">internal</attr>
<attr path="//class[@name='PlatformAppCompatTextView']/constructor" name="visibility">internal</attr>

<!-- We subclass this so it needs to be public -->
<attr path="//package[@name='com.microsoft.maui']/class[@name='MauiViewGroup']" name="visibility">public</attr>

<remove-node path="//package[@name='com.bumptech.glide']" />
<remove-node path="//package[@name='com.microsoft.maui.glide']" />
<remove-node path="//package[@name='com.microsoft.maui.glide.font']" />
Expand Down
Binary file modified src/Core/src/maui.aar
Binary file not shown.