Skip to content

Commit e32c584

Browse files
authored
fix: remove extra padding in table on mobile (#6915)
1 parent 64e4416 commit e32c584

File tree

3 files changed

+85
-32
lines changed

3 files changed

+85
-32
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,17 @@ SimpleTableBlockComponentBuilder _buildSimpleTableBlockComponentBuilder(
316316
BuildContext context,
317317
BlockComponentConfiguration configuration,
318318
) {
319-
return SimpleTableBlockComponentBuilder(configuration: configuration);
319+
final copiedConfiguration = configuration.copyWith(
320+
padding: (node) {
321+
final padding = configuration.padding(node);
322+
if (UniversalPlatform.isDesktop) {
323+
return padding;
324+
} else {
325+
return padding.copyWith(right: padding.left);
326+
}
327+
},
328+
);
329+
return SimpleTableBlockComponentBuilder(configuration: copiedConfiguration);
320330
}
321331

322332
SimpleTableRowBlockComponentBuilder _buildSimpleTableRowBlockComponentBuilder(

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_block_component.dart

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/simple_tab
55
import 'package:appflowy_editor/appflowy_editor.dart';
66
import 'package:flutter/material.dart';
77
import 'package:provider/provider.dart';
8+
import 'package:universal_platform/universal_platform.dart';
89

910
typedef SimpleTableColumnWidthMap = Map<String, double>;
1011
typedef SimpleTableRowAlignMap = Map<String, String>;
@@ -187,28 +188,34 @@ class _SimpleTableBlockWidgetState extends State<SimpleTableBlockWidget>
187188
@override
188189
Widget build(BuildContext context) {
189190
Widget child = Transform.translate(
190-
offset: const Offset(
191-
-SimpleTableConstants.tableLeftPadding,
191+
offset: Offset(
192+
UniversalPlatform.isDesktop
193+
? -SimpleTableConstants.tableLeftPadding
194+
: 0,
192195
0,
193196
),
194197
child: _buildTable(),
195198
);
196199

197-
child = Provider.value(
198-
value: simpleTableContext,
199-
child: MouseRegion(
200-
onEnter: (event) =>
201-
simpleTableContext.isHoveringOnTableBlock.value = true,
202-
onExit: (event) {
203-
simpleTableContext.isHoveringOnTableBlock.value = false;
204-
},
205-
child: Container(
206-
alignment: Alignment.topLeft,
207-
padding: padding,
200+
child = Container(
201+
alignment: Alignment.topLeft,
202+
padding: padding,
203+
child: child,
204+
);
205+
206+
if (UniversalPlatform.isDesktop) {
207+
child = Provider.value(
208+
value: simpleTableContext,
209+
child: MouseRegion(
210+
onEnter: (event) =>
211+
simpleTableContext.isHoveringOnTableBlock.value = true,
212+
onExit: (event) {
213+
simpleTableContext.isHoveringOnTableBlock.value = false;
214+
},
208215
child: child,
209216
),
210-
),
211-
);
217+
);
218+
}
212219

213220
if (widget.showActions && widget.actionBuilder != null) {
214221
child = BlockComponentActionWrapper(
@@ -222,6 +229,14 @@ class _SimpleTableBlockWidgetState extends State<SimpleTableBlockWidget>
222229
}
223230

224231
Widget _buildTable() {
232+
if (UniversalPlatform.isDesktop) {
233+
return _buildDesktopTable();
234+
} else {
235+
return _buildMobileTable();
236+
}
237+
}
238+
239+
Widget _buildDesktopTable() {
225240
// IntrinsicWidth and IntrinsicHeight are used to make the table size fit the content.
226241
return MouseRegion(
227242
onEnter: (event) => simpleTableContext.isHoveringOnTableArea.value = true,
@@ -260,24 +275,45 @@ class _SimpleTableBlockWidgetState extends State<SimpleTableBlockWidget>
260275
),
261276
),
262277
),
263-
SimpleTableAddColumnHoverButton(
264-
editorState: editorState,
265-
node: node,
266-
),
267-
SimpleTableAddRowHoverButton(
268-
editorState: editorState,
269-
tableNode: node,
270-
),
271-
SimpleTableAddColumnAndRowHoverButton(
272-
editorState: editorState,
273-
node: node,
274-
),
278+
if (UniversalPlatform.isDesktop) ...[
279+
SimpleTableAddColumnHoverButton(
280+
editorState: editorState,
281+
node: node,
282+
),
283+
SimpleTableAddRowHoverButton(
284+
editorState: editorState,
285+
tableNode: node,
286+
),
287+
SimpleTableAddColumnAndRowHoverButton(
288+
editorState: editorState,
289+
node: node,
290+
),
291+
],
275292
],
276293
),
277294
),
278295
);
279296
}
280297

298+
Widget _buildMobileTable() {
299+
return Provider.value(
300+
value: simpleTableContext,
301+
child: SingleChildScrollView(
302+
controller: scrollController,
303+
scrollDirection: Axis.horizontal,
304+
child: IntrinsicWidth(
305+
child: IntrinsicHeight(
306+
child: Column(
307+
mainAxisSize: MainAxisSize.min,
308+
crossAxisAlignment: CrossAxisAlignment.start,
309+
children: _buildRows(),
310+
),
311+
),
312+
),
313+
),
314+
);
315+
}
316+
281317
List<Widget> _buildRows() {
282318
final List<Widget> rows = [];
283319

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_constants.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:appflowy/util/theme_extension.dart';
33
import 'package:appflowy_backend/log.dart';
44
import 'package:appflowy_editor/appflowy_editor.dart';
55
import 'package:flutter/material.dart';
6+
import 'package:universal_platform/universal_platform.dart';
67

78
const enableTableDebugLog = false;
89

@@ -166,10 +167,16 @@ class SimpleTableConstants {
166167
static const addColumnAndRowButtonBottomPadding = 2.5 * addRowButtonPadding;
167168

168169
// Table cell
169-
static const cellEdgePadding = EdgeInsets.symmetric(
170-
horizontal: 9.0,
171-
vertical: 2.0,
172-
);
170+
static EdgeInsets get cellEdgePadding => UniversalPlatform.isDesktop
171+
? const EdgeInsets.symmetric(
172+
horizontal: 9.0,
173+
vertical: 2.0,
174+
)
175+
: const EdgeInsets.only(
176+
left: 8.0,
177+
right: 8.0,
178+
bottom: 6.0,
179+
);
173180
static const cellBorderWidth = 1.0;
174181
static const resizeHandleWidth = 3.0;
175182

0 commit comments

Comments
 (0)