Skip to content

Commit 0ea5b3c

Browse files
authored
fix: rtl related issues
1 parent f314864 commit 0ea5b3c

File tree

11 files changed

+108
-48
lines changed

11 files changed

+108
-48
lines changed

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
7575
alignToolbarItem,
7676
buildTextColorItem(),
7777
buildHighlightColorItem(),
78-
...textDirectionItems
78+
// TODO: enable it in version 0.3.3
79+
// ...textDirectionItems,
7980
];
8081

8182
late final List<SelectionMenuItem> slashMenuItems;

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_option_button.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import 'package:appflowy/generated/flowy_svgs.g.dart';
22
import 'package:appflowy/generated/locale_keys.g.dart';
33
import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/block_action_button.dart';
44
import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/option_action.dart';
5+
import 'package:appflowy/workspace/application/appearance.dart';
56
import 'package:appflowy/workspace/presentation/widgets/pop_up_action.dart';
67
import 'package:appflowy_editor/appflowy_editor.dart';
78
import 'package:appflowy_popover/appflowy_popover.dart';
89
import 'package:easy_localization/easy_localization.dart';
910
import 'package:flutter/material.dart';
11+
import 'package:flutter_bloc/flutter_bloc.dart';
1012

1113
class BlockOptionButton extends StatelessWidget {
1214
const BlockOptionButton({
@@ -38,7 +40,11 @@ class BlockOptionButton extends StatelessWidget {
3840
}).toList();
3941

4042
return PopoverActionList<PopoverAction>(
41-
direction: PopoverDirection.leftWithCenterAligned,
43+
direction:
44+
context.read<AppearanceSettingsCubit>().state.layoutDirection ==
45+
LayoutDirection.rtlLayout
46+
? PopoverDirection.rightWithCenterAligned
47+
: PopoverDirection.leftWithCenterAligned,
4248
actions: popoverActions,
4349
onPopupBuilder: () {
4450
keepEditorFocusNotifier.value += 1;

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ class CalloutBlockComponentWidget extends BlockComponentStatefulWidget {
115115

116116
class _CalloutBlockComponentWidgetState
117117
extends State<CalloutBlockComponentWidget>
118-
with SelectableMixin, DefaultSelectableMixin, BlockComponentConfigurable {
118+
with
119+
SelectableMixin,
120+
DefaultSelectableMixin,
121+
BlockComponentConfigurable,
122+
BlockComponentTextDirectionMixin,
123+
BlockComponentAlignMixin {
119124
// the key used to forward focus to the richtext child
120125
@override
121126
final forwardKey = GlobalKey(debugLabel: 'flowy_rich_text');
@@ -146,19 +151,28 @@ class _CalloutBlockComponentWidgetState
146151
String get emoji => node.attributes[CalloutBlockKeys.icon] ?? '📌';
147152

148153
// get access to the editor state via provider
154+
@override
149155
late final editorState = Provider.of<EditorState>(context, listen: false);
150156

151157
// build the callout block widget
152158
@override
153159
Widget build(BuildContext context) {
160+
final textDirection = calculateTextDirection(
161+
layoutDirection: Directionality.maybeOf(context),
162+
);
163+
154164
Widget child = Container(
155165
decoration: BoxDecoration(
156166
borderRadius: const BorderRadius.all(Radius.circular(8.0)),
157167
color: backgroundColor,
158168
),
159169
width: double.infinity,
170+
alignment: alignment,
160171
child: Row(
161172
crossAxisAlignment: CrossAxisAlignment.start,
173+
mainAxisAlignment: MainAxisAlignment.start,
174+
mainAxisSize: MainAxisSize.min,
175+
textDirection: textDirection,
162176
children: [
163177
// the emoji picker button for the note
164178
Padding(
@@ -178,10 +192,10 @@ class _CalloutBlockComponentWidgetState
178192
},
179193
),
180194
),
181-
Expanded(
195+
Flexible(
182196
child: Padding(
183197
padding: const EdgeInsets.symmetric(vertical: 8.0),
184-
child: buildCalloutBlockComponent(context),
198+
child: buildCalloutBlockComponent(context, textDirection),
185199
),
186200
),
187201
const HSpace(8.0),
@@ -218,7 +232,10 @@ class _CalloutBlockComponentWidgetState
218232
}
219233

220234
// build the richtext child
221-
Widget buildCalloutBlockComponent(BuildContext context) {
235+
Widget buildCalloutBlockComponent(
236+
BuildContext context,
237+
TextDirection textDirection,
238+
) {
222239
return Padding(
223240
padding: padding,
224241
child: AppFlowyRichText(
@@ -233,6 +250,7 @@ class _CalloutBlockComponentWidgetState
233250
placeholderTextSpanDecorator: (textSpan) => textSpan.updateTextStyle(
234251
placeholderTextStyle,
235252
),
253+
textDirection: textDirection,
236254
cursorColor: editorState.editorStyle.cursorColor,
237255
selectionColor: editorState.editorStyle.selectionColor,
238256
),

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_component.dart

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selec
33
import 'package:appflowy/plugins/document/presentation/editor_plugins/base/string_extension.dart';
44
import 'package:appflowy_editor/appflowy_editor.dart';
55
import 'package:appflowy_popover/appflowy_popover.dart';
6-
import 'package:easy_localization/easy_localization.dart';
6+
import 'package:easy_localization/easy_localization.dart' hide TextDirection;
77
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
88
import 'package:flutter/material.dart';
99
import 'package:highlight/highlight.dart' as highlight;
@@ -98,7 +98,11 @@ class CodeBlockComponentWidget extends BlockComponentStatefulWidget {
9898
}
9999

100100
class _CodeBlockComponentWidgetState extends State<CodeBlockComponentWidget>
101-
with SelectableMixin, DefaultSelectableMixin, BlockComponentConfigurable {
101+
with
102+
SelectableMixin,
103+
DefaultSelectableMixin,
104+
BlockComponentConfigurable,
105+
BlockComponentTextDirectionMixin {
102106
// the key used to forward focus to the richtext child
103107
@override
104108
final forwardKey = GlobalKey(debugLabel: 'flowy_rich_text');
@@ -175,13 +179,17 @@ class _CodeBlockComponentWidgetState extends State<CodeBlockComponentWidget>
175179
..add('c')
176180
..sort();
177181

182+
@override
178183
late final editorState = context.read<EditorState>();
179184

180185
String? get language => node.attributes[CodeBlockKeys.language] as String?;
181186
String? autoDetectLanguage;
182187

183188
@override
184189
Widget build(BuildContext context) {
190+
final textDirection = calculateTextDirection(
191+
layoutDirection: Directionality.maybeOf(context),
192+
);
185193
Widget child = Container(
186194
decoration: BoxDecoration(
187195
borderRadius: const BorderRadius.all(Radius.circular(8.0)),
@@ -191,9 +199,10 @@ class _CodeBlockComponentWidgetState extends State<CodeBlockComponentWidget>
191199
child: Column(
192200
crossAxisAlignment: CrossAxisAlignment.start,
193201
mainAxisSize: MainAxisSize.min,
202+
textDirection: textDirection,
194203
children: [
195204
_buildSwitchLanguageButton(context),
196-
_buildCodeBlock(context),
205+
_buildCodeBlock(context, textDirection),
197206
],
198207
),
199208
);
@@ -226,7 +235,7 @@ class _CodeBlockComponentWidgetState extends State<CodeBlockComponentWidget>
226235
return child;
227236
}
228237

229-
Widget _buildCodeBlock(BuildContext context) {
238+
Widget _buildCodeBlock(BuildContext context, TextDirection textDirection) {
230239
final delta = node.delta ?? Delta();
231240
final content = delta.toPlainText();
232241

@@ -258,6 +267,7 @@ class _CodeBlockComponentWidgetState extends State<CodeBlockComponentWidget>
258267
placeholderTextSpanDecorator: (textSpan) => TextSpan(
259268
style: textStyle,
260269
),
270+
textDirection: textDirection,
261271
cursorColor: editorState.editorStyle.cursorColor,
262272
selectionColor: editorState.editorStyle.selectionColor,
263273
),

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/outline/outline_block_component.dart

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import 'dart:async';
22

33
import 'package:appflowy/generated/locale_keys.g.dart';
44
import 'package:appflowy_editor/appflowy_editor.dart';
5-
import 'package:easy_localization/easy_localization.dart';
5+
import 'package:easy_localization/easy_localization.dart' hide TextDirection;
6+
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
67
import 'package:flowy_infra_ui/style_widget/hover.dart';
78
import 'package:flutter/material.dart';
89
import 'package:provider/provider.dart';
@@ -70,7 +71,7 @@ class OutlineBlockWidget extends BlockComponentStatefulWidget {
7071
}
7172

7273
class _OutlineBlockWidgetState extends State<OutlineBlockWidget>
73-
with BlockComponentConfigurable {
74+
with BlockComponentConfigurable, BlockComponentTextDirectionMixin {
7475
@override
7576
BlockComponentConfiguration get configuration => widget.configuration;
7677

@@ -87,6 +88,7 @@ class _OutlineBlockWidgetState extends State<OutlineBlockWidget>
8788
return colorString.tryToColor() ?? Colors.transparent;
8889
}
8990

91+
@override
9092
late EditorState editorState = context.read<EditorState>();
9193
late Stream<(TransactionTime, Transaction)> stream =
9294
editorState.transactionStream;
@@ -109,14 +111,21 @@ class _OutlineBlockWidgetState extends State<OutlineBlockWidget>
109111
}
110112

111113
Widget _buildOutlineBlock() {
114+
final textDirection = calculateTextDirection(
115+
layoutDirection: Directionality.maybeOf(context),
116+
);
117+
112118
final children = getHeadingNodes()
113119
.map(
114120
(e) => Container(
115121
padding: const EdgeInsets.only(
116122
bottom: 4.0,
117123
),
118124
width: double.infinity,
119-
child: OutlineItemWidget(node: e),
125+
child: OutlineItemWidget(
126+
node: e,
127+
textDirection: textDirection,
128+
),
120129
),
121130
)
122131
.toList();
@@ -136,7 +145,9 @@ class _OutlineBlockWidgetState extends State<OutlineBlockWidget>
136145
),
137146
child: Column(
138147
crossAxisAlignment: CrossAxisAlignment.start,
139-
mainAxisSize: MainAxisSize.max,
148+
mainAxisAlignment: MainAxisAlignment.start,
149+
mainAxisSize: MainAxisSize.min,
150+
textDirection: textDirection,
140151
children: children,
141152
),
142153
);
@@ -152,11 +163,13 @@ class OutlineItemWidget extends StatelessWidget {
152163
OutlineItemWidget({
153164
super.key,
154165
required this.node,
166+
required this.textDirection,
155167
}) {
156168
assert(node.type == HeadingBlockKeys.type);
157169
}
158170

159171
final Node node;
172+
final TextDirection textDirection;
160173

161174
@override
162175
Widget build(BuildContext context) {
@@ -170,15 +183,20 @@ class OutlineItemWidget extends StatelessWidget {
170183
builder: (context, onHover) {
171184
return GestureDetector(
172185
onTap: () => scrollToBlock(context),
173-
child: Container(
174-
padding: EdgeInsets.only(left: node.leftIndent),
175-
child: Text(
176-
node.outlineItemText,
177-
style: style.copyWith(
178-
color:
179-
onHover ? Theme.of(context).colorScheme.onSecondary : null,
186+
child: Row(
187+
textDirection: textDirection,
188+
children: [
189+
HSpace(node.leftIndent),
190+
Text(
191+
node.outlineItemText,
192+
textDirection: textDirection,
193+
style: style.copyWith(
194+
color: onHover
195+
? Theme.of(context).colorScheme.onSecondary
196+
: null,
197+
),
180198
),
181-
),
199+
],
182200
),
183201
);
184202
},

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ class _ToggleListBlockComponentWidgetState
109109
BlockComponentConfigurable,
110110
BlockComponentBackgroundColorMixin,
111111
NestedBlockComponentStatefulWidgetMixin,
112-
BlockComponentTextDirectionMixin {
112+
BlockComponentTextDirectionMixin,
113+
BlockComponentAlignMixin {
113114
// the key used to forward focus to the richtext child
114115
@override
115116
final forwardKey = GlobalKey(debugLabel: 'flowy_rich_text');
@@ -157,8 +158,12 @@ class _ToggleListBlockComponentWidgetState
157158
Widget child = Container(
158159
color: backgroundColor,
159160
width: double.infinity,
161+
alignment: alignment,
160162
child: Row(
163+
mainAxisSize: MainAxisSize.min,
161164
crossAxisAlignment: CrossAxisAlignment.start,
165+
mainAxisAlignment: MainAxisAlignment.start,
166+
textDirection: textDirection,
162167
children: [
163168
// the emoji picker button for the note
164169
FlowyIconButton(
@@ -171,7 +176,7 @@ class _ToggleListBlockComponentWidgetState
171176
const SizedBox(
172177
width: 4.0,
173178
),
174-
Expanded(
179+
Flexible(
175180
child: AppFlowyRichText(
176181
key: forwardKey,
177182
delegate: this,
@@ -187,6 +192,7 @@ class _ToggleListBlockComponentWidgetState
187192
placeholderTextStyle,
188193
),
189194
textDirection: textDirection,
195+
textAlign: alignment?.toTextAlign,
190196
cursorColor: editorState.editorStyle.cursorColor,
191197
selectionColor: editorState.editorStyle.selectionColor,
192198
),

frontend/appflowy_flutter/lib/workspace/application/appearance.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ class AppearanceSettingsState with _$AppearanceSettingsState {
300300
ThemeData get lightTheme => _getThemeData(Brightness.light);
301301
ThemeData get darkTheme => _getThemeData(Brightness.dark);
302302

303+
// only support LTR layout in version 0.3.2, enable it in version 0.3.3
304+
LayoutDirectionPB get layoutDirectionPB => LayoutDirectionPB.LTRLayout;
305+
TextDirectionPB get textDirectionPB => TextDirectionPB.LTR;
306+
303307
ThemeData _getThemeData(Brightness brightness) {
304308
// Poppins and SF Mono are not well supported in some languages, so use the
305309
// built-in font for the following languages.
@@ -450,7 +454,7 @@ class AppearanceSettingsState with _$AppearanceSettingsState {
450454
fontWeight: FontWeight.w400,
451455
fontColor: theme.hint,
452456
),
453-
)
457+
),
454458
],
455459
);
456460
return desktopThemeData;

frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_appearance_view.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ class SettingsAppearanceView extends StatelessWidget {
2929
ThemeFontFamilySetting(
3030
currentFontFamily: state.font,
3131
),
32-
LayoutDirectionSetting(
33-
currentLayoutDirection: state.layoutDirection,
34-
),
35-
TextDirectionSetting(
36-
currentTextDirection: state.textDirection,
37-
),
32+
// TODO: enablt them in version 0.3.3
33+
// LayoutDirectionSetting(
34+
// currentLayoutDirection: state.layoutDirection,
35+
// ),
36+
// TextDirectionSetting(
37+
// currentTextDirection: state.textDirection,
38+
// ),
3839
CreateFileSettings(),
3940
],
4041
);

frontend/appflowy_flutter/pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ packages:
5454
dependency: "direct main"
5555
description:
5656
path: "."
57-
ref: a97c816
58-
resolved-ref: a97c816c1d8cfbc5644a8be49deae334c47261e3
57+
ref: "4a87ec4"
58+
resolved-ref: "4a87ec4bd440344b8f51dd61ab84e2c68d4196d2"
5959
url: "https://github.com/AppFlowy-IO/appflowy-editor.git"
6060
source: git
6161
version: "1.3.0"

frontend/appflowy_flutter/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ dependencies:
4747
appflowy_editor:
4848
git:
4949
url: https://github.com/AppFlowy-IO/appflowy-editor.git
50-
ref: a97c816
50+
ref: 4a87ec4
5151
appflowy_popover:
5252
path: packages/appflowy_popover
5353

0 commit comments

Comments
 (0)