1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-20 00:38:24 +02:00
immich/mobile/lib/shared/views/immich_loading_overlay.dart
martyfuhry 3cd3411c1f
refactor(mobile): Use hooks to manage Chewie controller for video (#7008)
* video loading delayed

* Chewie controller implemented in hook

* fixing look and feel

* Finalizing delay and animations

* Fixes issue with immersive mode showing immediately in videos

* format fix

* Fixes bug where video controls would hide immediately after showing while playing and reverts hide controls timer to 5 seconds

* Fixed rebase issues

---------

Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
2024-02-22 23:18:02 -06:00

70 lines
1.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:immich_mobile/extensions/build_context_extensions.dart';
import 'package:immich_mobile/shared/ui/delayed_loading_indicator.dart';
final _loadingEntry = OverlayEntry(
builder: (context) => SizedBox.square(
dimension: double.infinity,
child: DecoratedBox(
decoration:
BoxDecoration(color: context.colorScheme.surface.withAlpha(200)),
child: const Center(
child: DelayedLoadingIndicator(
delay: Duration(seconds: 1),
fadeInDuration: Duration(milliseconds: 400),
),
),
),
),
);
ValueNotifier<bool> useProcessingOverlay() {
return use(const _LoadingOverlay());
}
class _LoadingOverlay extends Hook<ValueNotifier<bool>> {
const _LoadingOverlay();
@override
_LoadingOverlayState createState() => _LoadingOverlayState();
}
class _LoadingOverlayState
extends HookState<ValueNotifier<bool>, _LoadingOverlay> {
late final _isLoading = ValueNotifier(false)..addListener(_listener);
OverlayEntry? _loadingOverlay;
void _listener() {
setState(() {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (_isLoading.value) {
_loadingOverlay?.remove();
_loadingOverlay = _loadingEntry;
Overlay.of(context).insert(_loadingEntry);
} else {
_loadingOverlay?.remove();
_loadingOverlay = null;
}
});
});
}
@override
ValueNotifier<bool> build(BuildContext context) {
return _isLoading;
}
@override
void dispose() {
_isLoading.dispose();
super.dispose();
}
@override
Object? get debugValue => _isLoading.value;
@override
String get debugLabel => 'useProcessingOverlay<>';
}