Skip to content

Commit

Permalink
refactor(neon_rich_text): Separate building rich object from text spa…
Browse files Browse the repository at this point in the history
…n rendering

Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin committed Nov 28, 2024
1 parent 98c102f commit 4f486d7
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
export 'src/rich_objects/deck_card.dart';
export 'src/rich_objects/fallback.dart';
export 'src/rich_objects/file.dart';
export 'src/rich_objects/mention.dart';
export 'src/rich_objects/rich_objects.dart' hide buildRichObjectParameter;
export 'src/rich_text.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'package:flutter/widgets.dart';
import 'package:meta/meta.dart';
import 'package:neon_rich_text/src/rich_objects/deck_card.dart';
import 'package:neon_rich_text/src/rich_objects/fallback.dart';
import 'package:neon_rich_text/src/rich_objects/file.dart';
import 'package:neon_rich_text/src/rich_objects/mention.dart';
import 'package:nextcloud/core.dart' as core;

export 'deck_card.dart';
export 'fallback.dart';
export 'file.dart';
export 'mention.dart';

/// Renders a rich object [parameter] to be interactive.
@internal
InlineSpan buildRichObjectParameter({
required core.RichObjectParameter parameter,
required TextStyle? textStyle,
required bool isPreview,
}) {
if (isPreview) {
return TextSpan(
text: parameter.name,
style: textStyle,
);
}

return WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: switch (parameter.type) {
core.RichObjectParameter_Type.user ||
core.RichObjectParameter_Type.call ||
core.RichObjectParameter_Type.guest ||
core.RichObjectParameter_Type.userGroup =>
NeonRichObjectMention(
parameter: parameter,
textStyle: textStyle,
),
core.RichObjectParameter_Type.file => NeonRichObjectFile(
parameter: parameter,
textStyle: textStyle,
),
core.RichObjectParameter_Type.deckCard => NeonRichObjectDeckCard(
parameter: parameter,
),
_ => NeonRichObjectFallback(
parameter: parameter,
textStyle: textStyle,
),
},
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import 'package:built_value/json_object.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/widgets.dart';
import 'package:intersperse/intersperse.dart';
import 'package:neon_rich_text/src/rich_objects/deck_card.dart';
import 'package:neon_rich_text/src/rich_objects/fallback.dart';
import 'package:neon_rich_text/src/rich_objects/file.dart';
import 'package:neon_rich_text/src/rich_objects/mention.dart';
import 'package:neon_rich_text/src/rich_objects/rich_objects.dart';
import 'package:nextcloud/core.dart' as core;

/// Renders the [text] as a rich [TextSpan].
Expand Down Expand Up @@ -127,42 +124,3 @@ TextSpan buildRichTextSpan({
children: children,
);
}

/// Renders a rich object [parameter] to be interactive.
InlineSpan buildRichObjectParameter({
required core.RichObjectParameter parameter,
required TextStyle? textStyle,
required bool isPreview,
}) {
if (isPreview) {
return TextSpan(
text: parameter.name,
style: textStyle,
);
}

return WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: switch (parameter.type) {
core.RichObjectParameter_Type.user ||
core.RichObjectParameter_Type.call ||
core.RichObjectParameter_Type.guest ||
core.RichObjectParameter_Type.userGroup =>
NeonRichObjectMention(
parameter: parameter,
textStyle: textStyle,
),
core.RichObjectParameter_Type.file => NeonRichObjectFile(
parameter: parameter,
textStyle: textStyle,
),
core.RichObjectParameter_Type.deckCard => NeonRichObjectDeckCard(
parameter: parameter,
),
_ => NeonRichObjectFallback(
parameter: parameter,
textStyle: textStyle,
),
},
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies:
sdk: flutter
flutter_material_design_icons: ^1.1.7296
intersperse: ^2.0.0
meta: ^1.0.0
neon_framework:
git:
url: https://github.com/nextcloud/neon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:neon_framework/testing.dart';
import 'package:neon_framework/theme.dart';
import 'package:neon_framework/utils.dart';
import 'package:neon_framework/widgets.dart';
import 'package:neon_rich_text/src/rich_objects/rich_objects.dart';
import 'package:nextcloud/core.dart' as core;
import 'package:provider/provider.dart';
import 'package:rxdart/rxdart.dart';
Expand Down

0 comments on commit 4f486d7

Please sign in to comment.