fix: keep search visible on iOS tabs

This commit is contained in:
Tienson Qin
2026-05-21 17:48:09 +08:00
parent 31886f8499
commit 10ccc2c8c2
2 changed files with 20 additions and 5 deletions

View File

@@ -1,12 +1,14 @@
import Foundation
import Capacitor
import SwiftUI
import UIKit
import WebKit
@objc(LiquidTabsPlugin)
public class LiquidTabsPlugin: CAPPlugin, CAPBridgedPlugin {
// So SwiftUI can notify JS
static weak var shared: LiquidTabsPlugin?
private static let maxPhoneContentTabs = 4
private let store = LiquidTabsStore.shared
private var keyboardHackScriptInstalled = false
@@ -28,6 +30,14 @@ public class LiquidTabsPlugin: CAPPlugin, CAPBridgedPlugin {
installKeyboardHackScript()
}
private static func visibleContentTabs(_ tabs: [LiquidTab]) -> [LiquidTab] {
guard UIDevice.current.userInterfaceIdiom == .phone else {
return tabs
}
return Array(tabs.prefix(maxPhoneContentTabs))
}
// MARK: - Methods from JS
/// Configure tabs from JS.
@@ -63,12 +73,13 @@ public class LiquidTabsPlugin: CAPPlugin, CAPBridgedPlugin {
DispatchQueue.main.async {
let selectedId = self.store.selectedId
self.store.tabs = tabs
let visibleTabs = Self.visibleContentTabs(tabs)
self.store.tabs = visibleTabs
if let selectedId = selectedId,
selectedId == "search" || tabs.contains(where: { $0.id == selectedId }) {
selectedId == "search" || visibleTabs.contains(where: { $0.id == selectedId }) {
self.store.selectedId = selectedId
} else {
self.store.selectedId = tabs.first?.id
self.store.selectedId = visibleTabs.first?.id
}
}

View File

@@ -97,7 +97,11 @@
(let [width (.-width js/screen)
height (.-height js/screen)
landscape? (> width height)
[width height] (if landscape? [height width] [width height])]
[width height] (if landscape? [height width] [width height])
fallback-model (if (and (<= 320 width 600)
(<= 568 height 1000))
"iPhone"
"Not a known Apple device!")]
[(case [width height]
;; The following list is from:
;; - https://useyourloaf.com/blog/ipad-2024-screen-sizes/
@@ -121,7 +125,7 @@
[1024 1366] "iPadPro12.9"
[1032 1376] "iPadPro13(M4)"
[834 1210] "iPadPro11(M4)"
"Not a known Apple device!")
fallback-model)
landscape?])))
(defn native-iphone-without-notch?