enable bottom actions before first image is reached

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-09-01 23:55:43 +08:00
parent e88e17a4b0
commit 96d9604fe1
2 changed files with 41 additions and 16 deletions

View File

@ -1,5 +1,4 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_hbb/common/widgets/overlay.dart';
import 'package:flutter_hbb/mobile/pages/server_page.dart'; import 'package:flutter_hbb/mobile/pages/server_page.dart';
import 'package:flutter_hbb/mobile/pages/settings_page.dart'; import 'package:flutter_hbb/mobile/pages/settings_page.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
@ -26,7 +25,6 @@ class _HomePageState extends State<HomePage> {
var _selectedIndex = 0; var _selectedIndex = 0;
int get selectedIndex => _selectedIndex; int get selectedIndex => _selectedIndex;
final List<PageShape> _pages = []; final List<PageShape> _pages = [];
final _blockableOverlayState = BlockableOverlayState();
void refreshPages() { void refreshPages() {
setState(() { setState(() {
@ -38,7 +36,6 @@ class _HomePageState extends State<HomePage> {
void initState() { void initState() {
super.initState(); super.initState();
initPages(); initPages();
_blockableOverlayState.applyFfi(gFFI);
} }
void initPages() { void initPages() {

View File

@ -39,6 +39,8 @@ class _RemotePageState extends State<RemotePage> {
String _value = ''; String _value = '';
Orientation? _currentOrientation; Orientation? _currentOrientation;
final _blockableOverlayState = BlockableOverlayState();
final keyboardVisibilityController = KeyboardVisibilityController(); final keyboardVisibilityController = KeyboardVisibilityController();
late final StreamSubscription<bool> keyboardSubscription; late final StreamSubscription<bool> keyboardSubscription;
final FocusNode _mobileFocusNode = FocusNode(); final FocusNode _mobileFocusNode = FocusNode();
@ -67,6 +69,8 @@ class _RemotePageState extends State<RemotePage> {
initSharedStates(widget.id); initSharedStates(widget.id);
gFFI.chatModel gFFI.chatModel
.changeCurrentKey(MessageKey(widget.id, ChatModel.clientModeID)); .changeCurrentKey(MessageKey(widget.id, ChatModel.clientModeID));
_blockableOverlayState.applyFfi(gFFI);
} }
@override @override
@ -88,6 +92,15 @@ class _RemotePageState extends State<RemotePage> {
removeSharedStates(widget.id); removeSharedStates(widget.id);
} }
Widget emptyOverlay() => BlockableOverlay(
/// the Overlay key will be set with _blockableOverlayState in BlockableOverlay
/// see override build() in [BlockableOverlay]
state: _blockableOverlayState,
underlying: Container(
color: Colors.transparent,
),
);
void onSoftKeyboardChanged(bool visible) { void onSoftKeyboardChanged(bool visible) {
if (!visible) { if (!visible) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []); SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
@ -198,13 +211,19 @@ class _RemotePageState extends State<RemotePage> {
}); });
} }
bool get keyboard => gFFI.ffiModel.permissions['keyboard'] != false;
Widget _bottomWidget() => _showGestureHelp
? getGestureHelp()
: (_showBar && gFFI.ffiModel.pi.displays.isNotEmpty
? getBottomAppBar(keyboard)
: Offstage());
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final pi = Provider.of<FfiModel>(context).pi;
final keyboardIsVisible = final keyboardIsVisible =
keyboardVisibilityController.isVisible && _showEdit; keyboardVisibilityController.isVisible && _showEdit;
final showActionButton = !_showBar || keyboardIsVisible || _showGestureHelp; final showActionButton = !_showBar || keyboardIsVisible || _showGestureHelp;
final keyboard = gFFI.ffiModel.permissions['keyboard'] != false;
return WillPopScope( return WillPopScope(
onWillPop: () async { onWillPop: () async {
@ -241,11 +260,17 @@ class _RemotePageState extends State<RemotePage> {
} }
}); });
}), }),
bottomNavigationBar: _showGestureHelp bottomNavigationBar: Obx(() => Stack(
? getGestureHelp() alignment: Alignment.bottomCenter,
: (_showBar && pi.displays.isNotEmpty children: [
? getBottomAppBar(keyboard) gFFI.ffiModel.pi.isSet.isTrue &&
: null), gFFI.ffiModel.waitForFirstImage.isTrue
? emptyOverlay()
: Offstage(),
_bottomWidget(),
gFFI.ffiModel.pi.isSet.isFalse ? emptyOverlay() : Offstage(),
],
)),
body: Overlay( body: Overlay(
initialEntries: [ initialEntries: [
OverlayEntry(builder: (context) { OverlayEntry(builder: (context) {
@ -368,12 +393,15 @@ class _RemotePageState extends State<RemotePage> {
}, },
), ),
]), ]),
IconButton( Obx(() => IconButton(
color: Colors.white, color: Colors.white,
icon: Icon(Icons.expand_more), icon: Icon(Icons.expand_more),
onPressed: () { onPressed: gFFI.ffiModel.waitForFirstImage.isTrue
? null
: () {
setState(() => _showBar = !_showBar); setState(() => _showBar = !_showBar);
}), },
)),
], ],
), ),
); );