diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart index 705ceb5b48..0fb342bf03 100755 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart @@ -56,24 +56,23 @@ abstract class GridCellWidget implements FlowyHoverWidget { @override final ValueNotifier onFocus = ValueNotifier(false); - final GridCellRequestFocusNotifier requestFocus = GridCellRequestFocusNotifier(); + final GridCellBeginFocusFocus beginFocus = GridCellBeginFocusFocus(); GridCellExpander? buildExpander() { return null; } } -class GridCellRequestFocusNotifier extends ChangeNotifier { +class GridCellBeginFocusFocus extends ChangeNotifier { VoidCallback? _listener; - @override - void addListener(VoidCallback listener) { + void setListener(VoidCallback listener) { if (_listener != null) { removeListener(_listener!); } _listener = listener; - super.addListener(listener); + addListener(listener); } void removeAllListener() { @@ -89,10 +88,10 @@ class GridCellRequestFocusNotifier extends ChangeNotifier { abstract class GridCellStyle {} -class CellSingleFocusNode extends FocusNode { +class SingleListenrFocusNode extends FocusNode { VoidCallback? _listener; - void setSingleListener(VoidCallback listener) { + void setListener(VoidCallback listener) { if (_listener != null) { removeListener(_listener!); } @@ -101,7 +100,7 @@ class CellSingleFocusNode extends FocusNode { super.addListener(listener); } - void removeSingleListener() { + void removeAllListener() { if (_listener != null) { removeListener(_listener!); } @@ -163,7 +162,7 @@ class CellContainer extends StatelessWidget { return GestureDetector( behavior: HitTestBehavior.translucent, - onTap: () => child.requestFocus.notify(), + onTap: () => child.beginFocus.notify(), child: Container( constraints: BoxConstraints(maxWidth: width, minHeight: 46), decoration: _makeBoxDecoration(context, isFocus), diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/checkbox_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/checkbox_cell.dart index b2493d55ed..574063a91e 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/checkbox_cell.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/checkbox_cell.dart @@ -24,7 +24,7 @@ class _CheckboxCellState extends State { void initState() { final cellContext = widget.cellContextBuilder.build(); _cellBloc = getIt(param1: cellContext)..add(const CheckboxCellEvent.initial()); - _listenCellRequestFocus(); + _handleRequestFocus(); super.initState(); } @@ -51,19 +51,19 @@ class _CheckboxCellState extends State { @override void didUpdateWidget(covariant CheckboxCell oldWidget) { - _listenCellRequestFocus(); + _handleRequestFocus(); super.didUpdateWidget(oldWidget); } @override Future dispose() async { - widget.requestFocus.removeAllListener(); + widget.beginFocus.removeAllListener(); _cellBloc.close(); super.dispose(); } - void _listenCellRequestFocus() { - widget.requestFocus.addListener(() { + void _handleRequestFocus() { + widget.beginFocus.setListener(() { _cellBloc.add(const CheckboxCellEvent.select()); }); } diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/number_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/number_cell.dart index d11229c4cb..5c3947f05f 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/number_cell.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/number_cell.dart @@ -22,7 +22,7 @@ class NumberCell extends StatefulWidget with GridCellWidget { class _NumberCellState extends State { late NumberCellBloc _cellBloc; late TextEditingController _controller; - late CellSingleFocusNode _focusNode; + late SingleListenrFocusNode _focusNode; Timer? _delayOperation; @override @@ -30,14 +30,14 @@ class _NumberCellState extends State { final cellContext = widget.cellContextBuilder.build(); _cellBloc = getIt(param1: cellContext)..add(const NumberCellEvent.initial()); _controller = TextEditingController(text: contentFromState(_cellBloc.state)); - _focusNode = CellSingleFocusNode(); - _listenFocusNode(); + _focusNode = SingleListenrFocusNode(); + _listenOnFocusNodeChanged(); super.initState(); } @override Widget build(BuildContext context) { - _listenCellRequestFocus(context); + _handleCellRequestFocus(context); return BlocProvider.value( value: _cellBloc, child: MultiBlocListener( @@ -65,19 +65,17 @@ class _NumberCellState extends State { @override Future dispose() async { - widget.requestFocus.removeAllListener(); + widget.beginFocus.removeAllListener(); _delayOperation?.cancel(); _cellBloc.close(); - _focusNode.removeSingleListener(); + _focusNode.removeAllListener(); _focusNode.dispose(); super.dispose(); } @override void didUpdateWidget(covariant NumberCell oldWidget) { - if (oldWidget != widget) { - _listenFocusNode(); - } + _listenOnFocusNodeChanged(); super.didUpdateWidget(oldWidget); } @@ -92,16 +90,16 @@ class _NumberCellState extends State { } } - void _listenFocusNode() { + void _listenOnFocusNodeChanged() { widget.onFocus.value = _focusNode.hasFocus; - _focusNode.setSingleListener(() { + _focusNode.setListener(() { widget.onFocus.value = _focusNode.hasFocus; focusChanged(); }); } - void _listenCellRequestFocus(BuildContext context) { - widget.requestFocus.addListener(() { + void _handleCellRequestFocus(BuildContext context) { + widget.beginFocus.setListener(() { if (_focusNode.hasFocus == false && _focusNode.canRequestFocus) { FocusScope.of(context).requestFocus(_focusNode); } diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/text_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/text_cell.dart index 1563d41d86..3a79859372 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/text_cell.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/text_cell.dart @@ -35,7 +35,7 @@ class GridTextCell extends StatefulWidget with GridCellWidget { class _GridTextCellState extends State { late TextCellBloc _cellBloc; late TextEditingController _controller; - late CellSingleFocusNode _focusNode; + late SingleListenrFocusNode _focusNode; Timer? _delayOperation; @override @@ -44,9 +44,9 @@ class _GridTextCellState extends State { _cellBloc = getIt(param1: cellContext); _cellBloc.add(const TextCellEvent.initial()); _controller = TextEditingController(text: _cellBloc.state.content); - _focusNode = CellSingleFocusNode(); + _focusNode = SingleListenrFocusNode(); - _listenFocusNode(); + _listenOnFocusNodeChanged(); _listenRequestFocus(context); super.initState(); } @@ -81,10 +81,10 @@ class _GridTextCellState extends State { @override Future dispose() async { - widget.requestFocus.removeAllListener(); + widget.beginFocus.removeAllListener(); _delayOperation?.cancel(); _cellBloc.close(); - _focusNode.removeSingleListener(); + _focusNode.removeAllListener(); _focusNode.dispose(); super.dispose(); @@ -93,21 +93,21 @@ class _GridTextCellState extends State { @override void didUpdateWidget(covariant GridTextCell oldWidget) { if (oldWidget != widget) { - _listenFocusNode(); + _listenOnFocusNodeChanged(); } super.didUpdateWidget(oldWidget); } - void _listenFocusNode() { + void _listenOnFocusNodeChanged() { widget.onFocus.value = _focusNode.hasFocus; - _focusNode.setSingleListener(() { + _focusNode.setListener(() { widget.onFocus.value = _focusNode.hasFocus; focusChanged(); }); } void _listenRequestFocus(BuildContext context) { - widget.requestFocus.addListener(() { + widget.beginFocus.setListener(() { if (_focusNode.hasFocus == false && _focusNode.canRequestFocus) { FocusScope.of(context).requestFocus(_focusNode); } diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/url_cell/url_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/url_cell/url_cell.dart index fe708c710a..91624c9dd1 100644 --- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/url_cell/url_cell.dart +++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/url_cell/url_cell.dart @@ -2,8 +2,6 @@ import 'dart:async'; import 'package:app_flowy/workspace/application/grid/cell/url_cell_bloc.dart'; import 'package:flowy_infra/image.dart'; import 'package:flowy_infra/theme.dart'; -import 'package:flowy_infra_ui/style_widget/hover.dart'; -import 'package:flowy_infra_ui/style_widget/icon_button.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -53,7 +51,7 @@ class _GridURLCellState extends State { final cellContext = widget.cellContextBuilder.build() as GridURLCellContext; _cellBloc = URLCellBloc(cellContext: cellContext); _cellBloc.add(const URLCellEvent.initial()); - _listenRequestFocus(context); + _handleRequestFocus(); super.initState(); } @@ -85,11 +83,17 @@ class _GridURLCellState extends State { @override Future dispose() async { - widget.requestFocus.removeAllListener(); + widget.beginFocus.removeAllListener(); _cellBloc.close(); super.dispose(); } + @override + void didUpdateWidget(covariant GridURLCell oldWidget) { + _handleRequestFocus(); + super.didUpdateWidget(oldWidget); + } + TapGestureRecognizer _tapGesture(BuildContext context) { final gesture = TapGestureRecognizer(); gesture.onTap = () async { @@ -109,8 +113,8 @@ class _GridURLCellState extends State { } } - void _listenRequestFocus(BuildContext context) { - widget.requestFocus.addListener(() { + void _handleRequestFocus() { + widget.beginFocus.setListener(() { _openUrlOrEdit(_cellBloc.state.url); }); }