mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-10-04 04:43:13 +00:00
fix: title flash when resizing (#6481)
This commit is contained in:
parent
8e6f051dec
commit
1a82f3fff1
@ -1,6 +1,7 @@
|
|||||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
import 'package:appflowy/generated/locale_keys.g.dart';
|
||||||
import 'package:appflowy/plugins/document/application/document_appearance_cubit.dart';
|
import 'package:appflowy/plugins/document/application/document_appearance_cubit.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/shared_context/shared_context.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/shared_context/shared_context.dart';
|
||||||
|
import 'package:appflowy/plugins/document/presentation/editor_style.dart';
|
||||||
import 'package:appflowy/shared/text_field/text_filed_with_metric_lines.dart';
|
import 'package:appflowy/shared/text_field/text_filed_with_metric_lines.dart';
|
||||||
import 'package:appflowy/workspace/application/appearance_defaults.dart';
|
import 'package:appflowy/workspace/application/appearance_defaults.dart';
|
||||||
import 'package:appflowy/workspace/application/view/view_bloc.dart';
|
import 'package:appflowy/workspace/application/view/view_bloc.dart';
|
||||||
@ -16,11 +17,9 @@ class CoverTitle extends StatelessWidget {
|
|||||||
const CoverTitle({
|
const CoverTitle({
|
||||||
super.key,
|
super.key,
|
||||||
required this.view,
|
required this.view,
|
||||||
required this.offset,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
final ViewPB view;
|
final ViewPB view;
|
||||||
final double offset;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -28,7 +27,6 @@ class CoverTitle extends StatelessWidget {
|
|||||||
create: (context) => ViewBloc(view: view)..add(const ViewEvent.initial()),
|
create: (context) => ViewBloc(view: view)..add(const ViewEvent.initial()),
|
||||||
child: _InnerCoverTitle(
|
child: _InnerCoverTitle(
|
||||||
view: view,
|
view: view,
|
||||||
offset: offset,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -37,11 +35,9 @@ class CoverTitle extends StatelessWidget {
|
|||||||
class _InnerCoverTitle extends StatefulWidget {
|
class _InnerCoverTitle extends StatefulWidget {
|
||||||
const _InnerCoverTitle({
|
const _InnerCoverTitle({
|
||||||
required this.view,
|
required this.view,
|
||||||
required this.offset,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
final ViewPB view;
|
final ViewPB view;
|
||||||
final double offset;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<_InnerCoverTitle> createState() => _InnerCoverTitleState();
|
State<_InnerCoverTitle> createState() => _InnerCoverTitleState();
|
||||||
@ -50,6 +46,7 @@ class _InnerCoverTitle extends StatefulWidget {
|
|||||||
class _InnerCoverTitleState extends State<_InnerCoverTitle> {
|
class _InnerCoverTitleState extends State<_InnerCoverTitle> {
|
||||||
final titleTextController = TextEditingController();
|
final titleTextController = TextEditingController();
|
||||||
final titleFocusNode = FocusNode();
|
final titleFocusNode = FocusNode();
|
||||||
|
|
||||||
late final editorContext = context.read<SharedEditorContext>();
|
late final editorContext = context.read<SharedEditorContext>();
|
||||||
late final editorState = context.read<EditorState>();
|
late final editorState = context.read<EditorState>();
|
||||||
bool isTitleFocused = false;
|
bool isTitleFocused = false;
|
||||||
@ -99,12 +96,14 @@ class _InnerCoverTitleState extends State<_InnerCoverTitle> {
|
|||||||
.textTheme
|
.textTheme
|
||||||
.bodyMedium!
|
.bodyMedium!
|
||||||
.copyWith(fontSize: 38.0, fontWeight: FontWeight.w700);
|
.copyWith(fontSize: 38.0, fontWeight: FontWeight.w700);
|
||||||
|
final width = context.read<DocumentAppearanceCubit>().state.width;
|
||||||
return BlocConsumer<ViewBloc, ViewState>(
|
return BlocConsumer<ViewBloc, ViewState>(
|
||||||
listener: _onListen,
|
listener: _onListen,
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
final appearance = context.read<DocumentAppearanceCubit>().state;
|
final appearance = context.read<DocumentAppearanceCubit>().state;
|
||||||
return Container(
|
return Container(
|
||||||
padding: EdgeInsets.symmetric(horizontal: widget.offset),
|
padding: EditorStyleCustomizer.documentPaddingWithOptionMenu,
|
||||||
|
constraints: BoxConstraints(maxWidth: width),
|
||||||
child: Theme(
|
child: Theme(
|
||||||
data: Theme.of(context).copyWith(
|
data: Theme.of(context).copyWith(
|
||||||
textSelectionTheme: TextSelectionThemeData(
|
textSelectionTheme: TextSelectionThemeData(
|
||||||
|
@ -168,38 +168,48 @@ class _DocumentCoverWidgetState extends State<DocumentCoverWidget> {
|
|||||||
onChangeCover: (type, details) =>
|
onChangeCover: (type, details) =>
|
||||||
_saveIconOrCover(cover: (type, details)),
|
_saveIconOrCover(cover: (type, details)),
|
||||||
),
|
),
|
||||||
// don't render the icon if the offset is 0
|
_buildCoverIcon(
|
||||||
if (hasIcon && offset != 0)
|
context,
|
||||||
Positioned(
|
constraints,
|
||||||
left: offset,
|
offset,
|
||||||
// if hasCover, there shouldn't be icons present so the icon can
|
),
|
||||||
// be closer to the bottom.
|
|
||||||
bottom: hasCover
|
|
||||||
? kToolbarHeight - kIconHeight / 2
|
|
||||||
: kToolbarHeight,
|
|
||||||
child: DocumentIcon(
|
|
||||||
editorState: widget.editorState,
|
|
||||||
node: widget.node,
|
|
||||||
icon: viewIcon,
|
|
||||||
onChangeIcon: (icon) => _saveIconOrCover(icon: icon),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
if (offset != 0)
|
Padding(
|
||||||
Padding(
|
padding: const EdgeInsets.only(bottom: 12.0),
|
||||||
padding: const EdgeInsets.only(bottom: 12.0),
|
child: CoverTitle(
|
||||||
child: CoverTitle(
|
view: widget.view,
|
||||||
view: widget.view,
|
|
||||||
offset: offset,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildCoverIcon(
|
||||||
|
BuildContext context,
|
||||||
|
BoxConstraints constraints,
|
||||||
|
double offset,
|
||||||
|
) {
|
||||||
|
if (!hasIcon || offset == 0) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Positioned(
|
||||||
|
// if hasCover, there shouldn't be icons present so the icon can
|
||||||
|
// be closer to the bottom.
|
||||||
|
left: offset,
|
||||||
|
bottom: hasCover ? kToolbarHeight - kIconHeight / 2 : kToolbarHeight,
|
||||||
|
child: DocumentIcon(
|
||||||
|
editorState: widget.editorState,
|
||||||
|
node: widget.node,
|
||||||
|
icon: viewIcon,
|
||||||
|
onChangeIcon: (icon) => _saveIconOrCover(icon: icon),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void _reload() => setState(() {});
|
void _reload() => setState(() {});
|
||||||
|
|
||||||
double _calculateIconLeft(BuildContext context, BoxConstraints constraints) {
|
double _calculateIconLeft(BuildContext context, BoxConstraints constraints) {
|
||||||
|
@ -43,7 +43,15 @@ class EditorStyleCustomizer {
|
|||||||
|
|
||||||
static EdgeInsets get documentPadding => UniversalPlatform.isMobile
|
static EdgeInsets get documentPadding => UniversalPlatform.isMobile
|
||||||
? const EdgeInsets.symmetric(horizontal: 24)
|
? const EdgeInsets.symmetric(horizontal: 24)
|
||||||
: const EdgeInsets.only(left: 40, right: 40 + 44);
|
: EdgeInsets.only(
|
||||||
|
left: 40,
|
||||||
|
right: 40 + EditorStyleCustomizer.optionMenuWidth,
|
||||||
|
);
|
||||||
|
|
||||||
|
static EdgeInsets get documentPaddingWithOptionMenu =>
|
||||||
|
documentPadding + EdgeInsets.only(left: optionMenuWidth);
|
||||||
|
|
||||||
|
static double get optionMenuWidth => UniversalPlatform.isMobile ? 0 : 44;
|
||||||
|
|
||||||
EditorStyle style() {
|
EditorStyle style() {
|
||||||
if (UniversalPlatform.isDesktopOrWeb) {
|
if (UniversalPlatform.isDesktopOrWeb) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user