Group iOS code into a single component

This commit is contained in:
Balazs Perlaki-Horvath 2024-07-07 13:37:10 +02:00 committed by Kelson
parent ed4c64ae5c
commit 5ccd145463
3 changed files with 36 additions and 14 deletions

View File

@ -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)
}
}
}

View File

@ -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)
}

View File

@ -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