Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ This is a modified version for my personal use. It is perfectly compatible with
- Optimized for E-Ink displays (untested).
- Added more reading fonts.
- Render Markdown formatting in novel summaries.
- Search for text directly within the reading (chapter) screen.

| | | |
| :-------------------------------------------------------------: | :-------------------------------------------------------: | :------------------------------------------------------------: |
Expand Down
193 changes: 193 additions & 0 deletions patches/react-native-webview@13.16.1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
diff --git a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManagerImpl.kt b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManagerImpl.kt
index f83033b3..d933a258 100644
--- a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManagerImpl.kt
+++ b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManagerImpl.kt
@@ -295,6 +295,9 @@ class RNCWebViewManagerImpl(private val newArch: Boolean = false) {
val COMMAND_CLEAR_FORM_DATA = 1000
val COMMAND_CLEAR_CACHE = 1001
val COMMAND_CLEAR_HISTORY = 1002
+ val COMMAND_FIND_ALL_ASYNC = 1003
+ val COMMAND_FIND_NEXT = 1004
+ val COMMAND_CLEAR_MATCHES = 1005

fun getCommandsMap(): Map<String, Int>? {
return MapBuilder.builder<String, Int>()
@@ -309,6 +312,9 @@ class RNCWebViewManagerImpl(private val newArch: Boolean = false) {
.put("clearFormData", COMMAND_CLEAR_FORM_DATA)
.put("clearCache", COMMAND_CLEAR_CACHE)
.put("clearHistory", COMMAND_CLEAR_HISTORY)
+ .put("findAllAsync", COMMAND_FIND_ALL_ASYNC)
+ .put("findNext", COMMAND_FIND_NEXT)
+ .put("clearMatches", COMMAND_CLEAR_MATCHES)
.build()
}

@@ -351,9 +357,38 @@ class RNCWebViewManagerImpl(private val newArch: Boolean = false) {
webView.clearCache(includeDiskFiles)
}
"clearHistory" -> webView.clearHistory()
+ "findAllAsync" -> args.getString(0)?.let { findAllAsync(viewWrapper, it) }
+ "findNext" -> findNext(viewWrapper, args.getBoolean(0))
+ "clearMatches" -> clearMatches(viewWrapper)
}
}

+ fun findAllAsync(viewWrapper: RNCWebViewWrapper, search: String) {
+ val webView = viewWrapper.webView
+ webView.setFindListener { activeMatchOrdinal, numberOfMatches, isDoneCounting ->
+ val data = JSONObject()
+ .put("query", search)
+ .put("activeMatchOrdinal", activeMatchOrdinal)
+ .put("numberOfMatches", numberOfMatches)
+ .put("isDoneCounting", isDoneCounting)
+ val message = JSONObject()
+ .put("type", "find-result")
+ .put("data", data)
+
+ webView.onMessage(message.toString(), webView.url ?: "")
+ }
+ webView.findAllAsync(search)
+ }
+
+ fun findNext(viewWrapper: RNCWebViewWrapper, forward: Boolean) {
+ viewWrapper.webView.findNext(forward)
+ }
+
+ fun clearMatches(viewWrapper: RNCWebViewWrapper) {
+ viewWrapper.webView.setFindListener(null)
+ viewWrapper.webView.clearMatches()
+ }
+
fun setMixedContentMode(viewWrapper: RNCWebViewWrapper, mixedContentMode: String?) {
val view = viewWrapper.webView
if (mixedContentMode == null || "never" == mixedContentMode) {
diff --git a/android/src/newarch/com/reactnativecommunity/webview/RNCWebViewManager.java b/android/src/newarch/com/reactnativecommunity/webview/RNCWebViewManager.java
index 4709e282..6f39665d 100644
--- a/android/src/newarch/com/reactnativecommunity/webview/RNCWebViewManager.java
+++ b/android/src/newarch/com/reactnativecommunity/webview/RNCWebViewManager.java
@@ -509,6 +509,21 @@ public class RNCWebViewManager extends ViewGroupManager<RNCWebViewWrapper>
view.getWebView().clearHistory();
}

+ @Override
+ public void findAllAsync(RNCWebViewWrapper view, String search) {
+ mRNCWebViewManagerImpl.findAllAsync(view, search);
+ }
+
+ @Override
+ public void findNext(RNCWebViewWrapper view, boolean forward) {
+ mRNCWebViewManagerImpl.findNext(view, forward);
+ }
+
+ @Override
+ public void clearMatches(RNCWebViewWrapper view) {
+ mRNCWebViewManagerImpl.clearMatches(view);
+ }
+
@Override
protected void addEventEmitters(@NonNull ThemedReactContext reactContext, RNCWebViewWrapper view) {
// Do not register default touch emitter and let WebView implementation handle touches
@@ -561,4 +576,4 @@ public class RNCWebViewManager extends ViewGroupManager<RNCWebViewWrapper>
mRNCWebViewManagerImpl.onDropViewInstance(view);
super.onDropViewInstance(view);
}
-}
\ No newline at end of file
+}
diff --git a/index.d.ts b/index.d.ts
index a3eef139..c45ce658 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -58,6 +58,24 @@ declare class WebView<P = {}> extends Component<WebViewProps & P> {
* Tells this WebView to clear its internal back/forward list.
*/
clearHistory?: () => void;
+
+ /**
+ * (Android only)
+ * Finds and highlights all occurrences of the supplied text.
+ */
+ findAllAsync?: (search: string) => void;
+
+ /**
+ * (Android only)
+ * Selects the next or previous native find result.
+ */
+ findNext?: (forward: boolean) => void;
+
+ /**
+ * (Android only)
+ * Clears all native find highlights.
+ */
+ clearMatches?: () => void;
}

