Skip to content

Commit 8b5ca5c

Browse files
committed
Merge pull request #783 from BrianSakhai/master
Added ReactiveNavigationController
2 parents cb13925 + e882b32 commit 8b5ca5c

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
using System;
2+
using ReactiveUI;
3+
using System.Runtime.Serialization;
4+
using System.ComponentModel;
5+
using System.Reflection;
6+
using System.Reactive;
7+
using System.Reactive.Subjects;
8+
using System.Reactive.Concurrency;
9+
using System.Linq;
10+
using System.Threading;
11+
using System.Reactive.Disposables;
12+
using System.Diagnostics.Contracts;
13+
using System.Runtime.CompilerServices;
14+
using System.Collections.Generic;
15+
using System.Drawing;
16+
using Splat;
17+
18+
#if UNIFIED
19+
using Foundation;
20+
using UIKit;
21+
#else
22+
using MonoTouch.Foundation;
23+
using MonoTouch.UIKit;
24+
#endif
25+
26+
namespace ReactiveUI
27+
{
28+
public abstract class ReactiveNavigationController : UINavigationController,
29+
IReactiveNotifyPropertyChanged<ReactiveNavigationController>, IHandleObservableErrors, IReactiveObject, ICanActivate
30+
{
31+
protected ReactiveNavigationController(UIViewController rootViewController) : base(rootViewController) { setupRxObj(); }
32+
protected ReactiveNavigationController(Type navigationBarType, Type toolbarType) : base(navigationBarType, toolbarType) { setupRxObj(); }
33+
protected ReactiveNavigationController(string nibName, NSBundle bundle) : base(nibName, bundle) { setupRxObj(); }
34+
protected ReactiveNavigationController(IntPtr handle) : base(handle) { setupRxObj(); }
35+
protected ReactiveNavigationController(NSObjectFlag t) : base(t) { setupRxObj(); }
36+
protected ReactiveNavigationController(NSCoder coder) : base(coder) { setupRxObj(); }
37+
protected ReactiveNavigationController() { setupRxObj(); }
38+
39+
public event PropertyChangingEventHandler PropertyChanging {
40+
add { PropertyChangingEventManager.AddHandler(this, value); }
41+
remove { PropertyChangingEventManager.RemoveHandler(this, value); }
42+
}
43+
44+
void IReactiveObject.RaisePropertyChanging(PropertyChangingEventArgs args)
45+
{
46+
PropertyChangingEventManager.DeliverEvent(this, args);
47+
}
48+
49+
public event PropertyChangedEventHandler PropertyChanged {
50+
add { PropertyChangedEventManager.AddHandler(this, value); }
51+
remove { PropertyChangedEventManager.RemoveHandler(this, value); }
52+
}
53+
54+
void IReactiveObject.RaisePropertyChanged(PropertyChangedEventArgs args)
55+
{
56+
PropertyChangedEventManager.DeliverEvent(this, args);
57+
}
58+
59+
/// <summary>
60+
/// Represents an Observable that fires *before* a property is about to
61+
/// be changed.
62+
/// </summary>
63+
public IObservable<IReactivePropertyChangedEventArgs<ReactiveNavigationController>> Changing {
64+
get { return this.getChangingObservable(); }
65+
}
66+
67+
/// <summary>
68+
/// Represents an Observable that fires *after* a property has changed.
69+
/// </summary>
70+
public IObservable<IReactivePropertyChangedEventArgs<ReactiveNavigationController>> Changed {
71+
get { return this.getChangedObservable(); }
72+
}
73+
74+
public IObservable<Exception> ThrownExceptions { get { return this.getThrownExceptionsObservable(); } }
75+
76+
void setupRxObj()
77+
{
78+
}
79+
80+
/// <summary>
81+
/// When this method is called, an object will not fire change
82+
/// notifications (neither traditional nor Observable notifications)
83+
/// until the return value is disposed.
84+
/// </summary>
85+
/// <returns>An object that, when disposed, reenables change
86+
/// notifications.</returns>
87+
public IDisposable SuppressChangeNotifications()
88+
{
89+
return this.suppressChangeNotifications();
90+
}
91+
92+
Subject<Unit> activated = new Subject<Unit>();
93+
public IObservable<Unit> Activated { get { return activated; } }
94+
Subject<Unit> deactivated = new Subject<Unit>();
95+
public IObservable<Unit> Deactivated { get { return deactivated; } }
96+
97+
public override void ViewWillAppear(bool animated)
98+
{
99+
base.ViewWillAppear(animated);
100+
activated.OnNext(Unit.Default);
101+
this.ActivateSubviews(true);
102+
}
103+
104+
public override void ViewDidDisappear(bool animated)
105+
{
106+
base.ViewDidDisappear(animated);
107+
deactivated.OnNext(Unit.Default);
108+
this.ActivateSubviews(false);
109+
}
110+
}
111+
}
112+

ReactiveUI/ReactiveUI_iOS.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
<Compile Include="Cocoa\AutoSuspendHelper.cs" />
160160
<Compile Include="Legacy\ReactiveCommand.cs" />
161161
<Compile Include="Cocoa\ReactiveTabBarController.cs" />
162+
<Compile Include="Cocoa\ReactiveNavigationController.cs" />
162163
</ItemGroup>
163164
<ItemGroup>
164165
<None Include="packages.ReactiveUI_iOS.config" />

0 commit comments

Comments
 (0)