|
3 | 3 | using System.Runtime.Serialization; |
4 | 4 | using System.ComponentModel; |
5 | 5 | using System.Reflection; |
| 6 | +using System.Reactive; |
6 | 7 | using System.Reactive.Subjects; |
7 | 8 | using System.Reactive.Concurrency; |
8 | 9 | using System.Linq; |
|
16 | 17 | #if UIKIT |
17 | 18 | using MonoTouch.Foundation; |
18 | 19 | using MonoTouch.UIKit; |
| 20 | + |
19 | 21 | using NSImageView = MonoTouch.UIKit.UIImageView; |
20 | 22 | using NSImage = MonoTouch.UIKit.UIImage; |
| 23 | +using NSView = MonoTouch.UIKit.UIView; |
21 | 24 | #else |
22 | 25 | using MonoMac.AppKit; |
23 | 26 | #endif |
24 | 27 |
|
25 | 28 |
|
26 | 29 | namespace ReactiveUI.Cocoa |
27 | 30 | { |
28 | | - public abstract class ReactiveImageView : NSImageView, IReactiveNotifyPropertyChanged, IHandleObservableErrors |
| 31 | + public abstract class ReactiveImageView : NSImageView, IReactiveNotifyPropertyChanged, IHandleObservableErrors, ICanActivate |
29 | 32 | { |
30 | 33 | public ReactiveImageView(RectangleF frame) : base(frame) { setupRxObj(); } |
31 | 34 | public ReactiveImageView(IntPtr handle) : base(handle) { setupRxObj(); } |
@@ -79,6 +82,26 @@ public IObservable<IObservedChange<object, object>> Changed { |
79 | 82 | [IgnoreDataMember] |
80 | 83 | public IObservable<Exception> ThrownExceptions { get { return thrownExceptions; } } |
81 | 84 |
|
| 85 | + Subject<Unit> activated = new Subject<Unit>(); |
| 86 | + public IObservable<Unit> Activated { get { return activated; } } |
| 87 | + Subject<Unit> deactivated = new Subject<Unit>(); |
| 88 | + public IObservable<Unit> Deactivated { get { return deactivated; } } |
| 89 | + |
| 90 | +#if UIKIT |
| 91 | + public override void WillMoveToSuperview(NSView newsuper) |
| 92 | +#else |
| 93 | + public override void ViewWillMoveToSuperview(NSView newsuper) |
| 94 | +#endif |
| 95 | + { |
| 96 | +#if UIKIT |
| 97 | + base.WillMoveToSuperview(newsuper); |
| 98 | +#else |
| 99 | + base.ViewWillMoveToSuperview(newsuper); |
| 100 | +#endif |
| 101 | + |
| 102 | + RxApp.MainThreadScheduler.Schedule(() => (newsuper != null ? activated : deactivated).OnNext(Unit.Default)); |
| 103 | + } |
| 104 | + |
82 | 105 | [OnDeserialized] |
83 | 106 | void setupRxObj(StreamingContext sc) { setupRxObj(); } |
84 | 107 |
|
|
0 commit comments