mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-06-22 18:34:29 +10:00
fix(chat): stabilize pinch-to-zoom scaling
This commit is contained in:
@@ -6,12 +6,18 @@ import '../services/chat_text_scale_service.dart';
|
||||
/// Gesture wrapper that exposes two-finger pinch-to-zoom for chat scrollables.
|
||||
/// Double-tap resets the scale. Only the wrapper itself listens to gestures;
|
||||
/// child scrollables keep their normal touch handling.
|
||||
class ChatZoomWrapper extends StatelessWidget {
|
||||
ChatZoomWrapper({super.key, required this.child, this.onDoubleTap});
|
||||
class ChatZoomWrapper extends StatefulWidget {
|
||||
const ChatZoomWrapper({super.key, required this.child, this.onDoubleTap});
|
||||
|
||||
final Widget child;
|
||||
final VoidCallback? onDoubleTap;
|
||||
final _ZoomGestureState _state = _ZoomGestureState();
|
||||
|
||||
@override
|
||||
State<ChatZoomWrapper> createState() => _ChatZoomWrapperState();
|
||||
}
|
||||
|
||||
class _ChatZoomWrapperState extends State<ChatZoomWrapper> {
|
||||
double? _startScale;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -21,25 +27,23 @@ class ChatZoomWrapper extends StatelessWidget {
|
||||
behavior: HitTestBehavior.translucent,
|
||||
onDoubleTap: () {
|
||||
service.reset();
|
||||
onDoubleTap?.call();
|
||||
service.persist();
|
||||
widget.onDoubleTap?.call();
|
||||
},
|
||||
onScaleStart: (details) {
|
||||
if (details.pointerCount != 2) return;
|
||||
_state.startScale = service.scale;
|
||||
_startScale = service.scale;
|
||||
},
|
||||
onScaleUpdate: (details) {
|
||||
if (details.pointerCount != 2) return;
|
||||
final baseScale = _state.startScale ?? service.scale;
|
||||
final baseScale = _startScale ?? service.scale;
|
||||
service.setScale(baseScale * details.scale);
|
||||
},
|
||||
onScaleEnd: (_) {
|
||||
_state.startScale = null;
|
||||
_startScale = null;
|
||||
service.persist();
|
||||
},
|
||||
child: child,
|
||||
child: widget.child,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ZoomGestureState {
|
||||
double? startScale;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user