iosWebViewFix/lib/src/find_interaction/find_interaction_controller...

145 lines
8.1 KiB
Dart
Raw Normal View History

2023-11-17 22:28:11 +00:00
import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart';
2022-10-08 12:19:35 +00:00
///**Supported Platforms/Implementations**:
///- Android native WebView
///- iOS
///- MacOS
2023-11-17 22:28:11 +00:00
class FindInteractionController {
FindInteractionController(
{void Function(PlatformFindInteractionController controller,
int activeMatchOrdinal, int numberOfMatches, bool isDoneCounting)?
onFindResultReceived})
: this.fromPlatformCreationParams(
params: PlatformFindInteractionControllerCreationParams(
onFindResultReceived: onFindResultReceived));
/// Constructs a [FindInteractionController].
2022-10-08 12:19:35 +00:00
///
2023-11-17 22:28:11 +00:00
/// See [FindInteractionController.fromPlatformCreationParams] for setting parameters for
/// a specific platform.
FindInteractionController.fromPlatformCreationParams({
required PlatformFindInteractionControllerCreationParams params,
}) : this.fromPlatform(platform: PlatformFindInteractionController(params));
/// Constructs a [FindInteractionController] from a specific platform implementation.
FindInteractionController.fromPlatform({required this.platform});
/// Implementation of [PlatformFindInteractionController] for the current platform.
final PlatformFindInteractionController platform;
///{@macro flutter_inappwebview_platform_interface.PlatformFindInteractionController.onFindResultReceived}
void Function(PlatformFindInteractionController controller,
int activeMatchOrdinal, int numberOfMatches, bool isDoneCounting)?
get onFindResultReceived => platform.onFindResultReceived;
2022-10-08 12:19:35 +00:00
///Finds all instances of find on the page and highlights them. Notifies [FindInteractionController.onFindResultReceived] listener.
///
///[find] represents the string to find.
///
///**NOTE**: on Android native WebView, it finds all instances asynchronously. Successive calls to this will cancel any pending searches.
///
///**NOTE**: on iOS, if [InAppWebViewSettings.isFindInteractionEnabled] is `true`,
///it uses the built-in find interaction native UI,
///otherwise this is implemented using CSS and Javascript.
///
///**Supported Platforms/Implementations**:
///- Android native WebView ([Official API - WebView.findAllAsync](https://developer.android.com/reference/android/webkit/WebView#findAllAsync(java.lang.String)))
///- iOS (if [InAppWebViewSettings.isFindInteractionEnabled] is `true`: [Official API - UIFindInteraction.presentFindNavigator](https://developer.apple.com/documentation/uikit/uifindinteraction/3975832-presentfindnavigator?changes=_2) with [Official API - UIFindInteraction.searchText](https://developer.apple.com/documentation/uikit/uifindinteraction/3975834-searchtext?changes=_2))
///- MacOS
2023-11-17 22:28:11 +00:00
Future<void> findAll({String? find}) => platform.findAll(find: find);
2022-10-08 12:19:35 +00:00
2022-10-12 08:27:58 +00:00
///Highlights and scrolls to the next match found by [findAll]. Notifies [FindInteractionController.onFindResultReceived] listener.
2022-10-08 12:19:35 +00:00
///
///[forward] represents the direction to search. The default value is `true`, meaning forward.
2022-10-08 12:19:35 +00:00
///
///**NOTE**: on iOS, if [InAppWebViewSettings.isFindInteractionEnabled] is `true`,
///it uses the built-in find interaction native UI,
///otherwise this is implemented using CSS and Javascript.
///
///**Supported Platforms/Implementations**:
///- Android native WebView ([Official API - WebView.findNext](https://developer.android.com/reference/android/webkit/WebView#findNext(boolean)))
///- iOS (if [InAppWebViewSettings.isFindInteractionEnabled] is `true`: [Official API - UIFindInteraction.findNext](https://developer.apple.com/documentation/uikit/uifindinteraction/3975829-findnext?changes=_2) and ([Official API - UIFindInteraction.findPrevious](https://developer.apple.com/documentation/uikit/uifindinteraction/3975830-findprevious?changes=_2)))
///- MacOS
2023-11-17 22:28:11 +00:00
Future<void> findNext({bool forward = true}) =>
platform.findNext(forward: forward);
2022-10-08 12:19:35 +00:00
2022-10-12 08:27:58 +00:00
///Clears the highlighting surrounding text matches created by [findAll].
2022-10-08 12:19:35 +00:00
///
///**NOTE**: on iOS, if [InAppWebViewSettings.isFindInteractionEnabled] is `true`,
///it uses the built-in find interaction native UI,
///otherwise this is implemented using CSS and Javascript.
///
///**Supported Platforms/Implementations**:
///- Android native WebView ([Official API - WebView.clearMatches](https://developer.android.com/reference/android/webkit/WebView#clearMatches()))
///- iOS (if [InAppWebViewSettings.isFindInteractionEnabled] is `true`: [Official API - UIFindInteraction.dismissFindNavigator](https://developer.apple.com/documentation/uikit/uifindinteraction/3975827-dismissfindnavigator?changes=_2))
///- MacOS
2023-11-17 22:28:11 +00:00
Future<void> clearMatches() => platform.clearMatches();
2022-10-08 12:19:35 +00:00
///Pre-populate the search text to be used.
2022-10-08 12:19:35 +00:00
///
///On iOS, if [InAppWebViewSettings.isFindInteractionEnabled] is `true,
///it will pre-populate the system find panel's search text field with a search query.
2022-10-08 12:19:35 +00:00
///
///**Supported Platforms/Implementations**:
///- Android native WebView
2022-10-08 12:19:35 +00:00
///- iOS ([Official API - UIFindInteraction.searchText](https://developer.apple.com/documentation/uikit/uifindinteraction/3975834-searchtext?changes=_2))
///- MacOS
2023-11-17 22:28:11 +00:00
Future<void> setSearchText(String? searchText) =>
platform.setSearchText(searchText);
2022-10-08 12:19:35 +00:00
///Get the search text used.
2022-10-08 12:19:35 +00:00
///
///On iOS, if [InAppWebViewSettings.isFindInteractionEnabled] is `true,
///it will get the system find panel's search text field value.
2022-10-08 12:19:35 +00:00
///
///**Supported Platforms/Implementations**:
///- Android native WebView
2022-10-08 12:19:35 +00:00
///- iOS ([Official API - UIFindInteraction.searchText](https://developer.apple.com/documentation/uikit/uifindinteraction/3975834-searchtext?changes=_2))
///- MacOS
2023-11-17 22:28:11 +00:00
Future<String?> getSearchText() => platform.getSearchText();
2022-10-08 12:19:35 +00:00
///A Boolean value that indicates when the find panel displays onscreen.
///
///**NOTE**: available only on iOS and only if [InAppWebViewSettings.isFindInteractionEnabled] is `true`.
///
///**Supported Platforms/Implementations**:
///- iOS ([Official API - UIFindInteraction.isFindNavigatorVisible](https://developer.apple.com/documentation/uikit/uifindinteraction/3975828-isfindnavigatorvisible?changes=_2))
2023-11-17 22:28:11 +00:00
Future<bool?> isFindNavigatorVisible() => platform.isFindNavigatorVisible();
2022-10-08 12:19:35 +00:00
///Updates the results the interface displays for the active search.
///
///**NOTE**: available only on iOS and only if [InAppWebViewSettings.isFindInteractionEnabled] is `true`.
///
///**Supported Platforms/Implementations**:
///- iOS ([Official API - UIFindInteraction.updateResultCount](https://developer.apple.com/documentation/uikit/uifindinteraction/3975835-updateresultcount?changes=_2))
2023-11-17 22:28:11 +00:00
Future<void> updateResultCount() => platform.updateResultCount();
2022-10-08 12:19:35 +00:00
///Begins a search, displaying the find panel.
///
///**NOTE**: available only on iOS and only if [InAppWebViewSettings.isFindInteractionEnabled] is `true`.
///
///**Supported Platforms/Implementations**:
///- iOS ([Official API - UIFindInteraction.presentFindNavigator](https://developer.apple.com/documentation/uikit/uifindinteraction/3975832-presentfindnavigator?changes=_2))
2023-11-17 22:28:11 +00:00
Future<void> presentFindNavigator() => platform.presentFindNavigator();
2022-10-08 12:19:35 +00:00
///Dismisses the find panel, if present.
///
///**NOTE**: available only on iOS and only if [InAppWebViewSettings.isFindInteractionEnabled] is `true`.
///
///**Supported Platforms/Implementations**:
///- iOS ([Official API - UIFindInteraction.dismissFindNavigator](https://developer.apple.com/documentation/uikit/uifindinteraction/3975827-dismissfindnavigator?changes=_2))
2023-11-17 22:28:11 +00:00
Future<void> dismissFindNavigator() => platform.dismissFindNavigator();
2022-10-08 12:19:35 +00:00
///If there's a currently active find session, returns the active find session.
2022-10-08 12:19:35 +00:00
///
///**Supported Platforms/Implementations**:
2022-10-12 08:13:05 +00:00
///- Android native WebView
2022-10-08 12:19:35 +00:00
///- iOS ([Official API - UIFindInteraction.activeFindSession](https://developer.apple.com/documentation/uikit/uifindinteraction/3975825-activefindsession?changes=_7____4_8&language=objc))
///- MacOS
2023-11-17 22:28:11 +00:00
Future<FindSession?> getActiveFindSession() =>
platform.getActiveFindSession();
///Disposes the controller.
2023-11-17 22:28:11 +00:00
void dispose({bool isKeepAlive = false}) => platform.dispose();
}