From 5ccd145463831cb45bfffcd3d9bbe7b0e5de8c00 Mon Sep 17 00:00:00 2001 From: Balazs Perlaki-Horvath Date: Sun, 7 Jul 2024 13:37:10 +0200 Subject: [PATCH] Group iOS code into a single component --- App/CompactViewController.swift | 8 +---- Views/BrowserTab.swift | 8 +---- .../BuildingBlocks/ContentSearchButton.swift | 34 +++++++++++++++++++ 3 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 Views/BuildingBlocks/ContentSearchButton.swift diff --git a/App/CompactViewController.swift b/App/CompactViewController.swift index 3a801393..3a7472df 100644 --- a/App/CompactViewController.swift +++ b/App/CompactViewController.swift @@ -212,13 +212,7 @@ private struct Content: View { systemImage: "die.face.5", action: { browser.loadRandomArticle() }) .disabled(zimFiles.isEmpty) - Button("common.search".localized, - systemImage: "text.magnifyingglass", - action: { - browser.webView.isFindInteractionEnabled = true - browser.webView.findInteraction?.presentFindNavigator(showingReplace: false) - } - ).disabled(browser.webView.url == nil) + ContentSearchButton(webView: browser.webView) } } } diff --git a/Views/BrowserTab.swift b/Views/BrowserTab.swift index 98e6f8a4..e268ea51 100644 --- a/Views/BrowserTab.swift +++ b/Views/BrowserTab.swift @@ -43,13 +43,7 @@ struct BrowserTab: View { #endif BookmarkButton() #if os(iOS) - Button("common.search".localized, - systemImage: "text.magnifyingglass", - action: { - browser.webView.isFindInteractionEnabled = true - browser.webView.findInteraction?.presentFindNavigator(showingReplace: false) - } - ).disabled(browser.webView.url == nil) + ContentSearchButton(webView: browser.webView) #endif ArticleShortcutButtons(displayMode: .mainAndRandomArticle) } diff --git a/Views/BuildingBlocks/ContentSearchButton.swift b/Views/BuildingBlocks/ContentSearchButton.swift new file mode 100644 index 00000000..be0aee7d --- /dev/null +++ b/Views/BuildingBlocks/ContentSearchButton.swift @@ -0,0 +1,34 @@ +// This file is part of Kiwix for iOS & macOS. +// +// Kiwix is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// any later version. +// +// Kiwix is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Kiwix; If not, see https://www.gnu.org/licenses/. + +#if os(iOS) +import SwiftUI +import WebKit + +struct ContentSearchButton: View { + + let webView: WKWebView + + var body: some View { + Button("common.search".localized, + systemImage: "text.magnifyingglass", + action: { + webView.isFindInteractionEnabled = true + webView.findInteraction?.presentFindNavigator(showingReplace: false) + } + ).disabled(webView.url == nil) + } +} +#endif