export {WebView};
diff --git a/src/RNCWebViewNativeComponent.ts b/src/RNCWebViewNativeComponent.ts
index 7f4e6c4f..148537c1 100644
--- a/src/RNCWebViewNativeComponent.ts
+++ b/src/RNCWebViewNativeComponent.ts
@@ -324,6 +324,17 @@ export interface NativeCommands {
includeDiskFiles: boolean
) => void;
clearHistory: (viewRef: React.ElementRef<HostComponent<NativeProps>>) => void;
+ findAllAsync: (
+ viewRef: React.ElementRef<HostComponent<NativeProps>>,
+ search: string
+ ) => void;
+ findNext: (
+ viewRef: React.ElementRef<HostComponent<NativeProps>>,
+ forward: boolean
+ ) => void;
+ clearMatches: (
+ viewRef: React.ElementRef<HostComponent<NativeProps>>
+ ) => void;
// !Android Only
}

@@ -340,6 +351,9 @@ export const Commands = codegenNativeCommands<NativeCommands>({
'clearFormData',
'clearCache',
'clearHistory',
+ 'findAllAsync',
+ 'findNext',
+ 'clearMatches',
],
});

diff --git a/src/WebView.android.tsx b/src/WebView.android.tsx
index 6497a8b1..5677941c 100644
--- a/src/WebView.android.tsx
+++ b/src/WebView.android.tsx
@@ -182,6 +182,13 @@ const WebViewComponent = forwardRef<{}, AndroidWebViewProps>(
Commands.clearCache(webViewRef.current, includeDiskFiles),
clearHistory: () =>
webViewRef.current && Commands.clearHistory(webViewRef.current),
+ findAllAsync: (search: string) =>
+ webViewRef.current &&
+ Commands.findAllAsync(webViewRef.current, search),
+ findNext: (forward: boolean) =>
+ webViewRef.current && Commands.findNext(webViewRef.current, forward),
+ clearMatches: () =>
+ webViewRef.current && Commands.clearMatches(webViewRef.current),
}),
[setViewState, webViewRef]
);
diff --git a/src/WebViewTypes.ts b/src/WebViewTypes.ts
index eca81415..022acb9e 100644
--- a/src/WebViewTypes.ts
+++ b/src/WebViewTypes.ts
@@ -22,7 +22,12 @@ type WebViewCommands =
| 'requestFocus'
| 'clearCache';

-type AndroidWebViewCommands = 'clearHistory' | 'clearFormData';
+type AndroidWebViewCommands =
+ | 'clearHistory'
+ | 'clearFormData'
+ | 'findAllAsync'
+ | 'findNext'
+ | 'clearMatches';

interface RNCWebViewUIManager<Commands extends string> extends UIManagerStatic {
getViewManagerConfig: (name: string) => {
Loading
Loading