@@ -13,7 +13,7 @@ namespace RxUI.Plugins.Popup
13
13
/// Base Popup page for that implements <see cref="IViewFor"/>.
14
14
/// </summary>
15
15
/// <typeparam name="TViewModel">The view model type.</typeparam>
16
- public abstract class ReactivePopupPage < TViewModel > : PopupPage , IViewFor < TViewModel >
16
+ public abstract class ReactivePopupPage < TViewModel > : ReactivePopupPage , IViewFor < TViewModel >
17
17
where TViewModel : class
18
18
{
19
19
/// <summary>
@@ -31,29 +31,6 @@ public abstract class ReactivePopupPage<TViewModel> : PopupPage, IViewFor<TViewM
31
31
( BindableProperty . CoerceValueDelegate ) null ,
32
32
( BindableProperty . CreateDefaultValueDelegate ) null ) ;
33
33
34
- /// <summary>
35
- /// Initializes a new instance of the <see cref="ReactivePopupPage{TViewModel}"/> class.
36
- /// </summary>
37
- protected ReactivePopupPage ( )
38
- {
39
- BackgroundClick =
40
- Observable . FromEvent < EventHandler , Unit > (
41
- handler =>
42
- {
43
- void EventHandler ( object sender , EventArgs args ) => handler ( Unit . Default ) ;
44
- return EventHandler ;
45
- } ,
46
- x => BackgroundClicked += x ,
47
- x => BackgroundClicked -= x )
48
- . Select ( _ => Unit . Default ) ;
49
- }
50
-
51
- /// <summary>
52
- /// Gets or sets the background click observable signal.
53
- /// </summary>
54
- /// <value>The background click.</value>
55
- public IObservable < Unit > BackgroundClick { get ; protected set ; }
56
-
57
34
/// <summary>
58
35
/// Gets or sets the ViewModel corresponding to this specific View.
59
36
/// This should be a BindableProperty if you're using XAML.
@@ -70,7 +47,7 @@ object IViewFor.ViewModel
70
47
public TViewModel ViewModel
71
48
{
72
49
get => ( TViewModel ) GetValue ( ViewModelProperty ) ;
73
- set => SetValue ( ViewModelProperty , ( object ) value ) ;
50
+ set => SetValue ( ViewModelProperty , value ) ;
74
51
}
75
52
76
53
/// <summary>
@@ -90,4 +67,74 @@ private static void OnViewModelChanged(BindableObject bindableObject, object old
90
67
bindableObject . BindingContext = newValue ;
91
68
}
92
69
}
70
+
71
+ /// <summary>
72
+ /// Base Popup page for that implements <see cref="IViewFor"/>.
73
+ /// </summary>
74
+ public abstract class ReactivePopupPage : PopupPage , IViewFor
75
+ {
76
+ /// <summary>
77
+ /// The view model property.
78
+ /// </summary>
79
+ public static readonly BindableProperty ViewModelProperty = BindableProperty . Create (
80
+ nameof ( ViewModel ) ,
81
+ typeof ( object ) ,
82
+ typeof ( IViewFor < object > ) ,
83
+ ( object ) null ,
84
+ BindingMode . OneWay ,
85
+ ( BindableProperty . ValidateValueDelegate ) null ,
86
+ new BindableProperty . BindingPropertyChangedDelegate ( OnViewModelChanged ) ,
87
+ ( BindableProperty . BindingPropertyChangingDelegate ) null ,
88
+ ( BindableProperty . CoerceValueDelegate ) null ,
89
+ ( BindableProperty . CreateDefaultValueDelegate ) null ) ;
90
+
91
+ /// <summary>
92
+ /// Gets or sets the background click observable signal.
93
+ /// </summary>
94
+ /// <value>The background click.</value>
95
+ public IObservable < Unit > BackgroundClick { get ; protected set ; }
96
+
97
+ /// <summary>
98
+ /// Gets or sets the ViewModel to display.
99
+ /// </summary>
100
+ public object ViewModel
101
+ {
102
+ get => GetValue ( ViewModelProperty ) ;
103
+ set => SetValue ( ViewModelProperty , value ) ;
104
+ }
105
+
106
+ /// <summary>
107
+ /// Gets the control binding disposable.
108
+ /// </summary>
109
+ protected CompositeDisposable ControlBindings { get ; } = new CompositeDisposable ( ) ;
110
+
111
+ /// <summary>
112
+ /// Initializes a new instance of the <see cref="ReactivePopupPage{TViewModel}"/> class.
113
+ /// </summary>
114
+ protected ReactivePopupPage ( )
115
+ {
116
+ BackgroundClick =
117
+ Observable . FromEvent < EventHandler , Unit > (
118
+ handler =>
119
+ {
120
+ void EventHandler ( object sender , EventArgs args ) => handler ( Unit . Default ) ;
121
+ return EventHandler ;
122
+ } ,
123
+ x => BackgroundClicked += x ,
124
+ x => BackgroundClicked -= x )
125
+ . Select ( _ => Unit . Default ) ;
126
+ }
127
+
128
+ /// <inheritdoc/>
129
+ protected override void OnBindingContextChanged ( )
130
+ {
131
+ base . OnBindingContextChanged ( ) ;
132
+ ViewModel = BindingContext ;
133
+ }
134
+
135
+ private static void OnViewModelChanged ( BindableObject bindableObject , object oldValue , object newValue )
136
+ {
137
+ bindableObject . BindingContext = newValue ;
138
+ }
139
+ }
93
140
}
0 commit comments