feat:调整了启动/首屏阶段的 WebView 和壳层 fallback 展示:
WebView 背景从白色改成透明。 WebView 不再无条件渲染,只有已发起初始加载或首屏已展示后才渲染。 首屏未 ready 时,用 shell cover/fallback 盖住 WebView,避免白屏或 WebView 空白层提前露出。 顶部安全区背景色跟随 shell 背景,减少状态栏区域闪白
This commit is contained in:
@@ -164,7 +164,7 @@ class _H5ShellPageState extends State<H5ShellPage> with WidgetsBindingObserver {
|
|||||||
onMessageReceived: (message) =>
|
onMessageReceived: (message) =>
|
||||||
_handleFlutterShellMessage(generation, message),
|
_handleFlutterShellMessage(generation, message),
|
||||||
)
|
)
|
||||||
..setBackgroundColor(Colors.white)
|
..setBackgroundColor(Colors.transparent)
|
||||||
..setNavigationDelegate(
|
..setNavigationDelegate(
|
||||||
NavigationDelegate(
|
NavigationDelegate(
|
||||||
onProgress: (progress) {
|
onProgress: (progress) {
|
||||||
@@ -1009,6 +1009,12 @@ class _H5ShellPageState extends State<H5ShellPage> with WidgetsBindingObserver {
|
|||||||
final shouldPaintShellFallback =
|
final shouldPaintShellFallback =
|
||||||
(_isPreparingInitialLine || currentSlot.isAwaitingFirstScreen) &&
|
(_isPreparingInitialLine || currentSlot.isAwaitingFirstScreen) &&
|
||||||
currentSlot.loadError == null;
|
currentSlot.loadError == null;
|
||||||
|
final shouldPaintShellCover =
|
||||||
|
currentSlot.showShellCover && !currentSlot.hasPresentedFirstScreen;
|
||||||
|
final shouldPaintWebView = currentSlot.hasLoadedInitialRequest ||
|
||||||
|
currentSlot.hasPresentedFirstScreen;
|
||||||
|
final shellBackgroundColor =
|
||||||
|
shouldPaintShellFallback ? _shellBackground : Colors.white;
|
||||||
|
|
||||||
return PopScope(
|
return PopScope(
|
||||||
canPop: false,
|
canPop: false,
|
||||||
@@ -1018,20 +1024,20 @@ class _H5ShellPageState extends State<H5ShellPage> with WidgetsBindingObserver {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: shellBackgroundColor,
|
||||||
body: Stack(
|
body: Stack(
|
||||||
children: [
|
children: [
|
||||||
SafeArea(
|
SafeArea(
|
||||||
bottom: false,
|
bottom: false,
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
if (shouldPaintShellFallback)
|
if (shouldPaintShellFallback && !shouldPaintShellCover)
|
||||||
Positioned.fill(
|
Positioned.fill(
|
||||||
child: _ShellFallback(progress: currentSlot.progress),
|
child: _ShellFallback(progress: currentSlot.progress),
|
||||||
),
|
),
|
||||||
Positioned.fill(child: _buildWebViewWidget()),
|
if (shouldPaintWebView)
|
||||||
if (currentSlot.showShellCover &&
|
Positioned.fill(child: _buildWebViewWidget()),
|
||||||
!currentSlot.hasPresentedFirstScreen)
|
if (shouldPaintShellCover)
|
||||||
Positioned.fill(
|
Positioned.fill(
|
||||||
child: IgnorePointer(
|
child: IgnorePointer(
|
||||||
child: _ShellFallback(progress: currentSlot.progress),
|
child: _ShellFallback(progress: currentSlot.progress),
|
||||||
@@ -1060,8 +1066,7 @@ class _H5ShellPageState extends State<H5ShellPage> with WidgetsBindingObserver {
|
|||||||
right: 0,
|
right: 0,
|
||||||
height: topInset,
|
height: topInset,
|
||||||
child: ColoredBox(
|
child: ColoredBox(
|
||||||
color:
|
color: shellBackgroundColor,
|
||||||
shouldPaintShellFallback ? _shellBackground : Colors.white,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user