Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Prism
提交
b2bf48eb
P
Prism
项目概览
jobily
/
Prism
9 个月 前同步成功
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Prism
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
b2bf48eb
编写于
5月 25, 2023
作者:
D
Dan Siegel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: android back button
上级
734ff635
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
102 addition
and
18 deletion
+102
-18
e2e/Maui/PrismMauiDemo.sln
e2e/Maui/PrismMauiDemo.sln
+2
-1
src/Maui/Prism.Maui/Common/MvvmHelpers.cs
src/Maui/Prism.Maui/Common/MvvmHelpers.cs
+31
-2
src/Maui/Prism.Maui/Controls/PrismNavigationPage.cs
src/Maui/Prism.Maui/Controls/PrismNavigationPage.cs
+4
-1
src/Maui/Prism.Maui/Navigation/PrismWindow.cs
src/Maui/Prism.Maui/Navigation/PrismWindow.cs
+57
-1
src/Maui/Prism.Maui/PrismAppBuilder.cs
src/Maui/Prism.Maui/PrismAppBuilder.cs
+8
-13
未找到文件。
e2e/Maui/PrismMauiDemo.sln
浏览文件 @
b2bf48eb
...
...
@@ -29,7 +29,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prism.Maui.Tests", "..\..\t
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prism.Core.Tests", "..\..\tests\Prism.Core.Tests\Prism.Core.Tests.csproj", "{E0F13AA9-8083-47CA-B10D-93C5285D1505}"
EndProject
Project("{
FAE04EC0-301F-11D3-BF4B-00C04F79EFBC
}") = "Prism.Events", "..\..\src\Prism.Events\Prism.Events.csproj", "{5623CB62-59C1-49BC-BB16-4C5D63D82DAC}"
Project("{
9A19103F-16F7-4668-BE54-9A1E7A4F7556
}") = "Prism.Events", "..\..\src\Prism.Events\Prism.Events.csproj", "{5623CB62-59C1-49BC-BB16-4C5D63D82DAC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
...
...
@@ -95,6 +95,7 @@ Global
{EE6F0C99-61D1-4E2E-8185-FBA0D246D5C7} = {E91F80AA-3D61-4C28-B876-3EDFB5921E7D}
{F3D2DFDB-95FB-4CBB-A624-35EB6550854D} = {E91F80AA-3D61-4C28-B876-3EDFB5921E7D}
{E0F13AA9-8083-47CA-B10D-93C5285D1505} = {E91F80AA-3D61-4C28-B876-3EDFB5921E7D}
{5623CB62-59C1-49BC-BB16-4C5D63D82DAC} = {8202B92A-A573-4365-8A15-E246504A7CBD}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {50B0D1F3-D832-4C6C-858E-24F5F3B33632}
...
...
src/Maui/Prism.Maui/Common/MvvmHelpers.cs
浏览文件 @
b2bf48eb
...
...
@@ -269,13 +269,42 @@ public static class MvvmHelpers
if
(
lastModal
!=
null
)
page
=
lastModal
;
return
GetOnNavigatedToTargetFromChild
(
page
);
return
EvaluateCurrentPage
(
page
);
};
private
static
Page
EvaluateCurrentPage
(
Page
target
)
{
Page
child
=
null
;
if
(
target
is
FlyoutPage
flyout
)
child
=
flyout
.
Detail
;
else
if
(
target
is
TabbedPage
tabbed
)
child
=
tabbed
.
CurrentPage
;
else
if
(
target
is
NavigationPage
np
)
child
=
np
.
Navigation
.
NavigationStack
.
Last
();
if
(
child
!=
null
)
target
=
GetOnNavigatedToTargetFromChild
(
child
);
if
(
target
is
Page
page
)
return
page
.
Parent
switch
{
TabbedPage
tab
when
tab
.
CurrentPage
!=
target
=>
EvaluateCurrentPage
(
tab
.
CurrentPage
),
NavigationPage
nav
when
nav
.
CurrentPage
!=
target
=>
EvaluateCurrentPage
(
nav
.
CurrentPage
),
_
=>
target
};
return
null
;
}
public
static
async
Task
HandleNavigationPageGoBack
(
NavigationPage
navigationPage
)
{
var
navigationService
=
Navigation
.
Xaml
.
Navigation
.
GetNavigationService
(
navigationPage
.
CurrentPage
);
await
navigationService
.
GoBackAsync
();
var
result
=
await
navigationService
.
GoBackAsync
();
if
(
result
.
Exception
is
NavigationException
navEx
&&
navEx
.
Message
==
NavigationException
.
CannotPopApplicationMainPage
)
{
Application
.
Current
.
Quit
();
}
}
public
static
void
HandleSystemGoBack
(
IView
previousPage
,
IView
currentPage
)
...
...
src/Maui/Prism.Maui/Controls/PrismNavigationPage.cs
浏览文件 @
b2bf48eb
...
...
@@ -15,8 +15,11 @@ public class PrismNavigationPage : NavigationPage
BackButtonPressed
+=
HandleBackButtonPressed
;
}
/// <inheritdoc/>
public
event
EventHandler
BackButtonPressed
;
/// <inheritdoc/>
protected
override
bool
OnBackButtonPressed
()
{
BackButtonPressed
.
Invoke
(
this
,
EventArgs
.
Empty
);
...
...
@@ -27,4 +30,4 @@ public class PrismNavigationPage : NavigationPage
{
await
MvvmHelpers
.
HandleNavigationPageGoBack
(
this
);
}
}
\ No newline at end of file
}
src/Maui/Prism.Maui/Navigation/PrismWindow.cs
浏览文件 @
b2bf48eb
using
Prism.AppModel
;
using
System.ComponentModel
;
using
Prism.AppModel
;
using
Prism.Common
;
using
Prism.Ioc
;
using
Prism.Navigation.Xaml
;
using
Prism.Services
;
using
Prism.Xaml
;
using
TabbedPage
=
Microsoft
.
Maui
.
Controls
.
TabbedPage
;
namespace
Prism.Navigation
;
...
...
@@ -19,6 +25,56 @@ internal class PrismWindow : Window
internal
Page
CurrentPage
=>
Page
is
null
?
null
:
MvvmHelpers
.
GetCurrentPage
(
Page
);
internal
bool
IsRootPage
=>
Page
switch
{
TabbedPage
tabbed
=>
tabbed
.
CurrentPage
,
NavigationPage
nav
=>
nav
.
RootPage
,
_
=>
Page
}
==
CurrentPage
;
[
EditorBrowsable
(
EditorBrowsableState
.
Never
)]
public
void
OnSystemBack
()
{
var
currentPage
=
CurrentPage
;
if
(
currentPage
?.
Parent
is
NavigationPage
navPage
)
{
// The NavigationPage has already taken care of the GoBack
return
;
}
var
container
=
currentPage
.
GetContainerProvider
();
if
(
IsRoot
(
currentPage
))
{
var
app
=
container
.
Resolve
<
IApplication
>()
as
Application
;
app
.
Quit
();
return
;
}
else
if
(
currentPage
is
IDialogContainer
dialogContainer
)
{
if
(
dialogContainer
.
Dismiss
.
CanExecute
(
null
))
dialogContainer
.
Dismiss
.
Execute
(
null
);
}
else
{
var
navigation
=
container
.
Resolve
<
INavigationService
>();
navigation
.
GoBackAsync
();
}
}
private
bool
IsRoot
(
Page
page
)
{
if
(
page
==
Page
)
return
true
;
return
page
.
Parent
switch
{
FlyoutPage
flyout
=>
IsRoot
(
flyout
),
TabbedPage
tabbed
=>
IsRoot
(
tabbed
),
NavigationPage
navigation
=>
IsRoot
(
navigation
),
_
=>
false
};
}
private
async
void
PrismWindow_ModalPopping
(
object
sender
,
ModalPoppingEventArgs
e
)
{
if
(
PageNavigationService
.
NavigationSource
==
PageNavigationSource
.
Device
)
...
...
src/Maui/Prism.Maui/PrismAppBuilder.cs
浏览文件 @
b2bf48eb
...
...
@@ -45,28 +45,23 @@ public sealed class PrismAppBuilder
{
var
root
=
ContainerLocator
.
Container
;
if
(
root
is
null
)
return
tru
e
;
return
fals
e
;
var
app
=
root
.
Resolve
<
IApplication
>();
var
windows
=
app
.
Windows
.
OfType
<
PrismWindow
>();
if
(!
windows
.
Any
(
x
=>
x
.
IsActive
))
return
tru
e
;
return
fals
e
;
var
window
=
windows
.
First
(
x
=>
x
.
IsActive
);
var
currentPage
=
window
.
CurrentPage
;
var
container
=
currentPage
.
GetContainerProvider
();
if
(
currentPage
is
IDialogContainer
dialogContainer
)
if
(
window
.
IsRootPage
&&
app
is
Application
application
)
{
if
(
dialogContainer
.
Dismiss
.
CanExecute
(
null
))
dialogContainer
.
Dismiss
.
Execute
(
null
);
}
else
{
var
navigation
=
container
.
Resolve
<
INavigationService
>();
navigation
.
GoBackAsync
();
application
.
Quit
();
return
false
;
}
return
false
;
window
.
OnSystemBack
();
return
true
;
});
});
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录