mirror of https://github.com/immich-app/immich.git
refactor(mobile): immich loading overlay (#5320)
* refactor: dcm fixes * refactor: ImmichLoadingOverlay to custom hook * chore: dart fixes * pr changes * fix: process overlay add / remove in postframecallback --------- Co-authored-by: shalong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> Co-authored-by: Alex Tran <alex.tran1502@gmail.com>pull/5387/head
parent
513f252a0c
commit
527d602a9f
@ -1,5 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
Color immichBackgroundColor = const Color(0xFFf6f8fe);
|
const Color immichBackgroundColor = Color(0xFFf6f8fe);
|
||||||
Color immichDarkBackgroundColor = const Color.fromARGB(255, 0, 0, 0);
|
const Color immichDarkBackgroundColor = Color.fromARGB(255, 0, 0, 0);
|
||||||
Color immichDarkThemePrimaryColor = const Color.fromARGB(255, 173, 203, 250);
|
const Color immichDarkThemePrimaryColor = Color.fromARGB(255, 173, 203, 250);
|
||||||
|
|||||||
@ -1,41 +1,64 @@
|
|||||||
import 'package:flutter/material.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/immich_loading_indicator.dart';
|
import 'package:immich_mobile/shared/ui/immich_loading_indicator.dart';
|
||||||
|
|
||||||
class ImmichLoadingOverlay extends StatelessWidget {
|
final _loadingEntry = OverlayEntry(
|
||||||
const ImmichLoadingOverlay({
|
builder: (context) => SizedBox.square(
|
||||||
Key? key,
|
dimension: double.infinity,
|
||||||
}) : super(key: key);
|
child: DecoratedBox(
|
||||||
|
decoration:
|
||||||
|
BoxDecoration(color: context.colorScheme.surface.withAlpha(200)),
|
||||||
|
child: const Center(child: ImmichLoadingIndicator()),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
ValueNotifier<bool> useProcessingOverlay() {
|
||||||
|
return use(const _LoadingOverlay());
|
||||||
|
}
|
||||||
|
|
||||||
|
class _LoadingOverlay extends Hook<ValueNotifier<bool>> {
|
||||||
|
const _LoadingOverlay();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
_LoadingOverlayState createState() => _LoadingOverlayState();
|
||||||
return ValueListenableBuilder<bool>(
|
|
||||||
valueListenable:
|
|
||||||
ImmichLoadingOverlayController.appLoader.loaderShowingNotifier,
|
|
||||||
builder: (context, shouldShow, child) {
|
|
||||||
return shouldShow
|
|
||||||
? const Scaffold(
|
|
||||||
backgroundColor: Colors.black54,
|
|
||||||
body: Center(
|
|
||||||
child: ImmichLoadingIndicator(),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: const SizedBox();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ImmichLoadingOverlayController {
|
class _LoadingOverlayState
|
||||||
static final ImmichLoadingOverlayController appLoader =
|
extends HookState<ValueNotifier<bool>, _LoadingOverlay> {
|
||||||
ImmichLoadingOverlayController();
|
late final _isProcessing = ValueNotifier(false)..addListener(_listener);
|
||||||
ValueNotifier<bool> loaderShowingNotifier = ValueNotifier(false);
|
OverlayEntry? overlayEntry;
|
||||||
ValueNotifier<String> loaderTextNotifier = ValueNotifier('error message');
|
|
||||||
|
void _listener() {
|
||||||
|
setState(() {
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
if (_isProcessing.value) {
|
||||||
|
overlayEntry?.remove();
|
||||||
|
overlayEntry = _loadingEntry;
|
||||||
|
Overlay.of(context).insert(_loadingEntry);
|
||||||
|
} else {
|
||||||
|
overlayEntry?.remove();
|
||||||
|
overlayEntry = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void show() {
|
@override
|
||||||
loaderShowingNotifier.value = true;
|
ValueNotifier<bool> build(BuildContext context) {
|
||||||
|
return _isProcessing;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hide() {
|
@override
|
||||||
loaderShowingNotifier.value = false;
|
void dispose() {
|
||||||
|
_isProcessing.dispose();
|
||||||
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Object? get debugValue => _isProcessing.value;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get debugLabel => 'useProcessingOverlay<>';
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue