> getChildren = null)
- {
- PlatformBindingHelpers.SetBindingContext(target, bindingContext, getChildren);
- }
-
- internal static void TransferBindablePropertiesToWrapper(this global::Android.Views.View target, View wrapper)
- {
- PlatformBindingHelpers.TransferBindablePropertiesToWrapper(target, wrapper);
- }
- }
-}
\ No newline at end of file
diff --git a/src/Compatibility/Core/src/Android/Extensions/RecyclerExtensions.cs b/src/Compatibility/Core/src/Android/Extensions/RecyclerExtensions.cs
deleted file mode 100644
index 453a8ad5bf27..000000000000
--- a/src/Compatibility/Core/src/Android/Extensions/RecyclerExtensions.cs
+++ /dev/null
@@ -1,69 +0,0 @@
-using AndroidX.RecyclerView.Widget;
-using AView = Android.Views.View;
-
-namespace Microsoft.Maui.Controls.Compatibility.Platform.Android
-{
- internal static class RecyclerExtensions
- {
- public static int CalculateCenterItemIndex(this RecyclerView recyclerView, int firstVisibleItemIndex, LinearLayoutManager linearLayoutManager, bool lookCenteredOnXAndY)
- {
- // This can happen if a layout pass has not happened yet
- if (firstVisibleItemIndex == -1)
- return firstVisibleItemIndex;
-
- AView centerView;
-
- if (linearLayoutManager.Orientation == LinearLayoutManager.Horizontal)
- {
- float centerX = recyclerView.Width / 2;
- float centerY = recyclerView.Top;
-
- if (lookCenteredOnXAndY)
- centerY = recyclerView.Height / 2;
-
- centerView = recyclerView.FindChildViewUnder(centerX, centerY);
- }
- else
- {
- float centerY = recyclerView.Height / 2;
- float centerX = recyclerView.Left;
-
- if (lookCenteredOnXAndY)
- centerX = recyclerView.Width / 2;
-
- centerView = recyclerView.FindChildViewUnder(centerX, centerY);
- }
-
- if (centerView != null)
- return recyclerView.GetChildAdapterPosition(centerView);
-
- return firstVisibleItemIndex;
- }
-
- public static AView GetCenteredView(this RecyclerView recyclerView)
- {
- if (!(recyclerView.GetLayoutManager() is LinearLayoutManager linearLayoutManager))
- return null;
-
- AView centeredView;
- if (linearLayoutManager.Orientation == LinearLayoutManager.Horizontal)
- {
- float centerX = linearLayoutManager.Width / 2;
- float centerY = linearLayoutManager.Height / 2;
-
- centeredView = recyclerView.FindChildViewUnder(centerX, centerY);
- }
- else
- {
- float centerY = linearLayoutManager.Height / 2;
- float centerX = linearLayoutManager.Width / 2;
-
- centeredView = recyclerView.FindChildViewUnder(centerX, centerY);
- }
- return centeredView;
- }
-
-
- }
-
-}
\ No newline at end of file
diff --git a/src/Compatibility/Core/src/Android/Extensions/ScrollViewExtensions.cs b/src/Compatibility/Core/src/Android/Extensions/ScrollViewExtensions.cs
deleted file mode 100644
index c6b825f495cd..000000000000
--- a/src/Compatibility/Core/src/Android/Extensions/ScrollViewExtensions.cs
+++ /dev/null
@@ -1,44 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-using Android.App;
-using Android.Content;
-using Android.OS;
-using Android.Runtime;
-using Android.Views;
-using Android.Widget;
-
-namespace Microsoft.Maui.Controls.Compatibility.Platform.Android
-{
- internal static class ScrollViewExtensions
- {
- internal static void HandleScrollBarVisibilityChange(this IScrollView scrollView)
- {
- // According to the Android Documentation
- // * AwakenScrollBars method should be invoked every time a subclass directly updates
- // *the scroll parameters. p >
-
- // If AwakenScrollBars is never called there are cases where the ScrollDrawable is never called
- // which causes a crash during draw
-
- if (scrollView.ScrollBarsInitialized)
- scrollView.AwakenScrollBars();
-
- // The scrollbar drawable won't initialize if ScrollbarFadingEnabled == false
- if (!scrollView.ScrollbarFadingEnabled)
- {
- scrollView.ScrollbarFadingEnabled = true;
- scrollView.AwakenScrollBars();
- scrollView.ScrollbarFadingEnabled = false;
- }
- else
- {
- scrollView.AwakenScrollBars();
- }
-
- scrollView.ScrollBarsInitialized = true;
- }
- }
-}
\ No newline at end of file
diff --git a/src/Compatibility/Core/src/Android/Extensions/TextAlignmentExtensions.cs b/src/Compatibility/Core/src/Android/Extensions/TextAlignmentExtensions.cs
deleted file mode 100644
index 0e4b6445896b..000000000000
--- a/src/Compatibility/Core/src/Android/Extensions/TextAlignmentExtensions.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using Android.OS;
-using Android.Widget;
-using AGravityFlags = Android.Views.GravityFlags;
-
-namespace Microsoft.Maui.Controls.Compatibility.Platform.Android
-{
- [PortHandler]
- internal static class TextAlignmentExtensions
- {
- internal static void UpdateHorizontalAlignment(this EditText view, TextAlignment alignment, bool hasRtlSupport, AGravityFlags orMask = AGravityFlags.NoGravity)
- {
- if (!hasRtlSupport)
- view.Gravity = alignment.ToHorizontalGravityFlags() | orMask;
- else
- view.TextAlignment = alignment.ToTextAlignment();
- }
-
- internal static void UpdateVerticalAlignment(this EditText view, TextAlignment alignment, AGravityFlags orMask = AGravityFlags.NoGravity)
- {
- view.Gravity = alignment.ToVerticalGravityFlags() | orMask;
- }
-
- internal static void UpdateTextAlignment(this EditText view, TextAlignment horizontal, TextAlignment vertical)
- {
- if (!Rtl.IsSupported)
- {
- view.Gravity = vertical.ToVerticalGravityFlags() | horizontal.ToHorizontalGravityFlags();
- }
- else
- {
- view.TextAlignment = horizontal.ToTextAlignment();
- view.Gravity = vertical.ToVerticalGravityFlags();
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/Compatibility/Core/src/Android/Extensions/TextViewExtensions.cs b/src/Compatibility/Core/src/Android/Extensions/TextViewExtensions.cs
deleted file mode 100644
index 3a21e110b1b5..000000000000
--- a/src/Compatibility/Core/src/Android/Extensions/TextViewExtensions.cs
+++ /dev/null
@@ -1,157 +0,0 @@
-using System;
-using System.Collections.Generic;
-using Android.Text;
-using Android.Widget;
-using Microsoft.Maui.Controls.Internals;
-
-namespace Microsoft.Maui.Controls.Compatibility.Platform.Android
-{
- internal static class TextViewExtensions
- {
- [PortHandler]
- public static void SetMaxLines(this TextView textView, Label label)
- {
- var maxLines = label.MaxLines;
-
- if (maxLines == (int)Label.MaxLinesProperty.DefaultValue)
- {
- // MaxLines is not explicitly set, so just let it be whatever gets set by LineBreakMode
- textView.SetLineBreakMode(label);
- return;
- }
-
- textView.SetMaxLines(maxLines);
- }
-
- public static void SetLineBreakMode(this TextView textView, Label label)
- {
- var maxLines = SetLineBreak(textView, label.LineBreakMode);
- textView.SetMaxLines(maxLines);
- }
-
- public static void SetLineBreakMode(this TextView textView, Button button) =>
- SetLineBreak(textView, button.LineBreakMode);
-
- [PortHandler]
- public static int SetLineBreak(TextView textView, LineBreakMode lineBreakMode)
- {
- int maxLines = Int32.MaxValue;
- bool singleLine = false;
-
- switch (lineBreakMode)
- {
- case LineBreakMode.NoWrap:
- maxLines = 1;
- singleLine = true;
- textView.Ellipsize = null;
- break;
- case LineBreakMode.WordWrap:
- textView.Ellipsize = null;
- break;
- case LineBreakMode.CharacterWrap:
- textView.Ellipsize = null;
- break;
- case LineBreakMode.HeadTruncation:
- maxLines = 1;
- singleLine = true; // Workaround for bug in older Android API versions (https://bugzilla.xamarin.com/show_bug.cgi?id=49069)
- textView.Ellipsize = TextUtils.TruncateAt.Start;
- break;
- case LineBreakMode.TailTruncation:
- maxLines = 1;
- singleLine = true;
- textView.Ellipsize = TextUtils.TruncateAt.End;
- break;
- case LineBreakMode.MiddleTruncation:
- maxLines = 1;
- singleLine = true; // Workaround for bug in older Android API versions (https://bugzilla.xamarin.com/show_bug.cgi?id=49069)
- textView.Ellipsize = TextUtils.TruncateAt.Middle;
- break;
- }
-
- textView.SetSingleLine(singleLine);
- return maxLines;
- }
-
- public static void RecalculateSpanPositions(this TextView textView, Label element, SpannableString spannableString, SizeRequest finalSize)
- {
- if (element?.FormattedText?.Spans == null || element.FormattedText.Spans.Count == 0)
- return;
-
- var labelWidth = finalSize.Request.Width;
- if (labelWidth <= 0 || finalSize.Request.Height <= 0)
- return;
-
- if (spannableString == null || spannableString.IsDisposed())
- return;
-
- var layout = textView.Layout;
- if (layout == null)
- return;
-
- int next = 0;
- int count = 0;
- IList totalLineHeights = new List();
-
-#pragma warning disable CA1416 // https://github.com/xamarin/xamarin-android/issues/6962
- for (int i = 0; i < spannableString.Length(); i = next)
- {
- var type = Java.Lang.Class.FromType(typeof(Java.Lang.Object));
-
- var span = element.FormattedText.Spans[count];
-
- count++;
-
- if (string.IsNullOrEmpty(span.Text))
- continue;
-
- // find the next span
- next = spannableString.NextSpanTransition(i, spannableString.Length(), type);
-#pragma warning restore CA1416
-
- // get all spans in the range - Android can have overlapping spans
- var spans = spannableString.GetSpans(i, next, type);
-
- var startSpan = spans[0];
- var endSpan = spans[spans.Length - 1];
-
- var startSpanOffset = spannableString.GetSpanStart(startSpan);
- var endSpanOffset = spannableString.GetSpanEnd(endSpan);
-
- var thisLine = layout.GetLineForOffset(endSpanOffset);
- var lineStart = layout.GetLineStart(thisLine);
- var lineEnd = layout.GetLineEnd(thisLine);
-
- //If this is true, endSpanOffset has the value for another line that belong to the next span and not it self.
- //So it should be rearranged to value not pass the lineEnd.
- if (endSpanOffset > (lineEnd - lineStart))
- endSpanOffset = lineEnd;
-
- var startX = layout.GetPrimaryHorizontal(startSpanOffset);
- var endX = layout.GetPrimaryHorizontal(endSpanOffset);
-
- var startLine = layout.GetLineForOffset(startSpanOffset);
- var endLine = layout.GetLineForOffset(endSpanOffset);
-
- double[] lineHeights = new double[endLine - startLine + 1];
-
- // calculate all the different line heights
- for (var lineCount = startLine; lineCount <= endLine; lineCount++)
- {
- var lineHeight = layout.GetLineBottom(lineCount) - layout.GetLineTop(lineCount);
- lineHeights[lineCount - startLine] = lineHeight;
-
- if (totalLineHeights.Count <= lineCount)
- totalLineHeights.Add(lineHeight);
- }
-
- var yaxis = 0.0;
-
-
- for (var line = startLine; line > 0; line--)
- yaxis += totalLineHeights[line];
-
- ((ISpatialElement)span).Region = Region.FromLines(lineHeights, labelWidth, startX, endX, yaxis).Inflate(10);
- }
- }
- }
-}
diff --git a/src/Compatibility/Core/src/Android/Extensions/TransformExtensions.cs b/src/Compatibility/Core/src/Android/Extensions/TransformExtensions.cs
deleted file mode 100644
index 796f4efb64fe..000000000000
--- a/src/Compatibility/Core/src/Android/Extensions/TransformExtensions.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-using Microsoft.Maui.Controls.Shapes;
-using AMatrix = Android.Graphics.Matrix;
-
-namespace Microsoft.Maui.Controls.Compatibility.Platform.Android
-{
- public static class TransformExtensions
- {
- public static AMatrix ToAndroid(this Transform transform, float density = 1)
- {
- AMatrix aMatrix = new AMatrix();
-
- if (transform == null)
- return aMatrix;
-
- Matrix matrix = transform.Value;
-
- aMatrix.SetValues(
- new float[] {
- (float)matrix.M11,
- (float)matrix.M21,
- (float)matrix.OffsetX * density,
- (float)matrix.M12,
- (float)matrix.M22,
- (float)matrix.OffsetY * density,
- 0,
- 0,
- 1 });
-
- return aMatrix;
- }
- }
-}
\ No newline at end of file
diff --git a/src/Compatibility/Core/src/Android/FastRenderers/AutomationPropertiesProvider.cs b/src/Compatibility/Core/src/Android/FastRenderers/AutomationPropertiesProvider.cs
deleted file mode 100644
index d5db18c31acb..000000000000
--- a/src/Compatibility/Core/src/Android/FastRenderers/AutomationPropertiesProvider.cs
+++ /dev/null
@@ -1,115 +0,0 @@
-using System;
-using System.ComponentModel;
-using Android.Views;
-using Android.Widget;
-using Microsoft.Maui.Controls.Platform;
-using AView = Android.Views.View;
-
-namespace Microsoft.Maui.Controls.Compatibility.Platform.Android.FastRenderers
-{
- internal class AutomationPropertiesProvider : IDisposable
- {
- string _defaultContentDescription;
- string _defaultHint;
- bool _disposed;
-
- IVisualElementRenderer _renderer;
-
- public AutomationPropertiesProvider(IVisualElementRenderer renderer)
- {
- _renderer = renderer;
- _renderer.ElementPropertyChanged += OnElementPropertyChanged;
- _renderer.ElementChanged += OnElementChanged;
- }
-
- AView Control => _renderer?.View;
-
- VisualElement Element => _renderer?.Element;
-
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- protected virtual void Dispose(bool disposing)
- {
- if (_disposed)
- {
- return;
- }
-
- _disposed = true;
-
- if (Element != null)
- {
- Element.PropertyChanged -= OnElementPropertyChanged;
- }
-
- if (_renderer != null)
- {
- _renderer.ElementChanged -= OnElementChanged;
- _renderer.ElementPropertyChanged -= OnElementPropertyChanged;
-
- _renderer = null;
- }
- }
-
- void SetContentDescription()
- => Controls.Platform.AutomationPropertiesProvider.SetContentDescription(Control, Element, _defaultContentDescription, _defaultHint);
-
- void SetImportantForAccessibility()
- => Controls.Platform.AutomationPropertiesProvider.SetImportantForAccessibility(Control, Element);
-
- void SetLabeledBy()
- => Controls.Platform.AutomationPropertiesProvider.SetLabeledBy(Control, Element);
-
- bool _defaultsSet;
- void SetupDefaults()
- {
- if (_defaultsSet || Control == null)
- return;
-
- _defaultsSet = true;
- Controls.Platform.AutomationPropertiesProvider.SetupDefaults(Control, ref _defaultHint, ref _defaultContentDescription);
- }
-
- void OnElementChanged(object sender, VisualElementChangedEventArgs e)
- {
- if (e.OldElement != null)
- {
- e.OldElement.PropertyChanged -= OnElementPropertyChanged;
- }
-
- if (e.NewElement != null)
- {
- e.NewElement.PropertyChanged += OnElementPropertyChanged;
- }
-
- SetupDefaults();
- Controls.Platform.AutomationPropertiesProvider.AccessibilitySettingsChanged(Control, Element, _defaultHint, _defaultContentDescription);
- }
-
- void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
- {
-#pragma warning disable CS0618 // Type or member is obsolete
- if (e.PropertyName == AutomationProperties.HelpTextProperty.PropertyName)
- {
- SetContentDescription();
- }
- else if (e.PropertyName == AutomationProperties.NameProperty.PropertyName)
- {
- SetContentDescription();
- }
- else if (e.PropertyName == AutomationProperties.IsInAccessibleTreeProperty.PropertyName)
- {
- SetImportantForAccessibility();
- }
- else if (e.PropertyName == AutomationProperties.LabeledByProperty.PropertyName)
- {
- SetLabeledBy();
- }
-#pragma warning restore CS0618 // Type or member is obsolete
- }
- }
-}
diff --git a/src/Compatibility/Core/src/Android/FastRenderers/ButtonRenderer.cs b/src/Compatibility/Core/src/Android/FastRenderers/ButtonRenderer.cs
deleted file mode 100644
index 290aa9fb9684..000000000000
--- a/src/Compatibility/Core/src/Android/FastRenderers/ButtonRenderer.cs
+++ /dev/null
@@ -1,396 +0,0 @@
-using System;
-using System.ComponentModel;
-using Android.Content;
-using Android.Graphics;
-using Android.Util;
-using Android.Views;
-using AndroidX.AppCompat.Widget;
-using AndroidX.Core.View;
-using Microsoft.Maui.Controls.Internals;
-using Microsoft.Maui.Controls.Platform;
-using Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;
-using AColor = Android.Graphics.Color;
-using AView = Android.Views.View;
-
-namespace Microsoft.Maui.Controls.Compatibility.Platform.Android.FastRenderers
-{
- [System.Obsolete(Compatibility.Hosting.MauiAppBuilderExtensions.UseMapperInstead)]
- public class ButtonRenderer : AppCompatButton,
- IBorderVisualElementRenderer, IButtonLayoutRenderer, IVisualElementRenderer, IViewRenderer, ITabStop,
- AView.IOnAttachStateChangeListener, AView.IOnFocusChangeListener, AView.IOnClickListener, AView.IOnTouchListener
- {
- float _defaultFontSize;
- int? _defaultLabelFor;
- Typeface _defaultTypeface;
- bool _isDisposed;
- bool _inputTransparent;
- Lazy _textColorSwitcher;
- AutomationPropertiesProvider _automationPropertiesProvider;
- VisualElementTracker _tracker;
- VisualElementRenderer _visualElementRenderer;
- BorderBackgroundManager _backgroundTracker;
- ButtonLayoutManager _buttonLayoutManager;
- IPlatformElementConfiguration _platformElementConfiguration;
- Button _button;
- bool _hasLayoutOccurred;
-
- public event EventHandler ElementChanged;
- public event EventHandler ElementPropertyChanged;
-
- public ButtonRenderer(Context context) : base(context)
- {
- Initialize();
- }
-
- protected Button Element => Button;
- protected AppCompatButton Control => this;
-
- VisualElement IBorderVisualElementRenderer.Element => Element;
-
- VisualElement IVisualElementRenderer.Element => Element;
- AView IVisualElementRenderer.View => this;
- VisualElementTracker IVisualElementRenderer.Tracker => _tracker;
-
- Button Button
- {
- get => _button;
- set
- {
- _button = value;
- _platformElementConfiguration = null;
- }
- }
-
- AView ITabStop.TabStop => this;
-
- void IOnClickListener.OnClick(AView v) => ButtonElementManager.OnClick(Button, Button, v);
-
- bool IOnTouchListener.OnTouch(AView v, MotionEvent e) => ButtonElementManager.OnTouch(Button, Button, v, e);
-
- void IOnAttachStateChangeListener.OnViewAttachedToWindow(AView attachedView) =>
- _buttonLayoutManager.OnViewAttachedToWindow(attachedView);
-
- void IOnAttachStateChangeListener.OnViewDetachedFromWindow(AView detachedView) =>
- _buttonLayoutManager.OnViewDetachedFromWindow(detachedView);
-
- [PortHandler]
- void IOnFocusChangeListener.OnFocusChange(AView v, bool hasFocus)
- {
- ((IElementController)Button).SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, hasFocus);
- }
-
- SizeRequest IVisualElementRenderer.GetDesiredSize(int widthConstraint, int heightConstraint)
- {
- if (_isDisposed)
- {
- return new SizeRequest();
- }
-
- var hint = Control.Hint;
- bool setHint = Control.LayoutParameters != null;
-
- if (!string.IsNullOrWhiteSpace(hint) && setHint)
- {
- Control.Hint = string.Empty;
- }
-
- var result = _buttonLayoutManager.GetDesiredSize(widthConstraint, heightConstraint);
-
- if (setHint)
- Control.Hint = hint;
-
- return result;
- }
-
- void IVisualElementRenderer.SetElement(VisualElement element)
- {
- if (element == null)
- {
- throw new ArgumentNullException(nameof(element));
- }
-
- if (!(element is Button))
- {
- throw new ArgumentException($"{nameof(element)} must be of type {nameof(Button)}");
- }
-
- VisualElement oldElement = Button;
- Button = (Button)element;
-
- Performance.Start(out string reference);
-
- OnElementChanged(new ElementChangedEventArgs