Skip to content

Commit

Permalink
Merge pull request AppFlowy-IO#467 from AppFlowy-IO/fix_reorder_anima…
Browse files Browse the repository at this point in the history
…tion

Fix: reorder animation
  • Loading branch information
appflowy authored Apr 28, 2022
2 parents c3ff984 + 66cf0ca commit f2cd384
Show file tree
Hide file tree
Showing 22 changed files with 276 additions and 1,372 deletions.
11 changes: 10 additions & 1 deletion frontend/app_flowy/lib/workspace/application/app/app_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,12 @@ class AppViewDataContext extends ChangeNotifier {
final String appId;
final ValueNotifier<List<View>> _viewsNotifier = ValueNotifier([]);
final ValueNotifier<View?> _selectedViewNotifier = ValueNotifier(null);
VoidCallback? _menuSharedStateListener;
ExpandableController expandController = ExpandableController(initialExpanded: false);

AppViewDataContext({required this.appId}) {
_setLatestView(getIt<MenuSharedState>().latestOpenView);
getIt<MenuSharedState>().addLatestViewListener((view) {
_menuSharedStateListener = getIt<MenuSharedState>().addLatestViewListener((view) {
_setLatestView(view);
});
}
Expand Down Expand Up @@ -234,4 +235,12 @@ class AppViewDataContext extends ChangeNotifier {
});
}
}

@override
void dispose() {
if (_menuSharedStateListener != null) {
getIt<MenuSharedState>().removeLatestViewListener(_menuSharedStateListener!);
}
super.dispose();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'dart:async';
import 'dart:collection';

import 'package:app_flowy/workspace/application/grid/cell/select_option_service.dart';
import 'package:dartz/dartz.dart';
import 'package:equatable/equatable.dart';
import 'package:flowy_sdk/dispatch/dispatch.dart';
import 'package:flowy_sdk/log.dart';
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
Expand All @@ -10,13 +12,52 @@ import 'package:flowy_sdk/protobuf/flowy-grid/cell_entities.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-grid/selection_type_option.pb.dart';
import 'package:flutter/foundation.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

import 'package:app_flowy/workspace/application/grid/cell/cell_listener.dart';
import 'package:equatable/equatable.dart';

part 'cell_service.freezed.dart';

typedef GridDefaultCellContext = GridCellContext<Cell>;
typedef GridSelectOptionCellContext = GridCellContext<SelectOptionContext>;

class GridCellContextBuilder {
final GridCellCache _cellCache;
final GridCell _gridCell;
GridCellContextBuilder({
required GridCellCache cellCache,
required GridCell gridCell,
}) : _cellCache = cellCache,
_gridCell = gridCell;

GridCellContext build() {
switch (_gridCell.field.fieldType) {
case FieldType.Checkbox:
case FieldType.DateTime:
case FieldType.Number:
return GridDefaultCellContext(
gridCell: _gridCell,
cellCache: _cellCache,
cellDataLoader: DefaultCellDataLoader(gridCell: _gridCell, reloadOnCellChanged: true),
);
case FieldType.RichText:
return GridDefaultCellContext(
gridCell: _gridCell,
cellCache: _cellCache,
cellDataLoader: DefaultCellDataLoader(gridCell: _gridCell),
);
case FieldType.MultiSelect:
case FieldType.SingleSelect:
return GridSelectOptionCellContext(
gridCell: _gridCell,
cellCache: _cellCache,
cellDataLoader: SelectOptionCellDataLoader(gridCell: _gridCell),
);
default:
throw UnimplementedError;
}
}
}

// ignore: must_be_immutable
class GridCellContext<T> extends Equatable {
final GridCell gridCell;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,26 @@ class GridHeaderBloc extends Bloc<GridHeaderEvent, GridHeaderState> {
emit(state.copyWith(fields: value.fields));
},
moveField: (_MoveField value) async {
final result = await _fieldService.moveField(value.field.id, value.fromIndex, value.toIndex);
result.fold((l) {}, (err) => Log.error(err));
await _moveField(value, emit);
},
);
},
);
}

Future<void> _moveField(_MoveField value, Emitter<GridHeaderState> emit) async {
final fields = List<Field>.from(state.fields);
fields.insert(value.toIndex, fields.removeAt(value.fromIndex));
emit(state.copyWith(fields: fields));

final result = await _fieldService.moveField(
value.field.id,
value.fromIndex,
value.toIndex,
);
result.fold((l) {}, (err) => Log.error(err));
}

Future<void> _startListening() async {
fieldCache.addListener(
onChanged: (fields) => add(GridHeaderEvent.didReceiveFieldUpdate(fields)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> {
if (state.apps.length > value.fromIndex) {
final app = state.apps[value.fromIndex];
_workspaceService.moveApp(appId: app.id, fromIndex: value.fromIndex, toIndex: value.toIndex);
final apps = List<App>.from(state.apps);
apps.insert(value.toIndex, apps.removeAt(value.fromIndex));
emit(state.copyWith(apps: apps));
}
},
);
Expand Down
Loading

0 comments on commit f2cd384

Please sign in to comment.