implemented selection api
This commit is contained in:
+61
@@ -0,0 +1,61 @@
|
||||
import 'package:flutter_mozilla_components/src/pigeons/gecko.g.dart';
|
||||
|
||||
typedef PerformAction = void Function(String selectedText);
|
||||
|
||||
class BaseSelectionAction extends CustomSelectionAction {
|
||||
final PerformAction performAction;
|
||||
|
||||
BaseSelectionAction({
|
||||
required super.id,
|
||||
required super.title,
|
||||
required this.performAction,
|
||||
super.pattern,
|
||||
});
|
||||
}
|
||||
|
||||
class CallAction extends BaseSelectionAction {
|
||||
CallAction(PerformAction action)
|
||||
: super(
|
||||
id: 'CUSTOM_CONTEXT_MENU_CALL',
|
||||
title: 'Call',
|
||||
pattern: SelectionPattern.phone,
|
||||
performAction: action,
|
||||
);
|
||||
}
|
||||
|
||||
class EmailAction extends BaseSelectionAction {
|
||||
EmailAction(PerformAction action)
|
||||
: super(
|
||||
id: 'CUSTOM_CONTEXT_MENU_EMAIL',
|
||||
title: 'Email',
|
||||
pattern: SelectionPattern.email,
|
||||
performAction: action,
|
||||
);
|
||||
}
|
||||
|
||||
class SearchAction extends BaseSelectionAction {
|
||||
SearchAction(PerformAction action)
|
||||
: super(
|
||||
id: 'CUSTOM_CONTEXT_MENU_SEARCH',
|
||||
title: 'Search',
|
||||
performAction: action,
|
||||
);
|
||||
}
|
||||
|
||||
class PrivateSearchAction extends BaseSelectionAction {
|
||||
PrivateSearchAction(PerformAction action)
|
||||
: super(
|
||||
id: 'CUSTOM_CONTEXT_MENU_SEARCH_PRIVATELY',
|
||||
title: 'Private Search',
|
||||
performAction: action,
|
||||
);
|
||||
}
|
||||
|
||||
class ShareAction extends BaseSelectionAction {
|
||||
ShareAction(PerformAction action)
|
||||
: super(
|
||||
id: 'CUSTOM_CONTEXT_MENU_SHARE',
|
||||
title: 'Share',
|
||||
performAction: action,
|
||||
);
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_mozilla_components/src/domain/entities/default_selection_actions.dart';
|
||||
import 'package:flutter_mozilla_components/src/pigeons/gecko.g.dart';
|
||||
|
||||
final _apiInstance = GeckoSelectionActionController();
|
||||
|
||||
class GeckoSelectionActionService extends GeckoSelectionActionEvents {
|
||||
final GeckoSelectionActionController _api;
|
||||
|
||||
List<BaseSelectionAction> _actions;
|
||||
|
||||
List<BaseSelectionAction> get actions => _actions;
|
||||
|
||||
Future<void> setActions(List<BaseSelectionAction> value) async {
|
||||
_actions = value;
|
||||
await _api.setActions(actions);
|
||||
}
|
||||
|
||||
GeckoSelectionActionService.setUp({
|
||||
BinaryMessenger? binaryMessenger,
|
||||
String messageChannelSuffix = '',
|
||||
GeckoSelectionActionController? api,
|
||||
}) : _api = api ?? _apiInstance,
|
||||
_actions = [] {
|
||||
GeckoSelectionActionEvents.setUp(
|
||||
this,
|
||||
binaryMessenger: binaryMessenger,
|
||||
messageChannelSuffix: messageChannelSuffix,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void performSelectionAction(String id, String selectedText) {
|
||||
_actions.firstWhere((x) => x.id == id).performAction(selectedText);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user