chore: rename some classes

This commit is contained in:
appflowy 2022-05-31 21:26:06 +08:00
parent a568f6323d
commit cdfe94cf98
5 changed files with 43 additions and 42 deletions

View File

@ -56,24 +56,23 @@ abstract class GridCellWidget implements FlowyHoverWidget {
@override
final ValueNotifier<bool> onFocus = ValueNotifier<bool>(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),

View File

@ -24,7 +24,7 @@ class _CheckboxCellState extends State<CheckboxCell> {
void initState() {
final cellContext = widget.cellContextBuilder.build();
_cellBloc = getIt<CheckboxCellBloc>(param1: cellContext)..add(const CheckboxCellEvent.initial());
_listenCellRequestFocus();
_handleRequestFocus();
super.initState();
}
@ -51,19 +51,19 @@ class _CheckboxCellState extends State<CheckboxCell> {
@override
void didUpdateWidget(covariant CheckboxCell oldWidget) {
_listenCellRequestFocus();
_handleRequestFocus();
super.didUpdateWidget(oldWidget);
}
@override
Future<void> 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());
});
}

View File

@ -22,7 +22,7 @@ class NumberCell extends StatefulWidget with GridCellWidget {
class _NumberCellState extends State<NumberCell> {
late NumberCellBloc _cellBloc;
late TextEditingController _controller;
late CellSingleFocusNode _focusNode;
late SingleListenrFocusNode _focusNode;
Timer? _delayOperation;
@override
@ -30,14 +30,14 @@ class _NumberCellState extends State<NumberCell> {
final cellContext = widget.cellContextBuilder.build();
_cellBloc = getIt<NumberCellBloc>(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<NumberCell> {
@override
Future<void> 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<NumberCell> {
}
}
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);
}

View File

@ -35,7 +35,7 @@ class GridTextCell extends StatefulWidget with GridCellWidget {
class _GridTextCellState extends State<GridTextCell> {
late TextCellBloc _cellBloc;
late TextEditingController _controller;
late CellSingleFocusNode _focusNode;
late SingleListenrFocusNode _focusNode;
Timer? _delayOperation;
@override
@ -44,9 +44,9 @@ class _GridTextCellState extends State<GridTextCell> {
_cellBloc = getIt<TextCellBloc>(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<GridTextCell> {
@override
Future<void> 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<GridTextCell> {
@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);
}

View File

@ -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<GridURLCell> {
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<GridURLCell> {
@override
Future<void> 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<GridURLCell> {
}
}
void _listenRequestFocus(BuildContext context) {
widget.requestFocus.addListener(() {
void _handleRequestFocus() {
widget.beginFocus.setListener(() {
_openUrlOrEdit(_cellBloc.state.url);
});
}