Improve smaller tabbar on touch-id devices

This commit is contained in:
Kylmakalle 2025-04-20 13:57:05 +03:00
parent b472ac0ff5
commit d1295c341b
5 changed files with 49 additions and 9 deletions

View File

@ -0,0 +1,9 @@
filegroup(
name = "SGTabBarHeightModifier",
srcs = glob([
"Sources/**/*.swift",
]),
visibility = [
"//visibility:public",
],
)

View File

@ -0,0 +1,26 @@
import Foundation
import Display
public func sgTabBarHeightModifier(showTabNames: Bool, tabBarHeight: CGFloat, layout: ContainerViewLayout, defaultBarSmaller: Bool) -> CGFloat {
var tabBarHeight = tabBarHeight
guard !showTabNames else {
return tabBarHeight
}
if defaultBarSmaller {
tabBarHeight -= 6.0
} else {
tabBarHeight -= 12.0
}
if layout.intrinsicInsets.bottom.isZero {
// Devices with home button need a bit more space
if defaultBarSmaller {
tabBarHeight += 3.0
} else {
tabBarHeight += 6.0
}
}
return tabBarHeight
}

View File

@ -1,13 +1,17 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
sgdeps = [
"//Swiftgram/SGSimpleSettings:SGSimpleSettings"
"//Swiftgram/SGSimpleSettings:SGSimpleSettings",
]
sgsrc = [
"//Swiftgram/SGTabBarHeightModifier:SGTabBarHeightModifier"
]
swift_library(
name = "TabBarUI",
module_name = "TabBarUI",
srcs = glob([
srcs = sgsrc + glob([
"Sources/**/*.swift",
]),
copts = [

View File

@ -105,10 +105,10 @@ final class TabBarControllerNode: ASDisplayNode {
let bottomInset: CGFloat = layout.insets(options: options).bottom
if !layout.safeInsets.left.isZero {
tabBarHeight = 34.0 + bottomInset
if !self.showTabNames { tabBarHeight -= 6.0 } // MARK: Swiftgram
tabBarHeight = sgTabBarHeightModifier(showTabNames: self.showTabNames, tabBarHeight: tabBarHeight, layout: layout, defaultBarSmaller: true) // MARK: Swiftgram
} else {
tabBarHeight = 49.0 + bottomInset
if !self.showTabNames { tabBarHeight -= 12.0 } // MARK: Swiftgram
tabBarHeight = sgTabBarHeightModifier(showTabNames: self.showTabNames, tabBarHeight: tabBarHeight, layout: layout, defaultBarSmaller: false) // MARK: Swiftgram
}
let tabBarFrame = CGRect(origin: CGPoint(x: 0.0, y: layout.size.height - (self.tabBarHidden ? 0.0 : tabBarHeight)), size: CGSize(width: layout.size.width, height: tabBarHeight))

View File

@ -269,10 +269,11 @@ open class TabBarControllerImpl: ViewController, TabBarController {
let bottomInset: CGFloat = validLayout.insets(options: options).bottom
if !validLayout.safeInsets.left.isZero {
tabBarHeight = 34.0 + bottomInset
tabBarHeight = sgTabBarHeightModifier(showTabNames: strongSelf.showTabNames, tabBarHeight: tabBarHeight, layout: validLayout, defaultBarSmaller: true) // MARK: Swiftgram
} else {
tabBarHeight = 49.0 + bottomInset
tabBarHeight = sgTabBarHeightModifier(showTabNames: strongSelf.showTabNames, tabBarHeight: tabBarHeight, layout: validLayout, defaultBarSmaller: false) // MARK: Swiftgram
}
if !strongSelf.showTabNames { tabBarHeight -= 12.0 } // MARK: Swiftgram
updatedLayout.intrinsicInsets.bottom = tabBarHeight
strongSelf.controllers[index].containerLayoutUpdated(updatedLayout, transition: .immediate)
@ -449,10 +450,10 @@ open class TabBarControllerImpl: ViewController, TabBarController {
let bottomInset: CGFloat = updatedLayout.insets(options: options).bottom
if !updatedLayout.safeInsets.left.isZero {
tabBarHeight = 34.0 + bottomInset
if !self.showTabNames { tabBarHeight -= 6.0 } // MARK: Swiftgram
tabBarHeight = sgTabBarHeightModifier(showTabNames: self.showTabNames, tabBarHeight: tabBarHeight, layout: layout, defaultBarSmaller: true) // MARK: Swiftgram
} else {
tabBarHeight = 49.0 + bottomInset
if !self.showTabNames { tabBarHeight -= 12.0 } // MARK: Swiftgram
tabBarHeight = sgTabBarHeightModifier(showTabNames: self.showTabNames, tabBarHeight: tabBarHeight, layout: layout, defaultBarSmaller: false) // MARK: Swiftgram
}
if !self.tabBarControllerNode.tabBarHidden {
updatedLayout.intrinsicInsets.bottom = tabBarHeight
@ -480,10 +481,10 @@ open class TabBarControllerImpl: ViewController, TabBarController {
let bottomInset: CGFloat = updatedLayout.insets(options: options).bottom
if !updatedLayout.safeInsets.left.isZero {
tabBarHeight = 34.0 + bottomInset
if !self.showTabNames { tabBarHeight -= 6.0 } // MARK: Swiftgram
tabBarHeight = sgTabBarHeightModifier(showTabNames: self.showTabNames, tabBarHeight: tabBarHeight, layout: layout, defaultBarSmaller: true) // MARK: Swiftgram
} else {
tabBarHeight = 49.0 + bottomInset
if !self.showTabNames { tabBarHeight -= 12.0 } // MARK: Swiftgram
tabBarHeight = sgTabBarHeightModifier(showTabNames: self.showTabNames, tabBarHeight: tabBarHeight, layout: layout, defaultBarSmaller: false) // MARK: Swiftgram
}
if !self.tabBarControllerNode.tabBarHidden {
updatedLayout.intrinsicInsets.bottom = tabBarHeight