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 @override
final ValueNotifier<bool> onFocus = ValueNotifier<bool>(false); final ValueNotifier<bool> onFocus = ValueNotifier<bool>(false);
final GridCellRequestFocusNotifier requestFocus = GridCellRequestFocusNotifier(); final GridCellBeginFocusFocus beginFocus = GridCellBeginFocusFocus();
GridCellExpander? buildExpander() { GridCellExpander? buildExpander() {
return null; return null;
} }
} }
class GridCellRequestFocusNotifier extends ChangeNotifier { class GridCellBeginFocusFocus extends ChangeNotifier {
VoidCallback? _listener; VoidCallback? _listener;
@override void setListener(VoidCallback listener) {
void addListener(VoidCallback listener) {
if (_listener != null) { if (_listener != null) {
removeListener(_listener!); removeListener(_listener!);
} }
_listener = listener; _listener = listener;
super.addListener(listener); addListener(listener);
} }
void removeAllListener() { void removeAllListener() {
@ -89,10 +88,10 @@ class GridCellRequestFocusNotifier extends ChangeNotifier {
abstract class GridCellStyle {} abstract class GridCellStyle {}
class CellSingleFocusNode extends FocusNode { class SingleListenrFocusNode extends FocusNode {
VoidCallback? _listener; VoidCallback? _listener;
void setSingleListener(VoidCallback listener) { void setListener(VoidCallback listener) {
if (_listener != null) { if (_listener != null) {
removeListener(_listener!); removeListener(_listener!);
} }
@ -101,7 +100,7 @@ class CellSingleFocusNode extends FocusNode {
super.addListener(listener); super.addListener(listener);
} }
void removeSingleListener() { void removeAllListener() {
if (_listener != null) { if (_listener != null) {
removeListener(_listener!); removeListener(_listener!);
} }
@ -163,7 +162,7 @@ class CellContainer extends StatelessWidget {
return GestureDetector( return GestureDetector(
behavior: HitTestBehavior.translucent, behavior: HitTestBehavior.translucent,
onTap: () => child.requestFocus.notify(), onTap: () => child.beginFocus.notify(),
child: Container( child: Container(
constraints: BoxConstraints(maxWidth: width, minHeight: 46), constraints: BoxConstraints(maxWidth: width, minHeight: 46),
decoration: _makeBoxDecoration(context, isFocus), decoration: _makeBoxDecoration(context, isFocus),

View File

@ -24,7 +24,7 @@ class _CheckboxCellState extends State<CheckboxCell> {
void initState() { void initState() {
final cellContext = widget.cellContextBuilder.build(); final cellContext = widget.cellContextBuilder.build();
_cellBloc = getIt<CheckboxCellBloc>(param1: cellContext)..add(const CheckboxCellEvent.initial()); _cellBloc = getIt<CheckboxCellBloc>(param1: cellContext)..add(const CheckboxCellEvent.initial());
_listenCellRequestFocus(); _handleRequestFocus();
super.initState(); super.initState();
} }
@ -51,19 +51,19 @@ class _CheckboxCellState extends State<CheckboxCell> {
@override @override
void didUpdateWidget(covariant CheckboxCell oldWidget) { void didUpdateWidget(covariant CheckboxCell oldWidget) {
_listenCellRequestFocus(); _handleRequestFocus();
super.didUpdateWidget(oldWidget); super.didUpdateWidget(oldWidget);
} }
@override @override
Future<void> dispose() async { Future<void> dispose() async {
widget.requestFocus.removeAllListener(); widget.beginFocus.removeAllListener();
_cellBloc.close(); _cellBloc.close();
super.dispose(); super.dispose();
} }
void _listenCellRequestFocus() { void _handleRequestFocus() {
widget.requestFocus.addListener(() { widget.beginFocus.setListener(() {
_cellBloc.add(const CheckboxCellEvent.select()); _cellBloc.add(const CheckboxCellEvent.select());
}); });
} }

View File

@ -22,7 +22,7 @@ class NumberCell extends StatefulWidget with GridCellWidget {
class _NumberCellState extends State<NumberCell> { class _NumberCellState extends State<NumberCell> {
late NumberCellBloc _cellBloc; late NumberCellBloc _cellBloc;
late TextEditingController _controller; late TextEditingController _controller;
late CellSingleFocusNode _focusNode; late SingleListenrFocusNode _focusNode;
Timer? _delayOperation; Timer? _delayOperation;
@override @override
@ -30,14 +30,14 @@ class _NumberCellState extends State<NumberCell> {
final cellContext = widget.cellContextBuilder.build(); final cellContext = widget.cellContextBuilder.build();
_cellBloc = getIt<NumberCellBloc>(param1: cellContext)..add(const NumberCellEvent.initial()); _cellBloc = getIt<NumberCellBloc>(param1: cellContext)..add(const NumberCellEvent.initial());
_controller = TextEditingController(text: contentFromState(_cellBloc.state)); _controller = TextEditingController(text: contentFromState(_cellBloc.state));
_focusNode = CellSingleFocusNode(); _focusNode = SingleListenrFocusNode();
_listenFocusNode(); _listenOnFocusNodeChanged();
super.initState(); super.initState();
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
_listenCellRequestFocus(context); _handleCellRequestFocus(context);
return BlocProvider.value( return BlocProvider.value(
value: _cellBloc, value: _cellBloc,
child: MultiBlocListener( child: MultiBlocListener(
@ -65,19 +65,17 @@ class _NumberCellState extends State<NumberCell> {
@override @override
Future<void> dispose() async { Future<void> dispose() async {
widget.requestFocus.removeAllListener(); widget.beginFocus.removeAllListener();
_delayOperation?.cancel(); _delayOperation?.cancel();
_cellBloc.close(); _cellBloc.close();
_focusNode.removeSingleListener(); _focusNode.removeAllListener();
_focusNode.dispose(); _focusNode.dispose();
super.dispose(); super.dispose();
} }
@override @override
void didUpdateWidget(covariant NumberCell oldWidget) { void didUpdateWidget(covariant NumberCell oldWidget) {
if (oldWidget != widget) { _listenOnFocusNodeChanged();
_listenFocusNode();
}
super.didUpdateWidget(oldWidget); super.didUpdateWidget(oldWidget);
} }
@ -92,16 +90,16 @@ class _NumberCellState extends State<NumberCell> {
} }
} }
void _listenFocusNode() { void _listenOnFocusNodeChanged() {
widget.onFocus.value = _focusNode.hasFocus; widget.onFocus.value = _focusNode.hasFocus;
_focusNode.setSingleListener(() { _focusNode.setListener(() {
widget.onFocus.value = _focusNode.hasFocus; widget.onFocus.value = _focusNode.hasFocus;
focusChanged(); focusChanged();
}); });
} }
void _listenCellRequestFocus(BuildContext context) { void _handleCellRequestFocus(BuildContext context) {
widget.requestFocus.addListener(() { widget.beginFocus.setListener(() {
if (_focusNode.hasFocus == false && _focusNode.canRequestFocus) { if (_focusNode.hasFocus == false && _focusNode.canRequestFocus) {
FocusScope.of(context).requestFocus(_focusNode); FocusScope.of(context).requestFocus(_focusNode);
} }

View File

@ -35,7 +35,7 @@ class GridTextCell extends StatefulWidget with GridCellWidget {
class _GridTextCellState extends State<GridTextCell> { class _GridTextCellState extends State<GridTextCell> {
late TextCellBloc _cellBloc; late TextCellBloc _cellBloc;
late TextEditingController _controller; late TextEditingController _controller;
late CellSingleFocusNode _focusNode; late SingleListenrFocusNode _focusNode;
Timer? _delayOperation; Timer? _delayOperation;
@override @override
@ -44,9 +44,9 @@ class _GridTextCellState extends State<GridTextCell> {
_cellBloc = getIt<TextCellBloc>(param1: cellContext); _cellBloc = getIt<TextCellBloc>(param1: cellContext);
_cellBloc.add(const TextCellEvent.initial()); _cellBloc.add(const TextCellEvent.initial());
_controller = TextEditingController(text: _cellBloc.state.content); _controller = TextEditingController(text: _cellBloc.state.content);
_focusNode = CellSingleFocusNode(); _focusNode = SingleListenrFocusNode();
_listenFocusNode(); _listenOnFocusNodeChanged();
_listenRequestFocus(context); _listenRequestFocus(context);
super.initState(); super.initState();
} }
@ -81,10 +81,10 @@ class _GridTextCellState extends State<GridTextCell> {
@override @override
Future<void> dispose() async { Future<void> dispose() async {
widget.requestFocus.removeAllListener(); widget.beginFocus.removeAllListener();
_delayOperation?.cancel(); _delayOperation?.cancel();
_cellBloc.close(); _cellBloc.close();
_focusNode.removeSingleListener(); _focusNode.removeAllListener();
_focusNode.dispose(); _focusNode.dispose();
super.dispose(); super.dispose();
@ -93,21 +93,21 @@ class _GridTextCellState extends State<GridTextCell> {
@override @override
void didUpdateWidget(covariant GridTextCell oldWidget) { void didUpdateWidget(covariant GridTextCell oldWidget) {
if (oldWidget != widget) { if (oldWidget != widget) {
_listenFocusNode(); _listenOnFocusNodeChanged();
} }
super.didUpdateWidget(oldWidget); super.didUpdateWidget(oldWidget);
} }
void _listenFocusNode() { void _listenOnFocusNodeChanged() {
widget.onFocus.value = _focusNode.hasFocus; widget.onFocus.value = _focusNode.hasFocus;
_focusNode.setSingleListener(() { _focusNode.setListener(() {
widget.onFocus.value = _focusNode.hasFocus; widget.onFocus.value = _focusNode.hasFocus;
focusChanged(); focusChanged();
}); });
} }
void _listenRequestFocus(BuildContext context) { void _listenRequestFocus(BuildContext context) {
widget.requestFocus.addListener(() { widget.beginFocus.setListener(() {
if (_focusNode.hasFocus == false && _focusNode.canRequestFocus) { if (_focusNode.hasFocus == false && _focusNode.canRequestFocus) {
FocusScope.of(context).requestFocus(_focusNode); 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:app_flowy/workspace/application/grid/cell/url_cell_bloc.dart';
import 'package:flowy_infra/image.dart'; import 'package:flowy_infra/image.dart';
import 'package:flowy_infra/theme.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/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
@ -53,7 +51,7 @@ class _GridURLCellState extends State<GridURLCell> {
final cellContext = widget.cellContextBuilder.build() as GridURLCellContext; final cellContext = widget.cellContextBuilder.build() as GridURLCellContext;
_cellBloc = URLCellBloc(cellContext: cellContext); _cellBloc = URLCellBloc(cellContext: cellContext);
_cellBloc.add(const URLCellEvent.initial()); _cellBloc.add(const URLCellEvent.initial());
_listenRequestFocus(context); _handleRequestFocus();
super.initState(); super.initState();
} }
@ -85,11 +83,17 @@ class _GridURLCellState extends State<GridURLCell> {
@override @override
Future<void> dispose() async { Future<void> dispose() async {
widget.requestFocus.removeAllListener(); widget.beginFocus.removeAllListener();
_cellBloc.close(); _cellBloc.close();
super.dispose(); super.dispose();
} }
@override
void didUpdateWidget(covariant GridURLCell oldWidget) {
_handleRequestFocus();
super.didUpdateWidget(oldWidget);
}
TapGestureRecognizer _tapGesture(BuildContext context) { TapGestureRecognizer _tapGesture(BuildContext context) {
final gesture = TapGestureRecognizer(); final gesture = TapGestureRecognizer();
gesture.onTap = () async { gesture.onTap = () async {
@ -109,8 +113,8 @@ class _GridURLCellState extends State<GridURLCell> {
} }
} }
void _listenRequestFocus(BuildContext context) { void _handleRequestFocus() {
widget.requestFocus.addListener(() { widget.beginFocus.setListener(() {
_openUrlOrEdit(_cellBloc.state.url); _openUrlOrEdit(_cellBloc.state.url);
}); });
} }