mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-07-22 19:40:10 +08:00
opt dyn/reply text menu
Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
114
lib/common/widgets/context_menu/dyn_menu_helper.dart
Normal file
114
lib/common/widgets/context_menu/dyn_menu_helper.dart
Normal file
@@ -0,0 +1,114 @@
|
||||
part of 'package:PiliPlus/pages/dynamics/widgets/content_panel.dart';
|
||||
|
||||
Widget dynTextMenuBuilder(
|
||||
EditableTextState state,
|
||||
String text,
|
||||
ModuleDynamicModel? moduleDynamic,
|
||||
) {
|
||||
final buttonItems = state.contextMenuButtonItems
|
||||
..insertOrAdd(
|
||||
3,
|
||||
ContextMenuButtonItem(
|
||||
label: '文本',
|
||||
onPressed: () {
|
||||
state.hideToolbar();
|
||||
_showTextDialog(text);
|
||||
},
|
||||
),
|
||||
)
|
||||
..insertOrAdd(
|
||||
4,
|
||||
ContextMenuButtonItem(
|
||||
label: '表情',
|
||||
onPressed: () {
|
||||
state
|
||||
..hideToolbar()
|
||||
..clearSelectionIfNeeded();
|
||||
_showEmoteDialog(moduleDynamic);
|
||||
},
|
||||
),
|
||||
);
|
||||
return AdaptiveTextSelectionToolbar.buttonItems(
|
||||
buttonItems: buttonItems,
|
||||
anchors: state.contextMenuAnchors,
|
||||
);
|
||||
}
|
||||
|
||||
void _showEmoteDialog(ModuleDynamicModel? moduleDynamic) {
|
||||
if (moduleDynamic == null) return;
|
||||
final richTextNodes =
|
||||
moduleDynamic.desc?.richTextNodes ??
|
||||
moduleDynamic.major?.opus?.summary?.richTextNodes;
|
||||
if (richTextNodes == null || richTextNodes.isEmpty) return;
|
||||
Map<String, Emoji>? emotes;
|
||||
for (final e in richTextNodes) {
|
||||
if (e.type == 'RICH_TEXT_NODE_TYPE_EMOJI') {
|
||||
emotes ??= <String, Emoji>{};
|
||||
if (!emotes.containsKey(e.origText)) {
|
||||
emotes[e.origText!] = e.emoji!;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (emotes == null || emotes.isEmpty) return;
|
||||
showDialog(
|
||||
context: Get.context!,
|
||||
builder: (context) => Dialog(
|
||||
child: Padding(
|
||||
padding: const .symmetric(horizontal: 20, vertical: 16),
|
||||
child: SelectableText.rich(
|
||||
TextSpan(
|
||||
children: emotes!.entries.mapIndexed(
|
||||
(i, e) {
|
||||
final emoji = e.value;
|
||||
final size = emoji.size * 25.0;
|
||||
return TextSpan(
|
||||
children: [
|
||||
if (i != 0) const TextSpan(text: '\n\n'),
|
||||
WidgetSpan(
|
||||
child: NetworkImgLayer(
|
||||
src: emoji.url,
|
||||
type: .emote,
|
||||
width: size,
|
||||
height: size,
|
||||
),
|
||||
),
|
||||
TextSpan(text: '\n${e.key}\n${emoji.url}'),
|
||||
],
|
||||
);
|
||||
},
|
||||
).toList(),
|
||||
),
|
||||
contextMenuBuilder: openUrlMenuBuilder,
|
||||
style: const TextStyle(fontSize: 15, height: 1.7),
|
||||
scrollPhysics: const ClampingScrollPhysicsExt(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showTextDialog(String text) {
|
||||
showDialog(
|
||||
context: Get.context!,
|
||||
builder: (context) => Dialog(
|
||||
child: Padding(
|
||||
padding: const .symmetric(horizontal: 20, vertical: 16),
|
||||
child: SelectableText(
|
||||
text,
|
||||
contextMenuBuilder: openUrlMenuBuilder,
|
||||
style: const TextStyle(fontSize: 15, height: 1.7),
|
||||
scrollPhysics: const ClampingScrollPhysicsExt(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget openUrlMenuBuilder(_, EditableTextState state) {
|
||||
final buttonItems = state.contextMenuButtonItems;
|
||||
state.addLaunchMenuIfNeeded(buttonItems, index: 3);
|
||||
return AdaptiveTextSelectionToolbar.buttonItems(
|
||||
buttonItems: buttonItems,
|
||||
anchors: state.contextMenuAnchors,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user