-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add back support for using MainPage instead of CreateWindow #1262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
70623e4
WIP to get MainPage working
mattleibow b8a5f82
Merge branch 'release/6.0.1xx-preview5' into dev/mainpage
mattleibow c8f701d
- add additional init inside OnCreate
PureWeen 6865a3a
Merge remote-tracking branch 'origin/release/6.0.1xx-preview5' into d…
mattleibow fedec1d
Revert things and update templates
mattleibow 429f99a
Make this better
mattleibow b9ffd56
Merge remote-tracking branch 'origin/release/6.0.1xx-preview5' into d…
mattleibow 9396c7c
Merge remote-tracking branch 'origin/release/6.0.1xx-preview5' into d…
mattleibow b405801
Merge remote-tracking branch 'origin/main' into dev/mainpage
mattleibow 0041b7b
can skip that
mattleibow 09254d4
revert that
mattleibow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,152 @@ | ||
using System; | ||
using NUnit.Framework; | ||
|
||
namespace Microsoft.Maui.Controls.Core.UnitTests | ||
{ | ||
[TestFixture] | ||
public class ApplicationTests : BaseTestFixture | ||
{ | ||
[Test] | ||
public void NewApplicationHasNoWindowsNorPage() | ||
{ | ||
var app = new Application(); | ||
|
||
Assert.Null(app.MainPage); | ||
Assert.IsEmpty(app.Windows); | ||
} | ||
|
||
[Test] | ||
public void SettingMainPageSetsMainPageAndWindow() | ||
{ | ||
var app = new Application(); | ||
var page = new ContentPage(); | ||
|
||
app.MainPage = page; | ||
|
||
Assert.AreEqual(page, app.MainPage); | ||
Assert.AreEqual(1, app.Windows.Count); | ||
Assert.AreEqual(page, app.Windows[0].Page); | ||
} | ||
|
||
[Test] | ||
public void CreateWindowUsesMainPage() | ||
{ | ||
var app = new Application(); | ||
var iapp = app as IApplication; | ||
var page = new ContentPage(); | ||
|
||
app.MainPage = page; | ||
|
||
var window = iapp.CreateWindow(null); | ||
|
||
Assert.AreEqual(page, app.MainPage); | ||
Assert.IsNotEmpty(app.Windows); | ||
Assert.AreEqual(1, app.Windows.Count); | ||
Assert.AreEqual(window, app.Windows[0]); | ||
Assert.AreEqual(page, app.Windows[0].Page); | ||
} | ||
|
||
[Test] | ||
public void SettingMainPageUpdatesWindow() | ||
{ | ||
var app = new Application(); | ||
var iapp = app as IApplication; | ||
var page = new ContentPage(); | ||
|
||
app.MainPage = page; | ||
var window = iapp.CreateWindow(null); | ||
|
||
var page2 = new ContentPage(); | ||
app.MainPage = page2; | ||
|
||
Assert.AreEqual(page2, app.MainPage); | ||
Assert.IsNotEmpty(app.Windows); | ||
Assert.AreEqual(1, app.Windows.Count); | ||
Assert.AreEqual(window, app.Windows[0]); | ||
Assert.AreEqual(page2, app.Windows[0].Page); | ||
} | ||
|
||
[Test] | ||
public void NotSettingMainPageThrows() | ||
{ | ||
var app = new Application(); | ||
var iapp = app as IApplication; | ||
|
||
Assert.Throws<NotImplementedException>(() => iapp.CreateWindow(null)); | ||
} | ||
|
||
[Test] | ||
public void CanUseExistingWindow() | ||
{ | ||
var window = new Window(); | ||
|
||
var app = new StubApp { MainWindow = window }; | ||
var iapp = app as IApplication; | ||
|
||
var win = iapp.CreateWindow(null); | ||
|
||
Assert.AreEqual(window, win); | ||
Assert.Null(app.MainPage); | ||
} | ||
|
||
[Test] | ||
public void CanUseExistingWindowWithPage() | ||
{ | ||
var window = new Window { Page = new ContentPage() }; | ||
|
||
var app = new StubApp { MainWindow = window }; | ||
var iapp = app as IApplication; | ||
|
||
var win = iapp.CreateWindow(null); | ||
|
||
Assert.AreEqual(window, win); | ||
Assert.AreEqual(window.Page, app.MainPage); | ||
} | ||
|
||
[Test] | ||
public void SettingMainPageOverwritesExistingPage() | ||
{ | ||
var window = new Window { Page = new ContentPage() }; | ||
|
||
var app = new StubApp { MainWindow = window }; | ||
var iapp = app as IApplication; | ||
|
||
var win = iapp.CreateWindow(null); | ||
|
||
var page2 = new ContentPage(); | ||
app.MainPage = page2; | ||
|
||
Assert.AreEqual(window, win); | ||
Assert.AreEqual(page2, app.MainPage); | ||
Assert.AreEqual(window.Page, app.MainPage); | ||
} | ||
|
||
[Test] | ||
public void SettingWindowPageOverwritesMainPage() | ||
{ | ||
var window = new Window { Page = new ContentPage() }; | ||
|
||
var app = new StubApp { MainWindow = window }; | ||
var iapp = app as IApplication; | ||
|
||
var win = iapp.CreateWindow(null); | ||
|
||
var page2 = new ContentPage(); | ||
window.Page = page2; | ||
|
||
Assert.AreEqual(window, win); | ||
Assert.AreEqual(page2, app.MainPage); | ||
Assert.AreEqual(window.Page, app.MainPage); | ||
} | ||
|
||
class StubApp : Application | ||
{ | ||
public Window MainWindow { get; set; } | ||
|
||
protected override Window CreateWindow(IActivationState activationState) | ||
{ | ||
return MainWindow; | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or 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 |
---|---|---|
|
@@ -72,7 +72,7 @@ public class TestApp : Application | |
public TestWindow CreateWindow() => | ||
(TestWindow)(this as IApplication).CreateWindow(null); | ||
|
||
protected override IWindow CreateWindow(IActivationState activationState) | ||
protected override Window CreateWindow(IActivationState activationState) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
{ | ||
return new TestWindow(new ContentPage()); | ||
} | ||
|
This file contains hidden or 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 |
---|---|---|
|
@@ -8,6 +8,13 @@ namespace Microsoft.Maui.LifecycleEvents | |
{ | ||
public static class AndroidLifecycle | ||
{ | ||
// Events called by the Application | ||
public delegate void OnApplicationCreating(Application application); | ||
public delegate void OnApplicationCreate(Application application); | ||
public delegate void OnApplicationLowMemory(Application application); | ||
public delegate void OnApplicationTrimMemory(Application application, TrimMemory level); | ||
public delegate void OnApplicationConfigurationChanged(Application application, Configuration newConfig); | ||
Comment on lines
+11
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add some new application events. |
||
|
||
// Events called by the ActivityLifecycleCallbacks | ||
public delegate void OnCreate(Activity activity, Bundle? savedInstanceState); | ||
public delegate void OnStart(Activity activity); | ||
|
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use MainPage for single page apps.