Skip to content

Commit cdfe94c

Browse files
committed
chore: rename some classes
1 parent a568f63 commit cdfe94c

File tree

5 files changed

+43
-42
lines changed

5 files changed

+43
-42
lines changed

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,23 @@ abstract class GridCellWidget implements FlowyHoverWidget {
5656
@override
5757
final ValueNotifier<bool> onFocus = ValueNotifier<bool>(false);
5858

59-
final GridCellRequestFocusNotifier requestFocus = GridCellRequestFocusNotifier();
59+
final GridCellBeginFocusFocus beginFocus = GridCellBeginFocusFocus();
6060

6161
GridCellExpander? buildExpander() {
6262
return null;
6363
}
6464
}
6565

66-
class GridCellRequestFocusNotifier extends ChangeNotifier {
66+
class GridCellBeginFocusFocus extends ChangeNotifier {
6767
VoidCallback? _listener;
6868

69-
@override
70-
void addListener(VoidCallback listener) {
69+
void setListener(VoidCallback listener) {
7170
if (_listener != null) {
7271
removeListener(_listener!);
7372
}
7473

7574
_listener = listener;
76-
super.addListener(listener);
75+
addListener(listener);
7776
}
7877

7978
void removeAllListener() {
@@ -89,10 +88,10 @@ class GridCellRequestFocusNotifier extends ChangeNotifier {
8988

9089
abstract class GridCellStyle {}
9190

92-
class CellSingleFocusNode extends FocusNode {
91+
class SingleListenrFocusNode extends FocusNode {
9392
VoidCallback? _listener;
9493

95-
void setSingleListener(VoidCallback listener) {
94+
void setListener(VoidCallback listener) {
9695
if (_listener != null) {
9796
removeListener(_listener!);
9897
}
@@ -101,7 +100,7 @@ class CellSingleFocusNode extends FocusNode {
101100
super.addListener(listener);
102101
}
103102

104-
void removeSingleListener() {
103+
void removeAllListener() {
105104
if (_listener != null) {
106105
removeListener(_listener!);
107106
}
@@ -163,7 +162,7 @@ class CellContainer extends StatelessWidget {
163162

164163
return GestureDetector(
165164
behavior: HitTestBehavior.translucent,
166-
onTap: () => child.requestFocus.notify(),
165+
onTap: () => child.beginFocus.notify(),
167166
child: Container(
168167
constraints: BoxConstraints(maxWidth: width, minHeight: 46),
169168
decoration: _makeBoxDecoration(context, isFocus),

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/checkbox_cell.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class _CheckboxCellState extends State<CheckboxCell> {
2424
void initState() {
2525
final cellContext = widget.cellContextBuilder.build();
2626
_cellBloc = getIt<CheckboxCellBloc>(param1: cellContext)..add(const CheckboxCellEvent.initial());
27-
_listenCellRequestFocus();
27+
_handleRequestFocus();
2828
super.initState();
2929
}
3030

@@ -51,19 +51,19 @@ class _CheckboxCellState extends State<CheckboxCell> {
5151

5252
@override
5353
void didUpdateWidget(covariant CheckboxCell oldWidget) {
54-
_listenCellRequestFocus();
54+
_handleRequestFocus();
5555
super.didUpdateWidget(oldWidget);
5656
}
5757

5858
@override
5959
Future<void> dispose() async {
60-
widget.requestFocus.removeAllListener();
60+
widget.beginFocus.removeAllListener();
6161
_cellBloc.close();
6262
super.dispose();
6363
}
6464

65-
void _listenCellRequestFocus() {
66-
widget.requestFocus.addListener(() {
65+
void _handleRequestFocus() {
66+
widget.beginFocus.setListener(() {
6767
_cellBloc.add(const CheckboxCellEvent.select());
6868
});
6969
}

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/number_cell.dart

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ class NumberCell extends StatefulWidget with GridCellWidget {
2222
class _NumberCellState extends State<NumberCell> {
2323
late NumberCellBloc _cellBloc;
2424
late TextEditingController _controller;
25-
late CellSingleFocusNode _focusNode;
25+
late SingleListenrFocusNode _focusNode;
2626
Timer? _delayOperation;
2727

2828
@override
2929
void initState() {
3030
final cellContext = widget.cellContextBuilder.build();
3131
_cellBloc = getIt<NumberCellBloc>(param1: cellContext)..add(const NumberCellEvent.initial());
3232
_controller = TextEditingController(text: contentFromState(_cellBloc.state));
33-
_focusNode = CellSingleFocusNode();
34-
_listenFocusNode();
33+
_focusNode = SingleListenrFocusNode();
34+
_listenOnFocusNodeChanged();
3535
super.initState();
3636
}
3737

3838
@override
3939
Widget build(BuildContext context) {
40-
_listenCellRequestFocus(context);
40+
_handleCellRequestFocus(context);
4141
return BlocProvider.value(
4242
value: _cellBloc,
4343
child: MultiBlocListener(
@@ -65,19 +65,17 @@ class _NumberCellState extends State<NumberCell> {
6565

6666
@override
6767
Future<void> dispose() async {
68-
widget.requestFocus.removeAllListener();
68+
widget.beginFocus.removeAllListener();
6969
_delayOperation?.cancel();
7070
_cellBloc.close();
71-
_focusNode.removeSingleListener();
71+
_focusNode.removeAllListener();
7272
_focusNode.dispose();
7373
super.dispose();
7474
}
7575

7676
@override
7777
void didUpdateWidget(covariant NumberCell oldWidget) {
78-
if (oldWidget != widget) {
79-
_listenFocusNode();
80-
}
78+
_listenOnFocusNodeChanged();
8179
super.didUpdateWidget(oldWidget);
8280
}
8381

@@ -92,16 +90,16 @@ class _NumberCellState extends State<NumberCell> {
9290
}
9391
}
9492

95-
void _listenFocusNode() {
93+
void _listenOnFocusNodeChanged() {
9694
widget.onFocus.value = _focusNode.hasFocus;
97-
_focusNode.setSingleListener(() {
95+
_focusNode.setListener(() {
9896
widget.onFocus.value = _focusNode.hasFocus;
9997
focusChanged();
10098
});
10199
}
102100

103-
void _listenCellRequestFocus(BuildContext context) {
104-
widget.requestFocus.addListener(() {
101+
void _handleCellRequestFocus(BuildContext context) {
102+
widget.beginFocus.setListener(() {
105103
if (_focusNode.hasFocus == false && _focusNode.canRequestFocus) {
106104
FocusScope.of(context).requestFocus(_focusNode);
107105
}

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/text_cell.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class GridTextCell extends StatefulWidget with GridCellWidget {
3535
class _GridTextCellState extends State<GridTextCell> {
3636
late TextCellBloc _cellBloc;
3737
late TextEditingController _controller;
38-
late CellSingleFocusNode _focusNode;
38+
late SingleListenrFocusNode _focusNode;
3939
Timer? _delayOperation;
4040

4141
@override
@@ -44,9 +44,9 @@ class _GridTextCellState extends State<GridTextCell> {
4444
_cellBloc = getIt<TextCellBloc>(param1: cellContext);
4545
_cellBloc.add(const TextCellEvent.initial());
4646
_controller = TextEditingController(text: _cellBloc.state.content);
47-
_focusNode = CellSingleFocusNode();
47+
_focusNode = SingleListenrFocusNode();
4848

49-
_listenFocusNode();
49+
_listenOnFocusNodeChanged();
5050
_listenRequestFocus(context);
5151
super.initState();
5252
}
@@ -81,10 +81,10 @@ class _GridTextCellState extends State<GridTextCell> {
8181

8282
@override
8383
Future<void> dispose() async {
84-
widget.requestFocus.removeAllListener();
84+
widget.beginFocus.removeAllListener();
8585
_delayOperation?.cancel();
8686
_cellBloc.close();
87-
_focusNode.removeSingleListener();
87+
_focusNode.removeAllListener();
8888
_focusNode.dispose();
8989

9090
super.dispose();
@@ -93,21 +93,21 @@ class _GridTextCellState extends State<GridTextCell> {
9393
@override
9494
void didUpdateWidget(covariant GridTextCell oldWidget) {
9595
if (oldWidget != widget) {
96-
_listenFocusNode();
96+
_listenOnFocusNodeChanged();
9797
}
9898
super.didUpdateWidget(oldWidget);
9999
}
100100

101-
void _listenFocusNode() {
101+
void _listenOnFocusNodeChanged() {
102102
widget.onFocus.value = _focusNode.hasFocus;
103-
_focusNode.setSingleListener(() {
103+
_focusNode.setListener(() {
104104
widget.onFocus.value = _focusNode.hasFocus;
105105
focusChanged();
106106
});
107107
}
108108

109109
void _listenRequestFocus(BuildContext context) {
110-
widget.requestFocus.addListener(() {
110+
widget.beginFocus.setListener(() {
111111
if (_focusNode.hasFocus == false && _focusNode.canRequestFocus) {
112112
FocusScope.of(context).requestFocus(_focusNode);
113113
}

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/url_cell/url_cell.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import 'dart:async';
22
import 'package:app_flowy/workspace/application/grid/cell/url_cell_bloc.dart';
33
import 'package:flowy_infra/image.dart';
44
import 'package:flowy_infra/theme.dart';
5-
import 'package:flowy_infra_ui/style_widget/hover.dart';
6-
import 'package:flowy_infra_ui/style_widget/icon_button.dart';
75
import 'package:flutter/gestures.dart';
86
import 'package:flutter/material.dart';
97
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -53,7 +51,7 @@ class _GridURLCellState extends State<GridURLCell> {
5351
final cellContext = widget.cellContextBuilder.build() as GridURLCellContext;
5452
_cellBloc = URLCellBloc(cellContext: cellContext);
5553
_cellBloc.add(const URLCellEvent.initial());
56-
_listenRequestFocus(context);
54+
_handleRequestFocus();
5755
super.initState();
5856
}
5957

@@ -85,11 +83,17 @@ class _GridURLCellState extends State<GridURLCell> {
8583

8684
@override
8785
Future<void> dispose() async {
88-
widget.requestFocus.removeAllListener();
86+
widget.beginFocus.removeAllListener();
8987
_cellBloc.close();
9088
super.dispose();
9189
}
9290

91+
@override
92+
void didUpdateWidget(covariant GridURLCell oldWidget) {
93+
_handleRequestFocus();
94+
super.didUpdateWidget(oldWidget);
95+
}
96+
9397
TapGestureRecognizer _tapGesture(BuildContext context) {
9498
final gesture = TapGestureRecognizer();
9599
gesture.onTap = () async {
@@ -109,8 +113,8 @@ class _GridURLCellState extends State<GridURLCell> {
109113
}
110114
}
111115

112-
void _listenRequestFocus(BuildContext context) {
113-
widget.requestFocus.addListener(() {
116+
void _handleRequestFocus() {
117+
widget.beginFocus.setListener(() {
114118
_openUrlOrEdit(_cellBloc.state.url);
115119
});
116120
}

0 commit comments

Comments
 (0)