Skip to content

Commit d379c89

Browse files
committed
Make all of the NSView derivatives signal activation
1 parent 8c0ff0f commit d379c89

File tree

4 files changed

+61
-4
lines changed

4 files changed

+61
-4
lines changed

ReactiveUI.Platforms/Cocoa/ReactiveCollectionViewCell.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Reflection;
77
using System.Reactive.Subjects;
88
using System.Reactive.Concurrency;
9+
using System.Reactive;
910
using System.Linq;
1011
using System.Threading;
1112
using System.Reactive.Disposables;
@@ -15,10 +16,11 @@
1516
using MonoTouch.Foundation;
1617
using MonoTouch.UIKit;
1718
using Splat;
19+
using ReactiveUI;
1820

1921
namespace ReactiveUI.Cocoa
2022
{
21-
public abstract class ReactiveCollectionViewCell : UICollectionViewCell, IReactiveNotifyPropertyChanged, IHandleObservableErrors, IReactiveObjectExtension
23+
public abstract class ReactiveCollectionViewCell : UICollectionViewCell, IReactiveNotifyPropertyChanged, IHandleObservableErrors, IReactiveObjectExtension, ICanActivate
2224
{
2325
public ReactiveCollectionViewCell(IntPtr handle) : base (handle) { setupRxObj(); }
2426
public ReactiveCollectionViewCell(NSObjectFlag t) : base (t) { setupRxObj(); }
@@ -78,5 +80,16 @@ public IDisposable SuppressChangeNotifications()
7880
{
7981
return this.suppressChangeNotifications();
8082
}
83+
84+
Subject<Unit> activated = new Subject<Unit>();
85+
public IObservable<Unit> Activated { get { return activated; } }
86+
Subject<Unit> deactivated = new Subject<Unit>();
87+
public IObservable<Unit> Deactivated { get { return deactivated; } }
88+
89+
public override void WillMoveToSuperview(UIView newsuper)
90+
{
91+
base.WillMoveToSuperview(newsuper);
92+
RxApp.MainThreadScheduler.Schedule(() => (newsuper != null ? activated : deactivated).OnNext(Unit.Default));
93+
}
8194
}
8295
}

ReactiveUI.Platforms/Cocoa/ReactiveImageView.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using System.Collections.Generic;
1414
using System.Drawing;
1515
using Splat;
16+
using System.Reactive;
1617

1718
#if UIKIT
1819
using MonoTouch.Foundation;
@@ -26,7 +27,7 @@
2627

2728
namespace ReactiveUI.Cocoa
2829
{
29-
public abstract class ReactiveImageView : NSImageView, IReactiveNotifyPropertyChanged, IHandleObservableErrors, IReactiveObjectExtension
30+
public abstract class ReactiveImageView : NSImageView, IReactiveNotifyPropertyChanged, IHandleObservableErrors, IReactiveObjectExtension, ICanActivate
3031
{
3132
public ReactiveImageView(RectangleF frame) : base(frame) { this.setupReactiveExtension(); }
3233
public ReactiveImageView(IntPtr handle) : base(handle) { this.setupReactiveExtension(); }
@@ -78,6 +79,21 @@ public IDisposable SuppressChangeNotifications() {
7879
}
7980

8081
public IObservable<Exception> ThrownExceptions { get { return this.getThrownExceptionsObservable(); } }
82+
83+
Subject<Unit> activated = new Subject<Unit>();
84+
public IObservable<Unit> Activated { get { return activated; } }
85+
Subject<Unit> deactivated = new Subject<Unit>();
86+
public IObservable<Unit> Deactivated { get { return deactivated; } }
87+
88+
#if UIKIT
89+
public override void WillMoveToSuperview(NSView newsuper)
90+
#else
91+
public override void ViewWillMoveToSuperview(NSView newsuper)
92+
#endif
93+
{
94+
base.WillMoveToSuperview(newsuper);
95+
RxApp.MainThreadScheduler.Schedule(() => (newsuper != null ? activated : deactivated).OnNext(Unit.Default));
96+
}
8197
}
8298
}
8399

ReactiveUI.Platforms/Cocoa/ReactiveNSView.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Runtime.CompilerServices;
1313
using System.Collections.Generic;
1414
using Splat;
15+
using System.Reactive;
1516

1617
#if UIKIT
1718
using MonoTouch.UIKit;
@@ -28,7 +29,7 @@ namespace ReactiveUI.Cocoa
2829
/// This is an View that is both an NSView and has ReactiveObject powers
2930
/// (i.e. you can call RaiseAndSetIfChanged)
3031
/// </summary>
31-
public class ReactiveView : NSView, IReactiveNotifyPropertyChanged, IHandleObservableErrors, IReactiveObjectExtension
32+
public class ReactiveView : NSView, IReactiveNotifyPropertyChanged, IHandleObservableErrors, IReactiveObjectExtension, ICanActivate
3233
{
3334
protected ReactiveView() : base()
3435
{
@@ -103,5 +104,20 @@ public IDisposable SuppressChangeNotifications()
103104
}
104105

105106
public IObservable<Exception> ThrownExceptions { get { return this.getThrownExceptionsObservable(); } }
107+
108+
Subject<Unit> activated = new Subject<Unit>();
109+
public IObservable<Unit> Activated { get { return activated; } }
110+
Subject<Unit> deactivated = new Subject<Unit>();
111+
public IObservable<Unit> Deactivated { get { return deactivated; } }
112+
113+
#if UIKIT
114+
public override void WillMoveToSuperview(NSView newsuper)
115+
#else
116+
public override void ViewWillMoveToSuperview(NSView newsuper)
117+
#endif
118+
{
119+
base.WillMoveToSuperview(newsuper);
120+
RxApp.MainThreadScheduler.Schedule(() => (newsuper != null ? activated : deactivated).OnNext(Unit.Default));
121+
}
106122
}
107123
}

ReactiveUI.Platforms/Cocoa/ReactiveTableViewCell.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
using MonoTouch.Foundation;
1616
using MonoTouch.UIKit;
1717
using Splat;
18+
using System.Reactive;
1819

1920
namespace ReactiveUI.Cocoa
2021
{
21-
public abstract class ReactiveTableViewCell : UITableViewCell, IReactiveNotifyPropertyChanged, IHandleObservableErrors, IReactiveObjectExtension
22+
public abstract class ReactiveTableViewCell : UITableViewCell, IReactiveNotifyPropertyChanged, IHandleObservableErrors, IReactiveObjectExtension, ICanActivate
2223
{
2324
public ReactiveTableViewCell(IntPtr handle) : base (handle) { setupRxObj(); }
2425
public ReactiveTableViewCell(NSObjectFlag t) : base (t) { setupRxObj(); }
@@ -81,5 +82,16 @@ public IDisposable SuppressChangeNotifications()
8182
{
8283
return this.suppressChangeNotifications();
8384
}
85+
86+
Subject<Unit> activated = new Subject<Unit>();
87+
public IObservable<Unit> Activated { get { return activated; } }
88+
Subject<Unit> deactivated = new Subject<Unit>();
89+
public IObservable<Unit> Deactivated { get { return deactivated; } }
90+
91+
public override void WillMoveToSuperview(UIView newsuper)
92+
{
93+
base.WillMoveToSuperview(newsuper);
94+
RxApp.MainThreadScheduler.Schedule(() => (newsuper != null ? activated : deactivated).OnNext(Unit.Default));
95+
}
8496
}
8597
}

0 commit comments

Comments
 (0)