screensaver: fixed autopilot when device orientation changes
This commit is contained in:
parent
bf88e2d816
commit
36d92aaf38
2 changed files with 23 additions and 10 deletions
|
@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
|||
|
||||
## <a id="unreleased"></a>[Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- screensaver stopping when device orientation changes
|
||||
|
||||
## <a id="v1.6.12"></a>[v1.6.12] - 2022-08-27
|
||||
|
||||
### Added
|
||||
|
|
|
@ -29,7 +29,7 @@ class ScreenSaverPage extends StatefulWidget {
|
|||
State<ScreenSaverPage> createState() => _ScreenSaverPageState();
|
||||
}
|
||||
|
||||
class _ScreenSaverPageState extends State<ScreenSaverPage> {
|
||||
class _ScreenSaverPageState extends State<ScreenSaverPage> with WidgetsBindingObserver {
|
||||
late final ViewerController _viewerController;
|
||||
CollectionLens? _slideshowCollection;
|
||||
|
||||
|
@ -47,24 +47,24 @@ class _ScreenSaverPageState extends State<ScreenSaverPage> {
|
|||
);
|
||||
source.stateNotifier.addListener(_onSourceStateChanged);
|
||||
_initSlideshowCollection();
|
||||
}
|
||||
|
||||
void _onSourceStateChanged() {
|
||||
if (_slideshowCollection == null) {
|
||||
_initSlideshowCollection();
|
||||
if (_slideshowCollection != null) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
source.stateNotifier.removeListener(_onSourceStateChanged);
|
||||
_viewerController.dispose();
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
_viewerController.autopilot = true;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget child;
|
||||
|
@ -102,6 +102,15 @@ class _ScreenSaverPageState extends State<ScreenSaverPage> {
|
|||
);
|
||||
}
|
||||
|
||||
void _onSourceStateChanged() {
|
||||
if (_slideshowCollection == null) {
|
||||
_initSlideshowCollection();
|
||||
if (_slideshowCollection != null) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _initSlideshowCollection() {
|
||||
if (source.stateNotifier.value != SourceState.ready || _slideshowCollection != null) return;
|
||||
|
||||
|
|
Loading…
Reference in a new issue