Skip to content

Commit

Permalink
Merge pull request #7 from TheEightBot/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
michaelstonis authored Mar 6, 2024
2 parents 64f9f28 + 7102be4 commit 2782ed1
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 144 deletions.
7 changes: 0 additions & 7 deletions Stellar.Maui.PopUp/PopupPageBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@ protected override void OnDisappearing()
base.OnDisappearing();
}

protected override void OnHandlerChanging(HandlerChangingEventArgs args)
{
((MauiViewManager<TViewModel>)ViewManager).OnHandlerChanged(this, args);

base.OnHandlerChanging(args);
}

protected override void OnPropertyChanged(string propertyName = null)
{
ViewManager.PropertyChanged<PopupPageBase<TViewModel>, TViewModel>(this, propertyName);
Expand Down
72 changes: 30 additions & 42 deletions Stellar.Maui/MauiViewManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,48 @@ public class MauiViewManager<TViewModel> : ViewManager
{
private WeakReference<object?>? _reloadView;

public void OnHandlerChanged<TVisualElement>(TVisualElement visualElement, HandlerChangingEventArgs args)
where TVisualElement : VisualElement, IStellarView<TViewModel>, IStellarView
public override void PropertyChanged<TView, TViewModel>(TView view, string? propertyName = null)

Check warning on line 11 in Stellar.Maui/MauiViewManager.cs

View workflow job for this annotation

GitHub Actions / build

Type parameter 'TViewModel' has the same name as the type parameter from outer type 'MauiViewManager<TViewModel>'

Check warning on line 11 in Stellar.Maui/MauiViewManager.cs

View workflow job for this annotation

GitHub Actions / build

Type parameter 'TViewModel' has the same name as the type parameter from outer type 'MauiViewManager<TViewModel>'

Check warning on line 11 in Stellar.Maui/MauiViewManager.cs

View workflow job for this annotation

GitHub Actions / build

Type parameter 'TViewModel' has the same name as the type parameter from outer type 'MauiViewManager<TViewModel>'

Check warning on line 11 in Stellar.Maui/MauiViewManager.cs

View workflow job for this annotation

GitHub Actions / build

Type parameter 'TViewModel' has the same name as the type parameter from outer type 'MauiViewManager<TViewModel>'

Check warning on line 11 in Stellar.Maui/MauiViewManager.cs

View workflow job for this annotation

GitHub Actions / build

Type parameter 'TViewModel' has the same name as the type parameter from outer type 'MauiViewManager<TViewModel>'

Check warning on line 11 in Stellar.Maui/MauiViewManager.cs

View workflow job for this annotation

GitHub Actions / build

Type parameter 'TViewModel' has the same name as the type parameter from outer type 'MauiViewManager<TViewModel>'

Check warning on line 11 in Stellar.Maui/MauiViewManager.cs

View workflow job for this annotation

GitHub Actions / build

Type parameter 'TViewModel' has the same name as the type parameter from outer type 'MauiViewManager<TViewModel>'

Check warning on line 11 in Stellar.Maui/MauiViewManager.cs

View workflow job for this annotation

GitHub Actions / build

Type parameter 'TViewModel' has the same name as the type parameter from outer type 'MauiViewManager<TViewModel>'

Check warning on line 11 in Stellar.Maui/MauiViewManager.cs

View workflow job for this annotation

GitHub Actions / build

Type parameter 'TViewModel' has the same name as the type parameter from outer type 'MauiViewManager<TViewModel>'

Check warning on line 11 in Stellar.Maui/MauiViewManager.cs

View workflow job for this annotation

GitHub Actions / build

Type parameter 'TViewModel' has the same name as the type parameter from outer type 'MauiViewManager<TViewModel>'

Check warning on line 11 in Stellar.Maui/MauiViewManager.cs

View workflow job for this annotation

GitHub Actions / build

Type parameter 'TViewModel' has the same name as the type parameter from outer type 'MauiViewManager<TViewModel>'

Check warning on line 11 in Stellar.Maui/MauiViewManager.cs

View workflow job for this annotation

GitHub Actions / build

Type parameter 'TViewModel' has the same name as the type parameter from outer type 'MauiViewManager<TViewModel>'

Check warning on line 11 in Stellar.Maui/MauiViewManager.cs

View workflow job for this annotation

GitHub Actions / build

Type parameter 'TViewModel' has the same name as the type parameter from outer type 'MauiViewManager<TViewModel>'

Check warning on line 11 in Stellar.Maui/MauiViewManager.cs

View workflow job for this annotation

GitHub Actions / build

Type parameter 'TViewModel' has the same name as the type parameter from outer type 'MauiViewManager<TViewModel>'

Check warning on line 11 in Stellar.Maui/MauiViewManager.cs

View workflow job for this annotation

GitHub Actions / build

Type parameter 'TViewModel' has the same name as the type parameter from outer type 'MauiViewManager<TViewModel>'
{
if (args.OldHandler is not null)
{
visualElement.Loaded -= this.Handle_Loaded;
visualElement.Unloaded -= this.Handle_Unloaded;
base.PropertyChanged<TView, TViewModel>(view, propertyName);

HandleDeactivated(visualElement);
visualElement.DisposeView();
if (propertyName is null || !propertyName.Equals(nameof(VisualElement.Window)) || view is not VisualElement ve)
{
return;
}

if (args.NewHandler is not null)
if (ve.Window is not null)
{
HandleActivated(visualElement);
if (HotReloadService.HotReloadAware)
{
this._reloadView = new WeakReference<object?>(view);
HotReloadService.UpdateApplicationEvent -= this.HandleHotReload;
HotReloadService.UpdateApplicationEvent += this.HandleHotReload;
}

visualElement.Loaded -= this.Handle_Loaded;
visualElement.Loaded += this.Handle_Loaded;
if (view is not IStellarView<TViewModel> isv)
{
return;
}

visualElement.Unloaded -= this.Handle_Unloaded;
visualElement.Unloaded += this.Handle_Unloaded;
this.HandleActivated(isv);
this.OnLifecycle(isv, LifecycleEvent.Attached);
}
}

private void Handle_Loaded(object? sender, EventArgs e)
{
if (HotReloadService.HotReloadAware)
else
{
_reloadView = new WeakReference<object?>(sender);
HotReloadService.UpdateApplicationEvent -= HandleHotReload;
HotReloadService.UpdateApplicationEvent += HandleHotReload;
}
if (HotReloadService.HotReloadAware)
{
HotReloadService.UpdateApplicationEvent -= this.HandleHotReload;
}

if (sender is not IStellarView<TViewModel> isv)
{
return;
}
if (view is not IStellarView<TViewModel> isv)
{
return;
}

OnLifecycle(isv, LifecycleEvent.Attached);
}

private void Handle_Unloaded(object? sender, EventArgs e)
{
if (HotReloadService.HotReloadAware)
{
HotReloadService.UpdateApplicationEvent -= HandleHotReload;
this.OnLifecycle(isv, LifecycleEvent.Detached);
this.HandleDeactivated(isv);
isv.DisposeView();
}

if (sender is not IStellarView<TViewModel> isv)
{
return;
}

OnLifecycle(isv, LifecycleEvent.Detached);
}

private void HandleHotReload(Type[]? updatedTypes)
Expand Down
7 changes: 0 additions & 7 deletions Stellar.Maui/Pages/ContentPageBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ protected override void OnDisappearing()
base.OnDisappearing();
}

protected override void OnHandlerChanging(HandlerChangingEventArgs args)
{
((MauiViewManager<TViewModel>)ViewManager).OnHandlerChanged(this, args);

base.OnHandlerChanging(args);
}

protected override void OnPropertyChanged(string? propertyName = null)
{
ViewManager.PropertyChanged<ContentPageBase<TViewModel>, TViewModel>(this, propertyName);
Expand Down
7 changes: 0 additions & 7 deletions Stellar.Maui/Pages/FlyoutPageBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ protected override void OnDisappearing()
base.OnDisappearing();
}

protected override void OnHandlerChanging(HandlerChangingEventArgs args)
{
((MauiViewManager<TViewModel>)ViewManager).OnHandlerChanged(this, args);

base.OnHandlerChanging(args);
}

protected override void OnPropertyChanged(string? propertyName = null)
{
ViewManager.PropertyChanged<FlyoutPageBase<TViewModel>, TViewModel>(this, propertyName);
Expand Down
7 changes: 0 additions & 7 deletions Stellar.Maui/Pages/MultiPageBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ protected override void OnDisappearing()
base.OnDisappearing();
}

protected override void OnHandlerChanging(HandlerChangingEventArgs args)
{
((MauiViewManager<TViewModel>)ViewManager).OnHandlerChanged(this, args);

base.OnHandlerChanging(args);
}

protected override void OnPropertyChanged(string? propertyName = null)
{
ViewManager.PropertyChanged<MultiPageBase<TPage, TViewModel>, TViewModel>(this, propertyName);
Expand Down
7 changes: 0 additions & 7 deletions Stellar.Maui/Pages/NavigationPageBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ protected override void OnDisappearing()
base.OnDisappearing();
}

protected override void OnHandlerChanging(HandlerChangingEventArgs args)
{
((MauiViewManager<TViewModel>)ViewManager).OnHandlerChanged(this, args);

base.OnHandlerChanging(args);
}

protected override void OnPropertyChanged(string? propertyName = null)
{
ViewManager.PropertyChanged<NavigationPageBase<TViewModel>, TViewModel>(this, propertyName);
Expand Down
7 changes: 0 additions & 7 deletions Stellar.Maui/Pages/TabbedPageBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ protected override void OnDisappearing()
base.OnDisappearing();
}

protected override void OnHandlerChanging(HandlerChangingEventArgs args)
{
((MauiViewManager<TViewModel>)ViewManager).OnHandlerChanged(this, args);

base.OnHandlerChanging(args);
}

protected override void OnPropertyChanged(string? propertyName = null)
{
ViewManager.PropertyChanged<TabbedPageBase<TViewModel>, TViewModel>(this, propertyName);
Expand Down
7 changes: 0 additions & 7 deletions Stellar.Maui/ShellBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ protected override void OnDisappearing()
base.OnDisappearing();
}

protected override void OnHandlerChanging(HandlerChangingEventArgs args)
{
((MauiViewManager<TViewModel>)ViewManager).OnHandlerChanged(this, args);

base.OnHandlerChanging(args);
}

protected override void OnPropertyChanged(string? propertyName = null)
{
ViewManager.PropertyChanged<ShellBase<TViewModel>, TViewModel>(this, propertyName);
Expand Down
14 changes: 0 additions & 14 deletions Stellar.Maui/Views/ContentViewBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ public virtual void Initialize()

public abstract void Bind(CompositeDisposable disposables);

protected override void OnHandlerChanging(HandlerChangingEventArgs args)
{
((MauiViewManager<TViewModel>)ViewManager).OnHandlerChanged(this, args);

base.OnHandlerChanging(args);
}

protected override void OnPropertyChanged(string? propertyName = null)
{
ViewManager.PropertyChanged<ContentViewBase<TViewModel>, TViewModel>(this, propertyName);
Expand Down Expand Up @@ -82,13 +75,6 @@ public virtual void Initialize()

protected abstract void MapDataModelToViewModel(TViewModel viewModel, TDataModel dataModel);

protected override void OnHandlerChanging(HandlerChangingEventArgs args)
{
((MauiViewManager<TViewModel>)ViewManager).OnHandlerChanged(this, args);

base.OnHandlerChanging(args);
}

protected override void OnPropertyChanged(string? propertyName = null)
{
ViewManager.PropertyChanged<ContentViewBase<TViewModel, TDataModel>, TViewModel>(this, propertyName);
Expand Down
7 changes: 0 additions & 7 deletions Stellar.Maui/Views/FrameBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ public virtual void Initialize()

public abstract void Bind(CompositeDisposable disposables);

protected override void OnHandlerChanging(HandlerChangingEventArgs args)
{
((MauiViewManager<TViewModel>)ViewManager).OnHandlerChanged(this, args);

base.OnHandlerChanging(args);
}

protected override void OnPropertyChanged(string? propertyName = null)
{
ViewManager.PropertyChanged<FrameBase<TViewModel>, TViewModel>(this, propertyName);
Expand Down
14 changes: 0 additions & 14 deletions Stellar.Maui/Views/GridBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ public virtual void Initialize()

public abstract void Bind(CompositeDisposable disposables);

protected override void OnHandlerChanging(HandlerChangingEventArgs args)
{
((MauiViewManager<TViewModel>)ViewManager).OnHandlerChanged(this, args);

base.OnHandlerChanging(args);
}

protected override void OnPropertyChanged(string? propertyName = null)
{
ViewManager.PropertyChanged<GridBase<TViewModel>, TViewModel>(this, propertyName);
Expand Down Expand Up @@ -83,13 +76,6 @@ public virtual void Initialize()

protected abstract void MapDataModelToViewModel(TViewModel viewModel, TDataModel dataModel);

protected override void OnHandlerChanging(HandlerChangingEventArgs args)
{
((MauiViewManager<TViewModel>)ViewManager).OnHandlerChanged(this, args);

base.OnHandlerChanging(args);
}

protected override void OnPropertyChanged(string? propertyName = null)
{
ViewManager.PropertyChanged<GridBase<TViewModel, TDataModel>, TViewModel>(this, propertyName);
Expand Down
14 changes: 0 additions & 14 deletions Stellar.Maui/Views/StackLayoutBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ public virtual void Initialize()

public abstract void Bind(CompositeDisposable disposables);

protected override void OnHandlerChanging(HandlerChangingEventArgs args)
{
((MauiViewManager<TViewModel>)ViewManager).OnHandlerChanged(this, args);

base.OnHandlerChanging(args);
}

protected override void OnPropertyChanged(string? propertyName = null)
{
ViewManager.PropertyChanged<StackLayoutBase<TViewModel>, TViewModel>(this, propertyName);
Expand Down Expand Up @@ -83,13 +76,6 @@ public virtual void Initialize()

protected abstract void MapDataModelToViewModel(TViewModel viewModel, TDataModel dataModel);

protected override void OnHandlerChanging(HandlerChangingEventArgs args)
{
((MauiViewManager<TViewModel>)ViewManager).OnHandlerChanged(this, args);

base.OnHandlerChanging(args);
}

protected override void OnPropertyChanged(string? propertyName = null)
{
ViewManager.PropertyChanged<StackLayoutBase<TViewModel, TDataModel>, TViewModel>(this, propertyName);
Expand Down
5 changes: 3 additions & 2 deletions Stellar.MauiSample/UserInterface/Pages/SimpleSamplePage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,13 @@ public override void SetupUserInterface()
}
.Row(7).Column(0)
.Assign(out _picker),
/*
new ListView
{
ItemTemplate = new DataTemplate(typeof(Cells.SampleViewCell)),
VerticalOptions = LayoutOptions.Fill,
}
.Row(8).Column(0)
.Assign(out _listView),
*/
},
}
.Assign(out _mainLayout);
Expand Down Expand Up @@ -154,6 +152,9 @@ public override void Bind(CompositeDisposable disposables)
this.BindCommand(ViewModel, static vm => vm.GoValidation, static ui => ui._validation, Observables.UnitDefault)
.DisposeWith(disposables);

this.OneWayBind(ViewModel, static x => x.TestItems, static ui => ui._listView.ItemsSource)
.DisposeWith(disposables);

this.WhenAnyObservable(static x => x.ViewModel.GoValidation)
.NavigateToPage<SampleValidationPage>(this)
.DisposeWith(disposables);
Expand Down
6 changes: 5 additions & 1 deletion Stellar.MauiSample/ViewModels/SampleViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class SampleViewModel : ViewModelBase, ILifecycleEventAware

private long _parameterValue;

private Guid _id;

[Reactive]
public ReactiveCommand<Unit, Unit> GoPopup { get; private set; }

Expand Down Expand Up @@ -41,6 +43,8 @@ public long ParameterValue
public SampleViewModel(TestService testService)
{
_testService = testService;

this._id = Guid.NewGuid();
}

~SampleViewModel()
Expand Down Expand Up @@ -98,7 +102,7 @@ protected override void Bind(CompositeDisposable disposables)

public void OnLifecycleEvent(LifecycleEvent lifecycleEvent)
{
Console.WriteLine($"LifecycleEvent: {lifecycleEvent}");
Console.WriteLine($"LifecycleEvent:\t{this._id}\t{lifecycleEvent}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion Stellar/ViewManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public virtual void HandleDeactivated<TViewModel>(IStellarView<TViewModel> view)
UnregisterBindings(view);
}

public void PropertyChanged<TView, TViewModel>(TView view, string? propertyName = null)
public virtual void PropertyChanged<TView, TViewModel>(TView view, string? propertyName = null)
where TView : IViewFor<TViewModel>
where TViewModel : class
{
Expand Down

0 comments on commit 2782ed1

Please sign in to comment.