Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add attribute to show page on iOS (#3339)
* Add attribute to show page on iOS * Fixed some small issues in iOS * Adjusted the implementation for TvOs * Added all the views and viewmodels for the ios sample * Updated the page views * Added all the views to the storyboard, added the right viewmodels and updated the presenters * Updated the MvxPageViewController, so we now hold a list of pages in there so we can show them correctly
- Loading branch information
1 parent
5cc690c
commit 8382e53
Showing
28 changed files
with
959 additions
and
266 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
MvvmCross/Platforms/Ios/Presenters/Attributes/MvxPagePresentationAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MS-PL license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using MvvmCross.Presenters.Attributes; | ||
|
||
namespace MvvmCross.Platforms.Ios.Presenters.Attributes | ||
{ | ||
public class MvxPagePresentationAttribute : MvxBasePresentationAttribute | ||
{ | ||
public static bool DefaultWrapInNavigationController = false; | ||
public bool WrapInNavigationController { get; set; } = DefaultWrapInNavigationController; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MS-PL license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using MvvmCross.Platforms.Ios.Presenters.Attributes; | ||
using MvvmCross.ViewModels; | ||
using UIKit; | ||
|
||
namespace MvvmCross.Platforms.Ios.Views | ||
{ | ||
public interface IMvxPageViewController | ||
{ | ||
void AddPage(UIViewController viewController, MvxPagePresentationAttribute attribute); | ||
|
||
bool RemovePage (IMvxViewModel viewModel); | ||
} | ||
} |
168 changes: 168 additions & 0 deletions
168
MvvmCross/Platforms/Ios/Views/MvxBasePageViewController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MS-PL license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Foundation; | ||
using MvvmCross.Logging; | ||
using MvvmCross.Binding.BindingContext; | ||
using MvvmCross.Platforms.Ios.Views.Base; | ||
using MvvmCross.ViewModels; | ||
using UIKit; | ||
|
||
namespace MvvmCross.Platforms.Ios.Views | ||
{ | ||
public class MvxBasePageViewController : MvxEventSourcePageViewController, IMvxIosView | ||
{ | ||
public MvxBasePageViewController(UIPageViewControllerTransitionStyle style = UIPageViewControllerTransitionStyle.Scroll, UIPageViewControllerNavigationOrientation navigationOrientation = UIPageViewControllerNavigationOrientation.Horizontal, UIPageViewControllerSpineLocation spineLocation = UIPageViewControllerSpineLocation.None) : base(style, navigationOrientation, spineLocation) | ||
{ | ||
this.AdaptForBinding(); | ||
} | ||
|
||
public MvxBasePageViewController(UIPageViewControllerTransitionStyle style, UIPageViewControllerNavigationOrientation navigationOrientation, UIPageViewControllerSpineLocation spineLocation, float interPageSpacing) : base(style, navigationOrientation, spineLocation, interPageSpacing) | ||
{ | ||
this.AdaptForBinding(); | ||
} | ||
|
||
public MvxBasePageViewController(UIPageViewControllerTransitionStyle style, UIPageViewControllerNavigationOrientation navigationOrientation) : base(style, navigationOrientation) | ||
{ | ||
this.AdaptForBinding(); | ||
} | ||
|
||
public MvxBasePageViewController(NSCoder coder) : base(coder) | ||
{ | ||
this.AdaptForBinding(); | ||
} | ||
|
||
protected MvxBasePageViewController(NSObjectFlag t) : base(t) | ||
{ | ||
this.AdaptForBinding(); | ||
} | ||
|
||
protected internal MvxBasePageViewController(IntPtr handle) : base(handle) | ||
{ | ||
this.AdaptForBinding(); | ||
} | ||
|
||
public MvxBasePageViewController(string nibName, NSBundle bundle) : base(nibName, bundle) | ||
{ | ||
this.AdaptForBinding(); | ||
} | ||
|
||
public MvxBasePageViewController(UIPageViewControllerTransitionStyle style, UIPageViewControllerNavigationOrientation navigationOrientation, NSDictionary options) : base(style, navigationOrientation, options) | ||
{ | ||
this.AdaptForBinding(); | ||
} | ||
public object DataContext | ||
{ | ||
get | ||
{ | ||
// special code needed in PageViewController because View is initialized during construction | ||
return BindingContext?.DataContext; | ||
} | ||
set | ||
{ | ||
BindingContext.DataContext = value; | ||
} | ||
} | ||
|
||
public IMvxViewModel ViewModel | ||
{ | ||
get { return DataContext as IMvxViewModel; } | ||
set { DataContext = value; } | ||
} | ||
|
||
public MvxViewModelRequest Request { get; set; } | ||
|
||
public IMvxBindingContext BindingContext { get; set; } | ||
|
||
public override void ViewDidLoad() | ||
{ | ||
base.ViewDidLoad(); | ||
ViewModel?.ViewCreated(); | ||
} | ||
|
||
public override void ViewWillAppear(bool animated) | ||
{ | ||
base.ViewWillAppear(animated); | ||
ViewModel?.ViewAppearing(); | ||
} | ||
|
||
public override void ViewDidAppear(bool animated) | ||
{ | ||
base.ViewDidAppear(animated); | ||
ViewModel?.ViewAppeared(); | ||
} | ||
|
||
public override void ViewWillDisappear(bool animated) | ||
{ | ||
base.ViewWillDisappear(animated); | ||
ViewModel?.ViewDisappearing(); | ||
} | ||
|
||
public override void ViewDidDisappear(bool animated) | ||
{ | ||
base.ViewDidDisappear(animated); | ||
ViewModel?.ViewDisappeared(); | ||
} | ||
|
||
public override void DidMoveToParentViewController(UIViewController parent) | ||
{ | ||
base.DidMoveToParentViewController(parent); | ||
if (parent == null) | ||
ViewModel?.ViewDestroy(); | ||
} | ||
|
||
public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender) | ||
{ | ||
base.PrepareForSegue(segue, sender); | ||
this.ViewModelRequestForSegue(segue, sender); | ||
} | ||
} | ||
|
||
public class MvxBasePageViewController<TViewModel> : MvxPageViewController, IMvxIosView<TViewModel> where TViewModel : class, IMvxViewModel | ||
{ | ||
public MvxBasePageViewController() | ||
{ | ||
} | ||
|
||
public MvxBasePageViewController(NSCoder coder) : base(coder) | ||
{ | ||
} | ||
|
||
public MvxBasePageViewController(UIPageViewControllerTransitionStyle style, UIPageViewControllerNavigationOrientation navigationOrientation) : base(style, navigationOrientation) | ||
{ | ||
} | ||
|
||
public MvxBasePageViewController(string nibName, NSBundle bundle) : base(nibName, bundle) | ||
{ | ||
} | ||
|
||
public MvxBasePageViewController(UIPageViewControllerTransitionStyle style, UIPageViewControllerNavigationOrientation navigationOrientation, UIPageViewControllerSpineLocation spineLocation) : base(style, navigationOrientation, spineLocation) | ||
{ | ||
} | ||
|
||
public MvxBasePageViewController(UIPageViewControllerTransitionStyle style, UIPageViewControllerNavigationOrientation navigationOrientation, NSDictionary options) : base(style, navigationOrientation, options) | ||
{ | ||
} | ||
|
||
public MvxBasePageViewController(UIPageViewControllerTransitionStyle style, UIPageViewControllerNavigationOrientation navigationOrientation, UIPageViewControllerSpineLocation spineLocation, float interPageSpacing) : base(style, navigationOrientation, spineLocation, interPageSpacing) | ||
{ | ||
} | ||
|
||
protected MvxBasePageViewController(NSObjectFlag t) : base(t) | ||
{ | ||
} | ||
|
||
protected internal MvxBasePageViewController(IntPtr handle) : base(handle) | ||
{ | ||
} | ||
|
||
public new TViewModel ViewModel | ||
{ | ||
get { return (TViewModel)base.ViewModel; } | ||
set { base.ViewModel = value; } | ||
} | ||
} | ||
} |
Oops, something went wrong.