Skip to content

Commit

Permalink
Try add some detections for maui view changing
Browse files Browse the repository at this point in the history
  • Loading branch information
Redth committed Mar 21, 2024
1 parent 96d2fdb commit c2df409
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions VirtualListView/Apple/CvCell.ios.maccatalyst.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using CoreGraphics;
using Foundation;
using Microsoft.Maui.Platform;
using Microsoft.VisualBasic;
using System.Diagnostics.CodeAnalysis;
using UIKit;

namespace Microsoft.Maui;
Expand Down Expand Up @@ -37,15 +35,15 @@ public override UIKeyCommand[] KeyCommands
get
{
if (keyCommands?.TryGetTarget(out var commands) ?? false)
return commands;
return commands;

var v = new[]
{
UIKeyCommand.Create(new NSString("\r"), 0, new ObjCRuntime.Selector("keyCommandSelect")),
UIKeyCommand.Create(new NSString(" "), 0, new ObjCRuntime.Selector("keyCommandSelect")),
};

keyCommands = new WeakReference<UIKeyCommand[]>(v);
keyCommands = new WeakReference<UIKeyCommand[]>(v);

return v;
}
Expand Down Expand Up @@ -119,33 +117,43 @@ public override void PrepareForReuse()

public void SetupView(IView view)
{
// Create a new platform native view if we don't have one yet
if (!(NativeView?.TryGetTarget(out var _) ?? false))
{
if (view is VisualElement ve) {
ve.MeasureInvalidated += (s, e) => {

Check warning on line 121 in VirtualListView/Apple/CvCell.ios.maccatalyst.cs

View workflow job for this annotation

GitHub Actions / Build

Subscribing to events with instance method '' could cause memory leaks in an NSObject subclass. Remove the subscription or convert the method to a static method.

Check warning on line 121 in VirtualListView/Apple/CvCell.ios.maccatalyst.cs

View workflow job for this annotation

GitHub Actions / Build

Subscribing to events with instance method '' could cause memory leaks in an NSObject subclass. Remove the subscription or convert the method to a static method.

Check warning on line 121 in VirtualListView/Apple/CvCell.ios.maccatalyst.cs

View workflow job for this annotation

GitHub Actions / Build

Subscribing to events with instance method '' could cause memory leaks in an NSObject subclass. Remove the subscription or convert the method to a static method.

Check warning on line 121 in VirtualListView/Apple/CvCell.ios.maccatalyst.cs

View workflow job for this annotation

GitHub Actions / Build

Subscribing to events with instance method '' could cause memory leaks in an NSObject subclass. Remove the subscription or convert the method to a static method.

Check warning on line 121 in VirtualListView/Apple/CvCell.ios.maccatalyst.cs

View workflow job for this annotation

GitHub Actions / Build

Subscribing to events with instance method '' could cause memory leaks in an NSObject subclass. Remove the subscription or convert the method to a static method.

Check warning on line 121 in VirtualListView/Apple/CvCell.ios.maccatalyst.cs

View workflow job for this annotation

GitHub Actions / Build

Subscribing to events with instance method '' could cause memory leaks in an NSObject subclass. Remove the subscription or convert the method to a static method.

Check warning on line 121 in VirtualListView/Apple/CvCell.ios.maccatalyst.cs

View workflow job for this annotation

GitHub Actions / Build

Subscribing to events with instance method '' could cause memory leaks in an NSObject subclass. Remove the subscription or convert the method to a static method.

Check warning on line 121 in VirtualListView/Apple/CvCell.ios.maccatalyst.cs

View workflow job for this annotation

GitHub Actions / Build

Subscribing to events with instance method '' could cause memory leaks in an NSObject subclass. Remove the subscription or convert the method to a static method.

Check warning on line 121 in VirtualListView/Apple/CvCell.ios.maccatalyst.cs

View workflow job for this annotation

GitHub Actions / Build

Subscribing to events with instance method '' could cause memory leaks in an NSObject subclass. Remove the subscription or convert the method to a static method.

Check warning on line 121 in VirtualListView/Apple/CvCell.ios.maccatalyst.cs

View workflow job for this annotation

GitHub Actions / Build

Subscribing to events with instance method '' could cause memory leaks in an NSObject subclass. Remove the subscription or convert the method to a static method.
System.Diagnostics.Debug.WriteLine("Measure invalidated");
//this.SizeToFit();
};
}
// if (view is VisualElement ve) {
// ve.SizeChanged += (s, e) => {
// this.SetNeedsLayout();
// };
// }

// Create a new platform native view if we don't have one yet
if (!(NativeView?.TryGetTarget(out var _) ?? false))
{
var nativeView = view.ToPlatform(this.Handler.MauiContext);
nativeView.Frame = this.ContentView.Frame;
nativeView.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth;

nativeView.Frame = this.ContentView.Frame;
nativeView.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth;
this.ContentView.AddSubview(nativeView);

NativeView = new WeakReference<UIView>(nativeView);
}
}

if (!(VirtualView?.TryGetTarget(out var virtualView) ?? false) || (virtualView?.Handler is null))
{
VirtualView = new WeakReference<IView>(view);
}
}
if (!(VirtualView?.TryGetTarget(out var virtualView) ?? false) || (virtualView?.Handler is null))
{
VirtualView = new WeakReference<IView>(view);
}
}

public void UpdatePosition(PositionInfo positionInfo)
{
PositionInfo = positionInfo;
if (VirtualView?.TryGetTarget(out var virtualView) ?? false)
PositionInfo = positionInfo;
if (VirtualView?.TryGetTarget(out var virtualView) ?? false)
{
if (virtualView is IPositionInfo viewPositionInfo)
viewPositionInfo.Update(positionInfo);
}
}
if (virtualView is IPositionInfo viewPositionInfo)
viewPositionInfo.Update(positionInfo);
}
}

class TapHandlerCallback
{
Expand Down

0 comments on commit c2df409

Please sign in to comment.