mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: set minimum width for grid fields to 50px (#3397)
* fix: set minimum width for grid field to 100px * test: add grid field width test * fix: field width should not be less then 50px * test: grid field width should not be less then 50px * fix: cursor-based resizing issue * test: updated tests
This commit is contained in:
@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:appflowy_backend/protobuf/flowy-database2/field_entities.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-database2/field_entities.pb.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||||
@ -29,8 +31,11 @@ class FieldCellBloc extends Bloc<FieldCellEvent, FieldCellState> {
|
|||||||
didReceiveFieldUpdate: (field) {
|
didReceiveFieldUpdate: (field) {
|
||||||
emit(state.copyWith(field: cellContext.field));
|
emit(state.copyWith(field: cellContext.field));
|
||||||
},
|
},
|
||||||
|
onResizeStart: () {
|
||||||
|
emit(state.copyWith(resizeStart: state.width));
|
||||||
|
},
|
||||||
startUpdateWidth: (offset) {
|
startUpdateWidth: (offset) {
|
||||||
final width = state.width + offset;
|
final width = max(offset + state.resizeStart, 50).toDouble();
|
||||||
emit(state.copyWith(width: width));
|
emit(state.copyWith(width: width));
|
||||||
},
|
},
|
||||||
endUpdateWidth: () {
|
endUpdateWidth: () {
|
||||||
@ -66,6 +71,7 @@ class FieldCellEvent with _$FieldCellEvent {
|
|||||||
const factory FieldCellEvent.initial() = _InitialCell;
|
const factory FieldCellEvent.initial() = _InitialCell;
|
||||||
const factory FieldCellEvent.didReceiveFieldUpdate(FieldPB field) =
|
const factory FieldCellEvent.didReceiveFieldUpdate(FieldPB field) =
|
||||||
_DidReceiveFieldUpdate;
|
_DidReceiveFieldUpdate;
|
||||||
|
const factory FieldCellEvent.onResizeStart() = _OnResizeStart;
|
||||||
const factory FieldCellEvent.startUpdateWidth(double offset) =
|
const factory FieldCellEvent.startUpdateWidth(double offset) =
|
||||||
_StartUpdateWidth;
|
_StartUpdateWidth;
|
||||||
const factory FieldCellEvent.endUpdateWidth() = _EndUpdateWidth;
|
const factory FieldCellEvent.endUpdateWidth() = _EndUpdateWidth;
|
||||||
@ -77,11 +83,13 @@ class FieldCellState with _$FieldCellState {
|
|||||||
required String viewId,
|
required String viewId,
|
||||||
required FieldPB field,
|
required FieldPB field,
|
||||||
required double width,
|
required double width,
|
||||||
|
required double resizeStart,
|
||||||
}) = _FieldCellState;
|
}) = _FieldCellState;
|
||||||
|
|
||||||
factory FieldCellState.initial(FieldContext cellContext) => FieldCellState(
|
factory FieldCellState.initial(FieldContext cellContext) => FieldCellState(
|
||||||
viewId: cellContext.viewId,
|
viewId: cellContext.viewId,
|
||||||
field: cellContext.field,
|
field: cellContext.field,
|
||||||
width: cellContext.field.width.toDouble(),
|
width: cellContext.field.width.toDouble(),
|
||||||
|
resizeStart: 0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -125,10 +125,15 @@ class _DragToExpandLine extends StatelessWidget {
|
|||||||
onTap: () {},
|
onTap: () {},
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
behavior: HitTestBehavior.opaque,
|
behavior: HitTestBehavior.opaque,
|
||||||
|
onHorizontalDragStart: (details) {
|
||||||
|
context
|
||||||
|
.read<FieldCellBloc>()
|
||||||
|
.add(const FieldCellEvent.onResizeStart());
|
||||||
|
},
|
||||||
onHorizontalDragUpdate: (value) {
|
onHorizontalDragUpdate: (value) {
|
||||||
context
|
context
|
||||||
.read<FieldCellBloc>()
|
.read<FieldCellBloc>()
|
||||||
.add(FieldCellEvent.startUpdateWidth(value.delta.dx));
|
.add(FieldCellEvent.startUpdateWidth(value.localPosition.dx));
|
||||||
},
|
},
|
||||||
onHorizontalDragEnd: (end) {
|
onHorizontalDragEnd: (end) {
|
||||||
context
|
context
|
||||||
|
@ -0,0 +1,60 @@
|
|||||||
|
import 'package:appflowy/plugins/database_view/application/field/field_cell_bloc.dart';
|
||||||
|
import 'package:appflowy/plugins/database_view/application/field/field_service.dart';
|
||||||
|
import 'package:bloc_test/bloc_test.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
import '../util.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
late AppFlowyGridTest gridTest;
|
||||||
|
|
||||||
|
setUpAll(() async {
|
||||||
|
gridTest = await AppFlowyGridTest.ensureInitialized();
|
||||||
|
});
|
||||||
|
|
||||||
|
group('$FieldCellBloc', () {
|
||||||
|
late GridTestContext context;
|
||||||
|
late double width;
|
||||||
|
|
||||||
|
setUp(() async {
|
||||||
|
context = await gridTest.createTestGrid();
|
||||||
|
});
|
||||||
|
|
||||||
|
blocTest(
|
||||||
|
'update field width',
|
||||||
|
build: () => FieldCellBloc(
|
||||||
|
cellContext: FieldContext(
|
||||||
|
field: context.fieldContexts[0].field,
|
||||||
|
viewId: context.gridView.id,
|
||||||
|
),
|
||||||
|
)..add(const FieldCellEvent.initial()),
|
||||||
|
act: (bloc) {
|
||||||
|
width = bloc.state.width;
|
||||||
|
bloc.add(const FieldCellEvent.onResizeStart());
|
||||||
|
bloc.add(const FieldCellEvent.startUpdateWidth(100));
|
||||||
|
bloc.add(const FieldCellEvent.endUpdateWidth());
|
||||||
|
},
|
||||||
|
verify: (bloc) {
|
||||||
|
expect(bloc.state.width, width + 100);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
blocTest(
|
||||||
|
'field width should not be lesser than 50px',
|
||||||
|
build: () => FieldCellBloc(
|
||||||
|
cellContext: FieldContext(
|
||||||
|
field: context.fieldContexts[0].field,
|
||||||
|
viewId: context.gridView.id,
|
||||||
|
),
|
||||||
|
)..add(const FieldCellEvent.initial()),
|
||||||
|
act: (bloc) {
|
||||||
|
bloc.add(const FieldCellEvent.onResizeStart());
|
||||||
|
bloc.add(const FieldCellEvent.startUpdateWidth(-110));
|
||||||
|
bloc.add(const FieldCellEvent.endUpdateWidth());
|
||||||
|
},
|
||||||
|
verify: (bloc) {
|
||||||
|
expect(bloc.state.width, 50);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
Reference in New Issue
Block a user