From 7ef92fc932b525d43ff20f0ff92e392db072d719 Mon Sep 17 00:00:00 2001
From: Myzel394 <50424412+Myzel394@users.noreply.github.com>
Date: Wed, 24 Aug 2022 13:57:47 +0200
Subject: [PATCH] added focus change listener for android
---
android/app/src/main/AndroidManifest.xml | 1 +
.../example/share_location/MainActivity.kt | 31 +++++++++++++++++++
lib/widgets/status.dart | 19 ++++++++++++
3 files changed, 51 insertions(+)
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index c233f0a..d9442b7 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -6,6 +6,7 @@
+
with TickerProviderStateMixin {
+ bool _wasAnimatingBeforeLostFocus = false;
+
Animation? animation;
AnimationController? animationController;
@@ -60,6 +65,20 @@ class _StatusState extends State with TickerProviderStateMixin {
void initState() {
super.initState();
+ EventChannelWindowFocus.setGlobalListener((hasFocus) {
+ if (!widget.pauseOnLostFocus) {
+ return;
+ }
+
+ if (hasFocus && _wasAnimatingBeforeLostFocus) {
+ animationController?.forward();
+ } else if (!hasFocus) {
+ _wasAnimatingBeforeLostFocus =
+ animationController?.isAnimating ?? false;
+ animationController?.stop();
+ }
+ });
+
if (widget.autoStart) {
initializeAnimation();
}