Skip to content

Commit 6854ed6

Browse files
committed
2 parents 5e7c076 + 8b5ca5c commit 6854ed6

File tree

5 files changed

+133
-3
lines changed

5 files changed

+133
-3
lines changed

ReactiveUI.Testing/TestUtils.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace ReactiveUI.Testing
1212
{
1313
public static class TestUtils
1414
{
15-
static readonly object schedGate = 42;
15+
static readonly AutoResetEvent schedGate = new AutoResetEvent(true);
1616
static readonly object mbGate = 42;
1717

1818
/// <summary>
@@ -26,7 +26,7 @@ public static class TestUtils
2626
/// schedulers.</returns>
2727
public static IDisposable WithScheduler(IScheduler sched)
2828
{
29-
Monitor.Enter(schedGate);
29+
schedGate.WaitOne();
3030
var prevDef = RxApp.MainThreadScheduler;
3131
var prevTask = RxApp.TaskpoolScheduler;
3232

@@ -36,7 +36,7 @@ public static IDisposable WithScheduler(IScheduler sched)
3636
return Disposable.Create(() => {
3737
RxApp.MainThreadScheduler = prevDef;
3838
RxApp.TaskpoolScheduler = prevTask;
39-
Monitor.Exit(schedGate);
39+
schedGate.Set();
4040
});
4141
}
4242

ReactiveUI.Tests/ReactiveUI.Tests_Net45.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
<Compile Include="AwaiterTest.cs" />
104104
<Compile Include="BindingTypeConvertersTest.cs" />
105105
<Compile Include="CommandBindingTests.cs" />
106+
<Compile Include="TestUtilsTest.cs" />
106107
<Compile Include="WeakEventManagerTest.cs" />
107108
<Compile Include="Winforms\ActivationTests.cs" />
108109
<Compile Include="Winforms\CommandBindingTests.cs">

ReactiveUI.Tests/TestUtilsTest.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Threading.Tasks;
2+
using Microsoft.Reactive.Testing;
3+
using ReactiveUI.Testing;
4+
using Xunit;
5+
6+
namespace ReactiveUI.Tests
7+
{
8+
public class TestUtilsTest
9+
{
10+
[Fact]
11+
public async Task WithAsyncScheduler()
12+
{
13+
await new TestScheduler().WithAsync(_ => Task.Run(() => { }));
14+
}
15+
}
16+
}
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)