From cc9bd30356911b01a16901489ba3c1b22b85aab6 Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Sun, 5 Feb 2023 15:38:06 +0700 Subject: [PATCH] fix: #1290 [Bug] 300ms delay on buttons in titlebar (#1789) --- .../lib/style_widget/button.dart | 8 ++++- .../lib/widget/ignore_parent_gesture.dart | 31 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 frontend/app_flowy/packages/flowy_infra_ui/lib/widget/ignore_parent_gesture.dart diff --git a/frontend/app_flowy/packages/flowy_infra_ui/lib/style_widget/button.dart b/frontend/app_flowy/packages/flowy_infra_ui/lib/style_widget/button.dart index 73e8800979..579138a2d1 100644 --- a/frontend/app_flowy/packages/flowy_infra_ui/lib/style_widget/button.dart +++ b/frontend/app_flowy/packages/flowy_infra_ui/lib/style_widget/button.dart @@ -2,6 +2,7 @@ import 'package:flowy_infra/theme_extension.dart'; import 'package:flowy_infra/size.dart'; import 'package:flowy_infra_ui/style_widget/hover.dart'; import 'package:flowy_infra_ui/style_widget/text.dart'; +import 'package:flowy_infra_ui/widget/ignore_parent_gesture.dart'; import 'package:flowy_infra_ui/widget/spacing.dart'; import 'package:flutter/material.dart'; import 'package:textstyle_extensions/textstyle_extensions.dart'; @@ -176,7 +177,12 @@ class FlowyTextButton extends StatelessWidget { highlightColor: Colors.transparent, elevation: 0, constraints: constraints, - onPressed: onPressed, + onPressed: () {}, + child: child, + ); + + child = IgnoreParentGestureWidget( + onPress: onPressed, child: child, ); diff --git a/frontend/app_flowy/packages/flowy_infra_ui/lib/widget/ignore_parent_gesture.dart b/frontend/app_flowy/packages/flowy_infra_ui/lib/widget/ignore_parent_gesture.dart new file mode 100644 index 0000000000..9a679775b4 --- /dev/null +++ b/frontend/app_flowy/packages/flowy_infra_ui/lib/widget/ignore_parent_gesture.dart @@ -0,0 +1,31 @@ +import 'package:flutter/material.dart'; + +class IgnoreParentGestureWidget extends StatelessWidget { + const IgnoreParentGestureWidget({ + Key? key, + required this.child, + this.onPress, + }) : super(key: key); + + final Widget child; + final VoidCallback? onPress; + + @override + Widget build(BuildContext context) { + // https://docs.flutter.dev/development/ui/advanced/gestures#gesture-disambiguation + // https://github.com/AppFlowy-IO/AppFlowy/issues/1290 + return Listener( + onPointerDown: (event) { + onPress?.call(); + }, + onPointerSignal: (event) {}, + onPointerMove: (event) {}, + onPointerUp: (event) {}, + onPointerHover: (event) {}, + onPointerPanZoomStart: (event) {}, + onPointerPanZoomUpdate: (event) {}, + onPointerPanZoomEnd: (event) {}, + child: child, + ); + } +}