#258 fixed wrong window metrics on startup in some cases

This commit is contained in:
Thibault Deckers 2022-05-27 12:15:09 +09:00
parent 74d11aa131
commit 431b0e7b13
5 changed files with 32 additions and 34 deletions

View file

@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
## <a id="unreleased"></a>[Unreleased]
### Fixed
- wrong window metrics on startup in some cases
## <a id="v1.6.7"></a>[v1.6.7] - 2022-05-25
### Added

View file

@ -5,9 +5,7 @@ import android.app.SearchManager
import android.content.ClipData
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Parcelable
import android.os.*
import android.util.Log
import androidx.annotation.RequiresApi
import androidx.core.content.pm.ShortcutInfoCompat
@ -125,6 +123,15 @@ class MainActivity : FlutterActivity() {
Log.i(LOG_TAG, "onStart")
super.onStart()
analysisHandler.attachToActivity()
// as of Flutter v3.0.1, the window `viewInsets` and `viewPadding`
// are incorrect on startup in some environments (e.g. API 29 emulator),
// so we manually request to apply the insets to update the window metrics
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
Handler(Looper.getMainLooper()).postDelayed({
window.decorView.requestApplyInsets()
}, 10)
}
}
override fun onStop() {

View file

@ -55,6 +55,16 @@ class AvesApp extends StatefulWidget {
@override
State<AvesApp> createState() => _AvesAppState();
static void showSystemUI() {
if (device.supportEdgeToEdgeUIMode) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
} else {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: SystemUiOverlay.values);
}
}
static void hideSystemUI() => SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
}
class _AvesAppState extends State<AvesApp> with WidgetsBindingObserver {

View file

@ -2,7 +2,6 @@ import 'dart:math';
import 'package:aves/app_mode.dart';
import 'package:aves/model/actions/move_type.dart';
import 'package:aves/model/device.dart';
import 'package:aves/model/entry.dart';
import 'package:aves/model/filters/filters.dart';
import 'package:aves/model/filters/trash.dart';
@ -13,6 +12,7 @@ import 'package:aves/model/source/collection_lens.dart';
import 'package:aves/services/common/services.dart';
import 'package:aves/theme/durations.dart';
import 'package:aves/utils/change_notifier.dart';
import 'package:aves/widgets/aves_app.dart';
import 'package:aves/widgets/collection/collection_page.dart';
import 'package:aves/widgets/common/action_mixins/feedback.dart';
import 'package:aves/widgets/common/basic/insets.dart';
@ -584,22 +584,10 @@ class _EntryViewerStackState extends State<EntryViewerStack> with FeedbackMixin,
windowService.keepScreenOn(false);
}
_showSystemUI();
AvesApp.showSystemUI();
windowService.requestOrientation();
}
// system UI
static void _showSystemUI() {
if (device.supportEdgeToEdgeUIMode) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
} else {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: SystemUiOverlay.values);
}
}
static void _hideSystemUI() => SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
// overlay
Future<void> _initOverlay() async {
@ -611,7 +599,7 @@ class _EntryViewerStackState extends State<EntryViewerStack> with FeedbackMixin,
Future<void> _onOverlayVisibleChange({bool animate = true}) async {
if (_overlayVisible.value) {
_showSystemUI();
AvesApp.showSystemUI();
if (animate) {
await _overlayAnimationController.forward();
} else {
@ -623,7 +611,7 @@ class _EntryViewerStackState extends State<EntryViewerStack> with FeedbackMixin,
_frozenViewInsets = mediaQuery.viewInsets;
_frozenViewPadding = mediaQuery.viewPadding;
});
_hideSystemUI();
AvesApp.hideSystemUI();
if (animate) {
await _overlayAnimationController.reverse();
} else {

View file

@ -1,10 +1,10 @@
import 'dart:math';
import 'package:aves/model/device.dart';
import 'package:aves/model/entry.dart';
import 'package:aves/model/entry_images.dart';
import 'package:aves/model/panorama.dart';
import 'package:aves/theme/icons.dart';
import 'package:aves/widgets/aves_app.dart';
import 'package:aves/widgets/common/basic/insets.dart';
import 'package:aves/widgets/common/extensions/build_context.dart';
import 'package:aves/widgets/common/extensions/media_query.dart';
@ -13,7 +13,6 @@ import 'package:aves/widgets/viewer/overlay/common.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
import 'package:latlong2/latlong.dart';
import 'package:panorama/panorama.dart';
import 'package:provider/provider.dart';
@ -164,21 +163,11 @@ class _PanoramaPageState extends State<PanoramaPage> {
}
void _onLeave() {
_showSystemUI();
AvesApp.showSystemUI();
}
// system UI
static void _showSystemUI() {
if (device.supportEdgeToEdgeUIMode) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
} else {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: SystemUiOverlay.values);
}
}
static void _hideSystemUI() => SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
// overlay
Future<void> _initOverlay() async {
@ -190,9 +179,9 @@ class _PanoramaPageState extends State<PanoramaPage> {
Future<void> _onOverlayVisibleChange() async {
if (_overlayVisible.value) {
_showSystemUI();
AvesApp.showSystemUI();
} else {
_hideSystemUI();
AvesApp.hideSystemUI();
}
}
}