added FindSession to Android
This commit is contained in:
parent
b790039696
commit
b4558d356a
@ -4,6 +4,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.pichillilorenzo.flutter_inappwebview.types.ChannelDelegateImpl;
|
||||
import com.pichillilorenzo.flutter_inappwebview.types.FindSession;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -43,6 +44,13 @@ public class FindInteractionChannelDelegate extends ChannelDelegateImpl {
|
||||
}
|
||||
result.success(true);
|
||||
break;
|
||||
case "getActiveFindSession":
|
||||
if (findInteractionController != null && findInteractionController.activeFindSession != null) {
|
||||
result.success(findInteractionController.activeFindSession.toMap());
|
||||
} else {
|
||||
result.success(null);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
result.notImplemented();
|
||||
}
|
||||
@ -51,6 +59,11 @@ public class FindInteractionChannelDelegate extends ChannelDelegateImpl {
|
||||
public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches, boolean isDoneCounting) {
|
||||
MethodChannel channel = getChannel();
|
||||
if (channel == null) return;
|
||||
|
||||
if (isDoneCounting && findInteractionController != null && findInteractionController.webView != null) {
|
||||
findInteractionController.activeFindSession = new FindSession(numberOfMatches, activeMatchOrdinal);
|
||||
}
|
||||
|
||||
Map<String, Object> obj = new HashMap<>();
|
||||
obj.put("activeMatchOrdinal", activeMatchOrdinal);
|
||||
obj.put("numberOfMatches", numberOfMatches);
|
||||
|
@ -5,6 +5,7 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import com.pichillilorenzo.flutter_inappwebview.InAppWebViewFlutterPlugin;
|
||||
import com.pichillilorenzo.flutter_inappwebview.types.Disposable;
|
||||
import com.pichillilorenzo.flutter_inappwebview.types.FindSession;
|
||||
import com.pichillilorenzo.flutter_inappwebview.webview.InAppWebViewInterface;
|
||||
|
||||
import io.flutter.plugin.common.MethodChannel;
|
||||
@ -16,6 +17,8 @@ public class FindInteractionController implements Disposable {
|
||||
@Nullable
|
||||
public InAppWebViewInterface webView;
|
||||
@Nullable
|
||||
public FindSession activeFindSession;
|
||||
@Nullable
|
||||
public FindInteractionChannelDelegate channelDelegate;
|
||||
@Nullable
|
||||
public FindInteractionSettings settings;
|
||||
@ -38,5 +41,6 @@ public class FindInteractionController implements Disposable {
|
||||
channelDelegate = null;
|
||||
}
|
||||
webView = null;
|
||||
activeFindSession = null;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,76 @@
|
||||
package com.pichillilorenzo.flutter_inappwebview.types;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class FindSession {
|
||||
private int resultCount;
|
||||
private int highlightedResultIndex;
|
||||
private int searchResultDisplayStyle = 2; // matches NONE of iOS
|
||||
|
||||
public FindSession(int resultCount, int highlightedResultIndex) {
|
||||
this.resultCount = resultCount;
|
||||
this.highlightedResultIndex = highlightedResultIndex;
|
||||
}
|
||||
|
||||
public Map<String, Object> toMap() {
|
||||
Map<String, Object> obj = new HashMap<>();
|
||||
obj.put("resultCount", resultCount);
|
||||
obj.put("highlightedResultIndex", highlightedResultIndex);
|
||||
obj.put("searchResultDisplayStyle", searchResultDisplayStyle);
|
||||
return obj;
|
||||
}
|
||||
|
||||
public int getResultCount() {
|
||||
return resultCount;
|
||||
}
|
||||
|
||||
public void setResultCount(int resultCount) {
|
||||
this.resultCount = resultCount;
|
||||
}
|
||||
|
||||
public int getHighlightedResultIndex() {
|
||||
return highlightedResultIndex;
|
||||
}
|
||||
|
||||
public void setHighlightedResultIndex(int highlightedResultIndex) {
|
||||
this.highlightedResultIndex = highlightedResultIndex;
|
||||
}
|
||||
|
||||
public int getSearchResultDisplayStyle() {
|
||||
return searchResultDisplayStyle;
|
||||
}
|
||||
|
||||
public void setSearchResultDisplayStyle(int searchResultDisplayStyle) {
|
||||
this.searchResultDisplayStyle = searchResultDisplayStyle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
FindSession that = (FindSession) o;
|
||||
|
||||
if (resultCount != that.resultCount) return false;
|
||||
if (highlightedResultIndex != that.highlightedResultIndex) return false;
|
||||
return searchResultDisplayStyle == that.searchResultDisplayStyle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = resultCount;
|
||||
result = 31 * result + highlightedResultIndex;
|
||||
result = 31 * result + searchResultDisplayStyle;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FindSession{" +
|
||||
"resultCount=" + resultCount +
|
||||
", highlightedResultIndex=" + highlightedResultIndex +
|
||||
", searchResultDisplayStyle=" + searchResultDisplayStyle +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -50,9 +50,12 @@ void findInteractions() {
|
||||
if ([TargetPlatform.iOS, TargetPlatform.macOS]
|
||||
.contains(defaultTargetPlatform)) {
|
||||
expect(await findInteractionController.getSearchText(), firstSearchText);
|
||||
final session = await findInteractionController.getActiveFindSession();
|
||||
expect(session!.resultCount, 2);
|
||||
}
|
||||
if ([TargetPlatform.android].contains(defaultTargetPlatform)) {
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
}
|
||||
final session = await findInteractionController.getActiveFindSession();
|
||||
expect(session!.resultCount, 2);
|
||||
await expectLater(
|
||||
findInteractionController.findNext(forward: true), completes);
|
||||
await expectLater(
|
||||
|
@ -3,12 +3,11 @@
|
||||
export "FLUTTER_ROOT=/Users/lorenzopichilli/fvm/versions/2.10.4"
|
||||
export "FLUTTER_APPLICATION_PATH=/Users/lorenzopichilli/Desktop/flutter_inappwebview/example"
|
||||
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
|
||||
export "FLUTTER_TARGET=/Users/lorenzopichilli/Desktop/flutter_inappwebview/example/lib/main.dart"
|
||||
export "FLUTTER_TARGET=lib/main.dart"
|
||||
export "FLUTTER_BUILD_DIR=build"
|
||||
export "FLUTTER_BUILD_NAME=1.0.0"
|
||||
export "FLUTTER_BUILD_NUMBER=1"
|
||||
export "DART_DEFINES=Zmx1dHRlci5pbnNwZWN0b3Iuc3RydWN0dXJlZEVycm9ycz10cnVl,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ=="
|
||||
export "DART_OBFUSCATION=false"
|
||||
export "TRACK_WIDGET_CREATION=true"
|
||||
export "TREE_SHAKE_ICONS=false"
|
||||
export "PACKAGE_CONFIG=/Users/lorenzopichilli/Desktop/flutter_inappwebview/example/.dart_tool/package_config.json"
|
||||
export "PACKAGE_CONFIG=.dart_tool/package_config.json"
|
||||
|
@ -210,11 +210,12 @@ class FindInteractionController {
|
||||
await _channel?.invokeMethod('dismissFindNavigator', args);
|
||||
}
|
||||
|
||||
///If there's a currently active find session (implying [isFindNavigatorVisible] is `true`), returns the active find session.
|
||||
///If there's a currently active find session (on iOS, implying [isFindNavigatorVisible] is `true`), returns the active find session.
|
||||
///
|
||||
///**NOTE**: available only on iOS and only if [InAppWebViewSettings.isFindInteractionEnabled] is `true`.
|
||||
///**NOTE**: available on iOS only if [InAppWebViewSettings.isFindInteractionEnabled] is `true`.
|
||||
///
|
||||
///**Supported Platforms/Implementations**:
|
||||
///- Android native WebView
|
||||
///- iOS ([Official API - UIFindInteraction.activeFindSession](https://developer.apple.com/documentation/uikit/uifindinteraction/3975825-activefindsession?changes=_7____4_8&language=objc))
|
||||
Future<FindSession?> getActiveFindSession() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
|
Loading…
x
Reference in New Issue
Block a user