Skip to content

Commit 6714a2a

Browse files
authored
Merge pull request #33 from muak/fixCommand
Fix command
2 parents 31dc08c + ce6ebff commit 6714a2a

File tree

94 files changed

+2915
-1186
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+2915
-1186
lines changed

AiForms.Effects.Droid/AddCommandPlatformEffect.cs

+23-310
Large diffs are not rendered by default.

AiForms.Effects.Droid/AddDatePickerPlatformEffect.cs

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
[assembly: ExportEffect(typeof(AddDatePickerPlatformEffect), nameof(AddDatePicker))]
1010
namespace AiForms.Effects.Droid
1111
{
12+
[Android.Runtime.Preserve(AllMembers = true)]
1213
public class AddDatePickerPlatformEffect : AiEffectBase
1314
{
1415
Android.Views.View _view;
@@ -17,6 +18,8 @@ public class AddDatePickerPlatformEffect : AiEffectBase
1718

1819
protected override void OnAttached()
1920
{
21+
base.OnAttached();
22+
2023
_view = Control ?? Container;
2124

2225
_view.Touch += _view_Touch;
@@ -29,13 +32,15 @@ protected override void OnDetached()
2932
var renderer = Container as IVisualElementRenderer;
3033
if (!IsDisposed) {
3134
_view.Touch -= _view_Touch;
35+
System.Diagnostics.Debug.WriteLine($"{this.GetType().FullName} Detached Disposing");
3236
}
3337
if (_dialog != null) {
3438
_dialog.Dispose();
3539
_dialog = null;
3640
}
3741
_view = null;
3842
_command = null;
43+
System.Diagnostics.Debug.WriteLine($"{this.GetType().FullName} Detached completely");
3944
}
4045

4146
protected override void OnElementPropertyChanged(System.ComponentModel.PropertyChangedEventArgs e)

AiForms.Effects.Droid/AddNumberPickerPlatform.cs

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
[assembly: ExportEffect(typeof(AddNumberPickerPlatform), nameof(AddNumberPicker))]
1212
namespace AiForms.Effects.Droid
1313
{
14+
[Android.Runtime.Preserve(AllMembers = true)]
1415
public class AddNumberPickerPlatform : AiEffectBase
1516
{
1617
private AlertDialog _dialog;
@@ -22,6 +23,8 @@ public class AddNumberPickerPlatform : AiEffectBase
2223

2324
protected override void OnAttached()
2425
{
26+
base.OnAttached();
27+
2528
_view = Control ?? Container;
2629

2730
_view.Touch += _view_Touch;
@@ -41,13 +44,15 @@ protected override void OnDetached()
4144
{
4245
if (!IsDisposed) {
4346
_view.Touch -= _view_Touch;
47+
System.Diagnostics.Debug.WriteLine($"{this.GetType().FullName} Detached Disposing");
4448
}
4549
if (_dialog != null) {
4650
_dialog.Dispose();
4751
_dialog = null;
4852
}
4953
_view = null;
5054
_command = null;
55+
System.Diagnostics.Debug.WriteLine($"{this.GetType().FullName} Detached completely");
5156
}
5257

5358
protected override void OnElementPropertyChanged(System.ComponentModel.PropertyChangedEventArgs e)

AiForms.Effects.Droid/AddTextPlatformEffect.cs

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
[assembly: ExportEffect(typeof(AddTextPlatformEffect), nameof(AddText))]
1111
namespace AiForms.Effects.Droid
1212
{
13+
[Android.Runtime.Preserve(AllMembers = true)]
1314
public class AddTextPlatformEffect : AiEffectBase
1415
{
1516
private TextView _textView;
@@ -20,6 +21,8 @@ public class AddTextPlatformEffect : AiEffectBase
2021

2122
protected override void OnAttached()
2223
{
24+
base.OnAttached();
25+
2326
_container = Container;
2427

2528
_textView = new TextView(_context);
@@ -59,6 +62,7 @@ protected override void OnDetached()
5962
Control.RemoveOnLayoutChangeListener(_fastListener);
6063
_fastListener.CleanUp();
6164
}
65+
System.Diagnostics.Debug.WriteLine($"{this.GetType().FullName} Detached Disposing");
6266
}
6367

6468
_listener?.Dispose();
@@ -69,6 +73,7 @@ protected override void OnDetached()
6973

7074
_fastListener?.Dispose();
7175
_fastListener = null;
76+
System.Diagnostics.Debug.WriteLine($"{this.GetType().FullName} Detached completely");
7277
}
7378

7479
protected override void OnElementPropertyChanged(System.ComponentModel.PropertyChangedEventArgs args)

AiForms.Effects.Droid/AddTimePickerPlatformEffect.cs

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
[assembly: ExportEffect(typeof(AddTimePickerPlatformEffect), nameof(AddTimePicker))]
1111
namespace AiForms.Effects.Droid
1212
{
13+
[Android.Runtime.Preserve(AllMembers = true)]
1314
public class AddTimePickerPlatformEffect : AiEffectBase
1415
{
1516
Android.Views.View _view;
@@ -19,6 +20,8 @@ public class AddTimePickerPlatformEffect : AiEffectBase
1920

2021
protected override void OnAttached()
2122
{
23+
base.OnAttached();
24+
2225
_view = Control ?? Container;
2326

2427
_view.Touch += _view_Touch;
@@ -31,13 +34,15 @@ protected override void OnDetached()
3134
{
3235
if (!IsDisposed) {
3336
_view.Touch -= _view_Touch;
37+
System.Diagnostics.Debug.WriteLine($"{this.GetType().FullName} Detached Disposing");
3438
}
3539
if (_dialog != null) {
3640
_dialog.Dispose();
3741
_dialog = null;
3842
}
3943
_view = null;
4044
_command = null;
45+
System.Diagnostics.Debug.WriteLine($"{this.GetType().FullName} Detached completely");
4146
}
4247

4348
protected override void OnElementPropertyChanged(System.ComponentModel.PropertyChangedEventArgs e)

AiForms.Effects.Droid/AddTouchPlatformEffect.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
[assembly: ExportEffect(typeof(AddTouchPlatformEffect), nameof(AddTouch))]
1010
namespace AiForms.Effects.Droid
1111
{
12-
public class AddTouchPlatformEffect:PlatformEffect
12+
[Android.Runtime.Preserve(AllMembers = true)]
13+
public class AddTouchPlatformEffect:AiEffectBase
1314
{
1415
WeakReference<Android.Views.View> _viewRef;
1516
TouchRecognizer _recognizer;
1617
Context _context;
1718

1819
protected override void OnAttached()
1920
{
21+
base.OnAttached();
22+
2023
_viewRef = new WeakReference<Android.Views.View>(Control ?? Container);
2124

2225

@@ -62,9 +65,19 @@ void _view_Touch(object sender, Android.Views.View.TouchEventArgs e)
6265

6366
protected override void OnDetached()
6467
{
68+
if(!IsDisposed)
69+
{
70+
if (_viewRef.TryGetTarget(out var view))
71+
{
72+
view.Touch -= _view_Touch;
73+
}
74+
System.Diagnostics.Debug.WriteLine($"{this.GetType().FullName} Detached Disposing");
75+
}
76+
Element.ClearValue(AddTouch.RecognizerProperty);
6577
_context = null;
6678
_recognizer = null;
6779
_viewRef = null;
80+
System.Diagnostics.Debug.WriteLine($"{this.GetType().FullName} Detached completely");
6881
}
6982

7083
}

AiForms.Effects.Droid/AiEffectBase.cs

+48
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
using System.Linq.Expressions;
44
using System.Reflection;
55
using System.Linq;
6+
using Xamarin.Forms;
67

78
namespace AiForms.Effects.Droid
89
{
10+
[Android.Runtime.Preserve(AllMembers = true)]
911
public abstract class AiEffectBase : PlatformEffect
1012
{
1113
public static bool IsFastRenderers = global::Xamarin.Forms.Forms.Flags.Any(x => x == "FastRenderers_Experimental");
1214

1315
IVisualElementRenderer _renderer;
1416
bool _isDisposed = false;
17+
WeakReference<NavigationPage> _navigationRef;
18+
1519
protected bool IsDisposed {
1620
get {
1721
if (_isDisposed) {
@@ -30,6 +34,21 @@ protected bool IsDisposed {
3034
}
3135
}
3236

37+
protected override void OnAttached()
38+
{
39+
var visual = Element as VisualElement;
40+
var naviCandidate = visual.Navigation.NavigationStack.FirstOrDefault()?.Parent as NavigationPage;
41+
if(naviCandidate != null)
42+
{
43+
naviCandidate.Popped += PagePopped;
44+
_navigationRef = new WeakReference<NavigationPage>(naviCandidate);
45+
}
46+
47+
// Use not Popped but Popping because it is too late.
48+
Xamarin.Forms.Application.Current.ModalPopping += ModalPopping;
49+
}
50+
51+
3352
// whether Element is FastRenderer.(Exept Button)
3453
protected bool IsFastRenderer{
3554
get{
@@ -82,5 +101,34 @@ Func<object, object> CreateGetField(Type t)
82101

83102
return lambda.Compile();
84103
}
104+
105+
void PagePopped(object sender, NavigationEventArgs e)
106+
{
107+
Clear();
108+
}
109+
110+
void ModalPopping(object sender, ModalPoppingEventArgs e)
111+
{
112+
Clear();
113+
}
114+
115+
void Clear()
116+
{
117+
if (_navigationRef != null && _navigationRef.TryGetTarget(out var navi))
118+
{
119+
navi.Popped -= PagePopped;
120+
}
121+
Xamarin.Forms.Application.Current.ModalPopping -= ModalPopping;
122+
_navigationRef = null;
123+
124+
// For Android, when a page is popped, OnDetached is automatically not called. (when iOS, it is called)
125+
// So, made the Popped & ModalPopped event subscribe in advance
126+
// and make the effect manually removed when the page is popped.
127+
if (IsAttached && !IsDisposed)
128+
{
129+
var toRemove = Element.Effects.OfType<AiRoutingEffectBase>().FirstOrDefault(x => x.EffectId == ResolveId);
130+
Element.Effects.Remove(toRemove);
131+
}
132+
}
85133
}
86134
}

0 commit comments

Comments
 (0)