fix: refactor text alignment handling in block components
This commit is contained in:
parent
e59b36173f
commit
a912c1c965
11 changed files with 28 additions and 2 deletions
|
|
@ -203,7 +203,7 @@
|
||||||
isa = PBXProject;
|
isa = PBXProject;
|
||||||
attributes = {
|
attributes = {
|
||||||
LastSwiftUpdateCheck = 0920;
|
LastSwiftUpdateCheck = 0920;
|
||||||
LastUpgradeCheck = 1430;
|
LastUpgradeCheck = 1300;
|
||||||
ORGANIZATIONNAME = "";
|
ORGANIZATIONNAME = "";
|
||||||
TargetAttributes = {
|
TargetAttributes = {
|
||||||
33CC10EC2044A3C60003C045 = {
|
33CC10EC2044A3C60003C045 = {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Scheme
|
<Scheme
|
||||||
LastUpgradeVersion = "1430"
|
LastUpgradeVersion = "1300"
|
||||||
version = "1.3">
|
version = "1.3">
|
||||||
<BuildAction
|
<BuildAction
|
||||||
parallelizeBuildables = "YES"
|
parallelizeBuildables = "YES"
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,7 @@ class _BulletedListBlockComponentWidgetState
|
||||||
key: forwardKey,
|
key: forwardKey,
|
||||||
node: widget.node,
|
node: widget.node,
|
||||||
editorState: editorState,
|
editorState: editorState,
|
||||||
|
textAlign: alignment?.toTextAlign,
|
||||||
placeholderText: placeholderText,
|
placeholderText: placeholderText,
|
||||||
textSpanDecorator: (textSpan) => textSpan.updateTextStyle(
|
textSpanDecorator: (textSpan) => textSpan.updateTextStyle(
|
||||||
textStyle,
|
textStyle,
|
||||||
|
|
|
||||||
|
|
@ -142,6 +142,7 @@ class _HeadingBlockComponentWidgetState
|
||||||
key: forwardKey,
|
key: forwardKey,
|
||||||
node: widget.node,
|
node: widget.node,
|
||||||
editorState: editorState,
|
editorState: editorState,
|
||||||
|
textAlign: alignment?.toTextAlign,
|
||||||
textSpanDecorator: (textSpan) =>
|
textSpanDecorator: (textSpan) =>
|
||||||
textSpan.updateTextStyle(textStyle).updateTextStyle(
|
textSpan.updateTextStyle(textStyle).updateTextStyle(
|
||||||
widget.textStyleBuilder?.call(level) ??
|
widget.textStyleBuilder?.call(level) ??
|
||||||
|
|
|
||||||
|
|
@ -142,6 +142,7 @@ class _NumberedListBlockComponentWidgetState
|
||||||
key: forwardKey,
|
key: forwardKey,
|
||||||
node: widget.node,
|
node: widget.node,
|
||||||
editorState: editorState,
|
editorState: editorState,
|
||||||
|
textAlign: alignment?.toTextAlign,
|
||||||
placeholderText: placeholderText,
|
placeholderText: placeholderText,
|
||||||
textSpanDecorator: (textSpan) => textSpan.updateTextStyle(
|
textSpanDecorator: (textSpan) => textSpan.updateTextStyle(
|
||||||
textStyle,
|
textStyle,
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,7 @@ class _QuoteBlockComponentWidgetState extends State<QuoteBlockComponentWidget>
|
||||||
key: forwardKey,
|
key: forwardKey,
|
||||||
node: widget.node,
|
node: widget.node,
|
||||||
editorState: editorState,
|
editorState: editorState,
|
||||||
|
textAlign: alignment?.toTextAlign,
|
||||||
placeholderText: placeholderText,
|
placeholderText: placeholderText,
|
||||||
textSpanDecorator: (textSpan) => textSpan.updateTextStyle(
|
textSpanDecorator: (textSpan) => textSpan.updateTextStyle(
|
||||||
textStyle,
|
textStyle,
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ class AppFlowyRichText extends StatefulWidget {
|
||||||
this.placeholderTextSpanDecorator,
|
this.placeholderTextSpanDecorator,
|
||||||
this.textDirection = TextDirection.ltr,
|
this.textDirection = TextDirection.ltr,
|
||||||
this.textSpanDecoratorForCustomAttributes,
|
this.textSpanDecoratorForCustomAttributes,
|
||||||
|
this.textAlign,
|
||||||
required this.node,
|
required this.node,
|
||||||
required this.editorState,
|
required this.editorState,
|
||||||
});
|
});
|
||||||
|
|
@ -65,6 +66,8 @@ class AppFlowyRichText extends StatefulWidget {
|
||||||
/// customize the text span for placeholder text
|
/// customize the text span for placeholder text
|
||||||
final AppFlowyTextSpanDecorator? placeholderTextSpanDecorator;
|
final AppFlowyTextSpanDecorator? placeholderTextSpanDecorator;
|
||||||
|
|
||||||
|
final TextAlign? textAlign;
|
||||||
|
|
||||||
/// customize the text span for custom attributes
|
/// customize the text span for custom attributes
|
||||||
///
|
///
|
||||||
/// You can use this to customize the text span for custom attributes
|
/// You can use this to customize the text span for custom attributes
|
||||||
|
|
@ -247,6 +250,7 @@ class _AppFlowyRichTextState extends State<AppFlowyRichText>
|
||||||
final textSpan = getTextSpan();
|
final textSpan = getTextSpan();
|
||||||
return RichText(
|
return RichText(
|
||||||
key: textKey,
|
key: textKey,
|
||||||
|
textAlign: widget.textAlign ?? TextAlign.start,
|
||||||
textHeightBehavior: const TextHeightBehavior(
|
textHeightBehavior: const TextHeightBehavior(
|
||||||
applyHeightToFirstAscent: false,
|
applyHeightToFirstAscent: false,
|
||||||
applyHeightToLastDescent: false,
|
applyHeightToLastDescent: false,
|
||||||
|
|
|
||||||
|
|
@ -146,6 +146,7 @@ class _TextBlockComponentWidgetState extends State<TextBlockComponentWidget>
|
||||||
key: forwardKey,
|
key: forwardKey,
|
||||||
node: widget.node,
|
node: widget.node,
|
||||||
editorState: editorState,
|
editorState: editorState,
|
||||||
|
textAlign: alignment?.toTextAlign,
|
||||||
placeholderText: _showPlaceholder ? placeholderText : ' ',
|
placeholderText: _showPlaceholder ? placeholderText : ' ',
|
||||||
textSpanDecorator: (textSpan) =>
|
textSpanDecorator: (textSpan) =>
|
||||||
textSpan.updateTextStyle(textStyle),
|
textSpan.updateTextStyle(textStyle),
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,7 @@ class _TodoListBlockComponentWidgetState
|
||||||
key: forwardKey,
|
key: forwardKey,
|
||||||
node: widget.node,
|
node: widget.node,
|
||||||
editorState: editorState,
|
editorState: editorState,
|
||||||
|
textAlign: alignment?.toTextAlign,
|
||||||
placeholderText: placeholderText,
|
placeholderText: placeholderText,
|
||||||
textDirection: textDirection,
|
textDirection: textDirection,
|
||||||
textSpanDecorator: (textSpan) =>
|
textSpanDecorator: (textSpan) =>
|
||||||
|
|
|
||||||
15
lib/src/extensions/alignment_extension.dart
Normal file
15
lib/src/extensions/alignment_extension.dart
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
extension AppFlowyTextAlign on Alignment {
|
||||||
|
TextAlign get toTextAlign {
|
||||||
|
switch (this) {
|
||||||
|
case Alignment.center:
|
||||||
|
return TextAlign.center;
|
||||||
|
case Alignment.centerRight:
|
||||||
|
return TextAlign.right;
|
||||||
|
case Alignment.centerLeft:
|
||||||
|
default:
|
||||||
|
return TextAlign.left;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
export 'alignment_extension.dart';
|
||||||
export 'attributes_extension.dart';
|
export 'attributes_extension.dart';
|
||||||
export 'color_extension.dart';
|
export 'color_extension.dart';
|
||||||
export 'node_extensions.dart';
|
export 'node_extensions.dart';
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue