Skip to content

Commit 307af6b

Browse files
committed
Add support for Android Activity/Fragments
1 parent c580e40 commit 307af6b

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

ReactiveUI.Platforms/Android/ReactiveActivity.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
using System.Diagnostics.Contracts;
1919
using System.Runtime.CompilerServices;
2020
using Splat;
21+
using System.Reactive;
2122

2223
namespace ReactiveUI.Android
2324
{
2425
/// <summary>
2526
/// This is an Activity that is both an Activity and has ReactiveObject powers
2627
/// (i.e. you can call RaiseAndSetIfChanged)
2728
/// </summary>
28-
public class ReactiveActivity<TViewModel> : ReactiveActivity, IViewFor<TViewModel>, IReactiveNotifyPropertyChanged, IHandleObservableErrors
29+
public class ReactiveActivity<TViewModel> : ReactiveActivity, IViewFor<TViewModel>, ICanActivate
2930
where TViewModel : class, IReactiveNotifyPropertyChanged
3031
{
3132
protected ReactiveActivity() { }
@@ -235,6 +236,24 @@ public void RaisePropertyChanging([CallerMemberName] string propertyName = null)
235236
{
236237
raisePropertyChanging(propertyName);
237238
}
239+
240+
readonly Subject<Unit> activated = new Subject<Unit>();
241+
public IObservable<Unit> Activated { get { return activated; } }
242+
243+
readonly Subject<Unit> deactivated = new Subject<Unit>();
244+
public IObservable<Unit> Deactivated { get { return deactivated; } }
245+
246+
protected override void OnPause()
247+
{
248+
base.OnPause();
249+
deactivated.OnNext(Unit.Default);
250+
}
251+
252+
protected override void OnResume()
253+
{
254+
base.OnResume();
255+
activated.OnNext(Unit.Default);
256+
}
238257
}
239258
}
240259

ReactiveUI.Platforms/Android/ReactiveFragment.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
using System.Diagnostics.Contracts;
2020
using System.Runtime.CompilerServices;
2121
using Splat;
22+
using System.Reactive;
2223

2324
namespace ReactiveUI.Android
2425
{
2526
/// <summary>
2627
/// This is a Fragment that is both an Activity and has ReactiveObject powers
2728
/// (i.e. you can call RaiseAndSetIfChanged)
2829
/// </summary>
29-
public class ReactiveFragment<TViewModel> : ReactiveFragment, IViewFor<TViewModel>, IReactiveNotifyPropertyChanged, IHandleObservableErrors
30+
public class ReactiveFragment<TViewModel> : ReactiveFragment, IViewFor<TViewModel>, ICanActivate
3031
where TViewModel : class, IReactiveNotifyPropertyChanged
3132
{
3233
protected ReactiveFragment() { }
@@ -235,5 +236,23 @@ public void RaisePropertyChanging([CallerMemberName] string propertyName = null)
235236
{
236237
raisePropertyChanging(propertyName);
237238
}
239+
240+
readonly Subject<Unit> activated = new Subject<Unit>();
241+
public IObservable<Unit> Activated { get { return activated; } }
242+
243+
readonly Subject<Unit> deactivated = new Subject<Unit>();
244+
public IObservable<Unit> Deactivated { get { return deactivated; } }
245+
246+
public override void OnPause()
247+
{
248+
base.OnPause();
249+
deactivated.OnNext(Unit.Default);
250+
}
251+
252+
public override void OnResume()
253+
{
254+
base.OnResume();
255+
activated.OnNext(Unit.Default);
256+
}
238257
}
239258
}

ReactiveUI/Interfaces.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,8 @@ public interface ISupportsActivation
446446

447447
public interface ICanActivate
448448
{
449-
public IObservable<Unit> Activated { get; }
450-
public IObservable<Unit> Deactivated { get; }
449+
IObservable<Unit> Activated { get; }
450+
IObservable<Unit> Deactivated { get; }
451451
}
452452

453453
/// <summary>

0 commit comments

Comments
 (0)