Skip to content

Commit c7ed312

Browse files
committed
Merge remote-tracking branch 'origin/activation-5.4'
2 parents 99081f4 + c40f20b commit c7ed312

27 files changed

+697
-50
lines changed

ReactiveUI.Platforms/Android/ReactiveActivity.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Runtime.Serialization;
1212
using System.ComponentModel;
1313
using System.Reflection;
14+
using System.Reactive;
1415
using System.Reactive.Subjects;
1516
using System.Reactive.Concurrency;
1617
using System.Threading;
@@ -45,7 +46,7 @@ object IViewFor.ViewModel {
4546
/// This is an Activity that is both an Activity and has ReactiveObject powers
4647
/// (i.e. you can call RaiseAndSetIfChanged)
4748
/// </summary>
48-
public class ReactiveActivity : Activity, IReactiveNotifyPropertyChanged, IHandleObservableErrors
49+
public class ReactiveActivity : Activity, IReactiveNotifyPropertyChanged, IHandleObservableErrors, ICanActivate
4950
{
5051
protected ReactiveActivity()
5152
{
@@ -120,6 +121,24 @@ public IDisposable SuppressChangeNotifications()
120121
Interlocked.Decrement(ref changeNotificationsSuppressed));
121122
}
122123

124+
readonly Subject<Unit> activated = new Subject<Unit>();
125+
public IObservable<Unit> Activated { get { return activated; } }
126+
127+
readonly Subject<Unit> deactivated = new Subject<Unit>();
128+
public IObservable<Unit> Deactivated { get { return deactivated; } }
129+
130+
protected override void OnPause()
131+
{
132+
base.OnPause();
133+
deactivated.OnNext(Unit.Default);
134+
}
135+
136+
protected override void OnResume()
137+
{
138+
base.OnResume();
139+
activated.OnNext(Unit.Default);
140+
}
141+
123142
protected internal void raisePropertyChanging(string propertyName)
124143
{
125144
Contract.Requires(propertyName != null);

ReactiveUI.Platforms/Android/ReactiveFragment.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Runtime.Serialization;
1313
using System.ComponentModel;
1414
using System.Reflection;
15+
using System.Reactive;
1516
using System.Reactive.Subjects;
1617
using System.Reactive.Concurrency;
1718
using System.Threading;
@@ -46,7 +47,7 @@ object IViewFor.ViewModel {
4647
/// This is a Fragment that is both an Activity and has ReactiveObject powers
4748
/// (i.e. you can call RaiseAndSetIfChanged)
4849
/// </summary>
49-
public class ReactiveFragment : Fragment, IReactiveNotifyPropertyChanged, IHandleObservableErrors
50+
public class ReactiveFragment : Fragment, IReactiveNotifyPropertyChanged, IHandleObservableErrors, ICanActivate
5051
{
5152
protected ReactiveFragment()
5253
{
@@ -120,6 +121,24 @@ public IDisposable SuppressChangeNotifications()
120121
Interlocked.Decrement(ref changeNotificationsSuppressed));
121122
}
122123

124+
readonly Subject<Unit> activated = new Subject<Unit>();
125+
public IObservable<Unit> Activated { get { return activated; } }
126+
127+
readonly Subject<Unit> deactivated = new Subject<Unit>();
128+
public IObservable<Unit> Deactivated { get { return deactivated; } }
129+
130+
public override void OnPause()
131+
{
132+
base.OnPause();
133+
deactivated.OnNext(Unit.Default);
134+
}
135+
136+
public override void OnResume()
137+
{
138+
base.OnResume();
139+
activated.OnNext(Unit.Default);
140+
}
141+
123142
protected internal void raisePropertyChanging(string propertyName)
124143
{
125144
Contract.Requires(propertyName != null);

ReactiveUI.Platforms/Cocoa/ReactiveCollectionViewCell.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Runtime.Serialization;
55
using System.ComponentModel;
66
using System.Reflection;
7+
using System.Reactive;
78
using System.Reactive.Subjects;
89
using System.Reactive.Concurrency;
910
using System.Linq;
@@ -17,7 +18,7 @@
1718

1819
namespace ReactiveUI.Cocoa
1920
{
20-
public abstract class ReactiveCollectionViewCell : UICollectionViewCell, IReactiveNotifyPropertyChanged, IHandleObservableErrors
21+
public abstract class ReactiveCollectionViewCell : UICollectionViewCell, IReactiveNotifyPropertyChanged, IHandleObservableErrors, ICanActivate
2122
{
2223
public ReactiveCollectionViewCell(IntPtr handle) : base (handle) { setupRxObj(); }
2324
public ReactiveCollectionViewCell(NSObjectFlag t) : base (t) { setupRxObj(); }
@@ -90,6 +91,17 @@ public IDisposable SuppressChangeNotifications()
9091
return Disposable.Create(() => Interlocked.Decrement(ref changeNotificationsSuppressed));
9192
}
9293

94+
Subject<Unit> activated = new Subject<Unit>();
95+
public IObservable<Unit> Activated { get { return activated; } }
96+
Subject<Unit> deactivated = new Subject<Unit>();
97+
public IObservable<Unit> Deactivated { get { return deactivated; } }
98+
99+
public override void WillMoveToSuperview(UIView newsuper)
100+
{
101+
base.WillMoveToSuperview(newsuper);
102+
RxApp.MainThreadScheduler.Schedule(() => (newsuper != null ? activated : deactivated).OnNext(Unit.Default));
103+
}
104+
93105
protected internal void raisePropertyChanging(string propertyName)
94106
{
95107
Contract.Requires(propertyName != null);

ReactiveUI.Platforms/Cocoa/ReactiveImageView.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Runtime.Serialization;
44
using System.ComponentModel;
55
using System.Reflection;
6+
using System.Reactive;
67
using System.Reactive.Subjects;
78
using System.Reactive.Concurrency;
89
using System.Linq;
@@ -16,16 +17,18 @@
1617
#if UIKIT
1718
using MonoTouch.Foundation;
1819
using MonoTouch.UIKit;
20+
1921
using NSImageView = MonoTouch.UIKit.UIImageView;
2022
using NSImage = MonoTouch.UIKit.UIImage;
23+
using NSView = MonoTouch.UIKit.UIView;
2124
#else
2225
using MonoMac.AppKit;
2326
#endif
2427

2528

2629
namespace ReactiveUI.Cocoa
2730
{
28-
public abstract class ReactiveImageView : NSImageView, IReactiveNotifyPropertyChanged, IHandleObservableErrors
31+
public abstract class ReactiveImageView : NSImageView, IReactiveNotifyPropertyChanged, IHandleObservableErrors, ICanActivate
2932
{
3033
public ReactiveImageView(RectangleF frame) : base(frame) { setupRxObj(); }
3134
public ReactiveImageView(IntPtr handle) : base(handle) { setupRxObj(); }
@@ -79,6 +82,26 @@ public IObservable<IObservedChange<object, object>> Changed {
7982
[IgnoreDataMember]
8083
public IObservable<Exception> ThrownExceptions { get { return thrownExceptions; } }
8184

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+
82105
[OnDeserialized]
83106
void setupRxObj(StreamingContext sc) { setupRxObj(); }
84107

ReactiveUI.Platforms/Cocoa/ReactiveNSView.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Drawing;
33
using System.Runtime.Serialization;
4+
using System.Reactive;
45
using System.Reactive.Subjects;
56
using System.Reactive.Concurrency;
67
using System.Reflection;
@@ -27,7 +28,7 @@ namespace ReactiveUI.Cocoa
2728
/// This is an View that is both an NSView and has ReactiveObject powers
2829
/// (i.e. you can call RaiseAndSetIfChanged)
2930
/// </summary>
30-
public class ReactiveView : NSView, IReactiveNotifyPropertyChanged, IHandleObservableErrors
31+
public class ReactiveView : NSView, IReactiveNotifyPropertyChanged, IHandleObservableErrors, ICanActivate
3132
{
3233
protected ReactiveView() : base()
3334
{
@@ -95,6 +96,25 @@ public IObservable<IObservedChange<object, object>> Changed {
9596
[IgnoreDataMember]
9697
public IObservable<Exception> ThrownExceptions { get { return thrownExceptions; } }
9798

99+
Subject<Unit> activated = new Subject<Unit>();
100+
public IObservable<Unit> Activated { get { return activated; } }
101+
Subject<Unit> deactivated = new Subject<Unit>();
102+
public IObservable<Unit> Deactivated { get { return deactivated; } }
103+
104+
#if UIKIT
105+
public override void WillMoveToSuperview(NSView newsuper)
106+
#else
107+
public override void ViewWillMoveToSuperview(NSView newsuper)
108+
#endif
109+
{
110+
#if UIKIT
111+
base.WillMoveToSuperview(newsuper);
112+
#else
113+
base.ViewWillMoveToSuperview(newsuper);
114+
#endif
115+
RxApp.MainThreadScheduler.Schedule(() => (newsuper != null ? activated : deactivated).OnNext(Unit.Default));
116+
}
117+
98118
[OnDeserialized]
99119
void setupRxObj(StreamingContext sc) { setupRxObj(); }
100120

ReactiveUI.Platforms/Cocoa/ReactiveNSViewController.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Drawing;
33
using System.Runtime.Serialization;
4+
using System.Reactive;
45
using System.Reactive.Subjects;
56
using System.Reactive.Concurrency;
67
using System.Reflection;
@@ -28,6 +29,9 @@ namespace ReactiveUI.Cocoa
2829
/// (i.e. you can call RaiseAndSetIfChanged)
2930
/// </summary>
3031
public class ReactiveViewController : NSViewController, IReactiveNotifyPropertyChanged, IHandleObservableErrors
32+
#if UIKIT
33+
, ICanActivate
34+
#endif
3135
{
3236
protected ReactiveViewController() : base()
3337
{
@@ -121,6 +125,25 @@ public IDisposable SuppressChangeNotifications()
121125
Interlocked.Decrement(ref changeNotificationsSuppressed));
122126
}
123127

128+
#if UIKIT
129+
Subject<Unit> activated = new Subject<Unit>();
130+
public IObservable<Unit> Activated { get { return activated; } }
131+
Subject<Unit> deactivated = new Subject<Unit>();
132+
public IObservable<Unit> Deactivated { get { return deactivated; } }
133+
134+
public override void ViewDidLoad()
135+
{
136+
base.ViewDidLoad();
137+
activated.OnNext(Unit.Default);
138+
}
139+
140+
public override void ViewDidUnload()
141+
{
142+
base.ViewDidUnload();
143+
deactivated.OnNext(Unit.Default);
144+
}
145+
#endif
146+
124147
protected internal void raisePropertyChanging(string propertyName)
125148
{
126149
Contract.Requires(propertyName != null);

ReactiveUI.Platforms/Cocoa/ReactiveTableViewCell.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Runtime.Serialization;
55
using System.ComponentModel;
66
using System.Reflection;
7+
using System.Reactive;
78
using System.Reactive.Subjects;
89
using System.Reactive.Concurrency;
910
using System.Linq;
@@ -17,7 +18,7 @@
1718

1819
namespace ReactiveUI.Cocoa
1920
{
20-
public abstract class ReactiveTableViewCell : UITableViewCell, IReactiveNotifyPropertyChanged, IHandleObservableErrors
21+
public abstract class ReactiveTableViewCell : UITableViewCell, IReactiveNotifyPropertyChanged, IHandleObservableErrors, ICanActivate
2122
{
2223
public ReactiveTableViewCell(IntPtr handle) : base (handle) { setupRxObj(); }
2324
public ReactiveTableViewCell(NSObjectFlag t) : base (t) { setupRxObj(); }
@@ -92,6 +93,17 @@ public IDisposable SuppressChangeNotifications()
9293
return Disposable.Create(() => Interlocked.Decrement(ref changeNotificationsSuppressed));
9394
}
9495

96+
Subject<Unit> activated = new Subject<Unit>();
97+
public IObservable<Unit> Activated { get { return activated; } }
98+
Subject<Unit> deactivated = new Subject<Unit>();
99+
public IObservable<Unit> Deactivated { get { return deactivated; } }
100+
101+
public override void WillMoveToSuperview(UIView newsuper)
102+
{
103+
base.WillMoveToSuperview(newsuper);
104+
RxApp.MainThreadScheduler.Schedule(() => (newsuper != null ? activated : deactivated).OnNext(Unit.Default));
105+
}
106+
95107
protected internal void raisePropertyChanging(string propertyName)
96108
{
97109
Contract.Requires(propertyName != null);

ReactiveUI.Platforms/Cocoa/ReactiveTableViewController.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Runtime.Serialization;
44
using System.ComponentModel;
55
using System.Reflection;
6+
using System.Reactive;
67
using System.Reactive.Subjects;
78
using System.Reactive.Concurrency;
89
using System.Linq;
@@ -20,7 +21,7 @@
2021

2122
namespace ReactiveUI.Cocoa
2223
{
23-
public abstract class ReactiveTableViewController : NSTableViewController, IReactiveNotifyPropertyChanged, IHandleObservableErrors
24+
public abstract class ReactiveTableViewController : NSTableViewController, IReactiveNotifyPropertyChanged, IHandleObservableErrors, ICanActivate
2425
{
2526
protected ReactiveTableViewController(NSTableViewStyle withStyle) : base(withStyle) { setupRxObj(); }
2627
protected ReactiveTableViewController(string nibName, NSBundle bundle) : base(nibName, bundle) { setupRxObj(); }
@@ -94,6 +95,24 @@ public IDisposable SuppressChangeNotifications()
9495
return Disposable.Create(() => Interlocked.Decrement(ref changeNotificationsSuppressed));
9596
}
9697

98+
Subject<Unit> activated = new Subject<Unit>();
99+
public IObservable<Unit> Activated { get { return activated; } }
100+
Subject<Unit> deactivated = new Subject<Unit>();
101+
public IObservable<Unit> Deactivated { get { return deactivated; } }
102+
103+
public override void ViewDidLoad()
104+
{
105+
base.ViewDidLoad();
106+
activated.OnNext(Unit.Default);
107+
}
108+
109+
public override void ViewDidUnload()
110+
{
111+
base.ViewDidUnload();
112+
deactivated.OnNext(Unit.Default);
113+
}
114+
115+
97116
protected internal void raisePropertyChanging(string propertyName)
98117
{
99118
Contract.Requires(propertyName != null);

ReactiveUI.Platforms/Cocoa/ReactiveTableViewSource.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Specialized;
55
using System.Diagnostics.Contracts;
66
using System.Linq;
7+
using System.Reactive;
78
using System.Reactive.Concurrency;
89
using System.Reactive.Disposables;
910
using System.Reactive.Linq;

ReactiveUI.Platforms/ReactiveUI.Xaml_Net45.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,18 @@
130130
<Link>Xaml\Properties\CommonAssemblyInfo.cs</Link>
131131
</Compile>
132132
<Compile Include="ComponentModelTypeConverter.cs" />
133+
<Compile Include="Xaml\ActivationForViewFetcher.cs" />
133134
<Compile Include="Xaml\PlatformOperations.cs" />
134135
<Compile Include="PlatformUnitTestDetector.cs" />
135136
<Compile Include="Registrations.cs" />
136137
<Compile Include="Xaml\AutoDataTemplateBindingHook.cs" />
137138
<Compile Include="Xaml\BindingTypeConverters.cs" />
138139
<Compile Include="Xaml\CreatesCommandBinding.cs" />
139-
<Compile Include="Xaml\DependencyObjectObservableForProperty.cs" />
140140
<Compile Include="Xaml\Properties\AssemblyInfo.cs" />
141141
<Compile Include="Xaml\RoutedViewHost.cs" />
142142
<Compile Include="Xaml\TransitioningContentControl.cs" />
143143
<Compile Include="Xaml\ViewModelViewHost.cs" />
144+
<Compile Include="Xaml\WpfDependencyObjectObservableForProperty.cs" />
144145
<Compile Include="Xaml\XamlDefaultPropertyBinding.cs" />
145146
</ItemGroup>
146147
<ItemGroup>

0 commit comments

Comments
 (0)