[ios] Fix hang on launch in certain conditions related to the main buttons

Signed-off-by: Yannik Bloscheck <git@yannikbloscheck.com>
This commit is contained in:
Yannik Bloscheck
2025-09-30 02:36:29 +02:00
committed by Yannik Bloscheck
parent 8520f32f2d
commit db6ad05406
7 changed files with 35 additions and 84 deletions

View File

@@ -89,11 +89,9 @@ NSArray<UIImage *> *imagesWithName(NSString *name) {
auto const fitInAvailableArea = CGRectGetMaxY(self.view.frame) < CGRectGetMaxY(availableArea) + kTopOffset; auto const fitInAvailableArea = CGRectGetMaxY(self.view.frame) < CGRectGetMaxY(availableArea) + kTopOffset;
auto const shouldHide = self.hidden || !fitInAvailableArea; auto const shouldHide = self.hidden || !fitInAvailableArea;
auto const leftOffset = shouldHide ? -self.view.width : availableArea.origin.x + kViewControlsOffsetToBounds; auto const leftOffset = shouldHide ? -self.view.width : availableArea.origin.x + kViewControlsOffsetToBounds;
[self.view.superview animateConstraintsWithAnimations:^{ self.topOffset.constant = availableArea.origin.y + kTopOffset;
self.topOffset.constant = availableArea.origin.y + kTopOffset; self.leftOffset.constant = leftOffset;
self.leftOffset.constant = leftOffset; self.view.alpha = shouldHide ? 0 : 1;
self.view.alpha = shouldHide ? 0 : 1;
}];
}); });
} }

View File

@@ -39,7 +39,7 @@ extension Settings {
case .addPlace: case .addPlace:
return UIImage(systemName: "plus", withConfiguration: configuration)! return UIImage(systemName: "plus", withConfiguration: configuration)!
case .recordTrack: case .recordTrack:
return UIImage.MainButtons.LeftButton.recordTrack.withConfiguration(configuration) return UIImage(systemName: "record.circle", withConfiguration: configuration)!
case .settings: case .settings:
return UIImage(systemName: "gearshape.fill", withConfiguration: UIImage.SymbolConfiguration(pointSize: 22, weight: .semibold))! return UIImage(systemName: "gearshape.fill", withConfiguration: UIImage.SymbolConfiguration(pointSize: 22, weight: .semibold))!
case .help: case .help:

View File

@@ -24,9 +24,6 @@ class BottomTabBarButtonRenderer {
if let coloring = style.coloring { if let coloring = style.coloring {
control.coloring = coloring control.coloring = coloring
} }
if let imageName = style.mwmImage {
control.imageName = imageName
}
if let backgroundColor = style.backgroundColor { if let backgroundColor = style.backgroundColor {
control.backgroundColor = backgroundColor control.backgroundColor = backgroundColor
} }

View File

@@ -1,7 +1,6 @@
protocol BottomTabBarInteractorProtocol: AnyObject { protocol BottomTabBarInteractorProtocol: AnyObject {
func openSearch() func openSearch()
func openLeftButton() func openLeftButton()
func openFaq()
func openBookmarks() func openBookmarks()
func openMenu() func openMenu()
} }
@@ -55,10 +54,6 @@ extension BottomTabBarInteractor: BottomTabBarInteractorProtocol {
} }
} }
func openFaq() {
mapViewController?.openAbout()
}
func openBookmarks() { func openBookmarks() {
mapViewController?.bookmarksCoordinator.open() mapViewController?.bookmarksCoordinator.open()
} }

View File

@@ -1,7 +1,7 @@
protocol BottomTabBarPresenterProtocol: AnyObject { protocol BottomTabBarPresenterProtocol: AnyObject {
func configure() func configure()
func onLeftButtonPressed()
func onSearchButtonPressed() func onSearchButtonPressed()
func onLeftButtonPressed(withBadge: Bool)
func onBookmarksButtonPressed() func onBookmarksButtonPressed()
func onMenuButtonPressed() func onMenuButtonPressed()
} }
@@ -18,12 +18,12 @@ extension BottomTabBarPresenter: BottomTabBarPresenterProtocol {
func configure() { func configure() {
} }
func onSearchButtonPressed() { func onLeftButtonPressed() {
interactor.openSearch() interactor.openLeftButton()
} }
func onLeftButtonPressed(withBadge: Bool) { func onSearchButtonPressed() {
withBadge ? interactor.openFaq() : interactor.openLeftButton() interactor.openSearch()
} }
func onBookmarksButtonPressed() { func onBookmarksButtonPressed() {

View File

@@ -1,19 +1,16 @@
private let kUDDidShowFirstTimeRoutingEducationalHint = "kUDDidShowFirstTimeRoutingEducationalHint"
class BottomTabBarViewController: UIViewController { class BottomTabBarViewController: UIViewController {
var presenter: BottomTabBarPresenterProtocol! var presenter: BottomTabBarPresenterProtocol!
@IBOutlet var searchButton: MWMButton! @IBOutlet var leftButton: MWMButton?
@IBOutlet var searchConstraintWithLeftButton: NSLayoutConstraint! @IBOutlet var searchButton: MWMButton?
@IBOutlet var searchConstraintWithoutLeftButton: NSLayoutConstraint! @IBOutlet var searchConstraintWithLeftButton: NSLayoutConstraint?
@IBOutlet var leftButton: MWMButton! @IBOutlet var searchConstraintWithoutLeftButton: NSLayoutConstraint?
@IBOutlet var bookmarksButton: MWMButton! @IBOutlet var bookmarksButton: MWMButton?
@IBOutlet var bookmarksConstraintWithLeftButton: NSLayoutConstraint! @IBOutlet var bookmarksConstraintWithLeftButton: NSLayoutConstraint?
@IBOutlet var bookmarksConstraintWithoutLeftButton: NSLayoutConstraint! @IBOutlet var bookmarksConstraintWithoutLeftButton: NSLayoutConstraint?
@IBOutlet var moreButton: MWMButton! @IBOutlet var moreButton: MWMButton?
@IBOutlet var downloadBadge: UIView! @IBOutlet var downloadBadge: UIView?
@IBOutlet var leftButtonBadge: UIView!
private var avaliableArea = CGRect.zero private var avaliableArea = CGRect.zero
@objc var isHidden: Bool = false { @objc var isHidden: Bool = false {
@@ -47,7 +44,7 @@ class BottomTabBarViewController: UIViewController {
override func viewWillAppear(_ animated: Bool) { override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated) super.viewWillAppear(animated)
leftButton.imageView?.contentMode = .scaleAspectFit leftButton?.imageView?.contentMode = .scaleAspectFit
updateBadge() updateBadge()
} }
@@ -65,12 +62,7 @@ class BottomTabBarViewController: UIViewController {
} }
@IBAction func onLeftButtonPressed(_ sender: Any) { @IBAction func onLeftButtonPressed(_ sender: Any) {
if !leftButtonBadge.isHidden { presenter.onLeftButtonPressed()
presenter.onLeftButtonPressed(withBadge: true)
setLeftButtonBadgeShown()
} else {
presenter.onLeftButtonPressed(withBadge: false)
}
} }
@IBAction func onBookmarksButtonPressed(_ sender: Any) { @IBAction func onBookmarksButtonPressed(_ sender: Any) {
@@ -113,41 +105,27 @@ class BottomTabBarViewController: UIViewController {
private func updateLeftButton() { private func updateLeftButton() {
let leftButtonType = Settings.leftButtonType let leftButtonType = Settings.leftButtonType
if leftButtonType == .hidden { if leftButtonType == .hidden {
leftButton.isHidden = true leftButton?.isHidden = true
leftButtonBadge.isHidden = true
if let searchConstraintWithLeftButton, let searchConstraintWithoutLeftButton, let bookmarksConstraintWithLeftButton, let bookmarksConstraintWithoutLeftButton { if let searchConstraintWithLeftButton, let searchConstraintWithoutLeftButton, let bookmarksConstraintWithLeftButton, let bookmarksConstraintWithoutLeftButton {
NSLayoutConstraint.deactivate([searchConstraintWithLeftButton, bookmarksConstraintWithLeftButton])
NSLayoutConstraint.activate([searchConstraintWithoutLeftButton, bookmarksConstraintWithoutLeftButton]) NSLayoutConstraint.activate([searchConstraintWithoutLeftButton, bookmarksConstraintWithoutLeftButton])
NSLayoutConstraint.deactivate([searchConstraintWithLeftButton, bookmarksConstraintWithLeftButton])
} }
} else { } else {
leftButton.isHidden = false leftButton?.isHidden = false
leftButtonBadge.isHidden = !needsToShowleftButtonBadge()
leftButton.setTitle(nil, for: .normal) leftButton?.setTitle(nil, for: .normal)
leftButton.setImage(leftButtonType.image, for: .normal) leftButton?.setImage(leftButtonType.image, for: .normal)
leftButton.accessibilityLabel = leftButtonType.description; leftButton?.accessibilityLabel = leftButtonType.description;
if let searchConstraintWithLeftButton, let searchConstraintWithoutLeftButton, let bookmarksConstraintWithLeftButton, let bookmarksConstraintWithoutLeftButton { if let searchConstraintWithLeftButton, let searchConstraintWithoutLeftButton, let bookmarksConstraintWithLeftButton, let bookmarksConstraintWithoutLeftButton {
NSLayoutConstraint.deactivate([searchConstraintWithoutLeftButton, bookmarksConstraintWithoutLeftButton])
NSLayoutConstraint.activate([searchConstraintWithLeftButton, bookmarksConstraintWithLeftButton]) NSLayoutConstraint.activate([searchConstraintWithLeftButton, bookmarksConstraintWithLeftButton])
NSLayoutConstraint.deactivate([searchConstraintWithoutLeftButton, bookmarksConstraintWithoutLeftButton])
} }
} }
} }
private func updateBadge() { private func updateBadge() {
downloadBadge.isHidden = isApplicationBadgeHidden downloadBadge?.isHidden = isApplicationBadgeHidden
leftButtonBadge.isHidden = !needsToShowleftButtonBadge() || Settings.leftButtonType == .hidden
}
}
// MARK: - Help badge
private extension BottomTabBarViewController {
private func needsToShowleftButtonBadge() -> Bool {
!UserDefaults.standard.bool(forKey: kUDDidShowFirstTimeRoutingEducationalHint)
}
private func setLeftButtonBadgeShown() {
UserDefaults.standard.set(true, forKey: kUDDidShowFirstTimeRoutingEducationalHint)
} }
} }

View File

@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="23727" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="24128" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/> <device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="23721"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="24063"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/> <capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
@@ -15,7 +15,6 @@
<outlet property="bookmarksConstraintWithoutLeftButton" destination="NRb-vj-MFg" id="C3Z-Ia-D6i"/> <outlet property="bookmarksConstraintWithoutLeftButton" destination="NRb-vj-MFg" id="C3Z-Ia-D6i"/>
<outlet property="downloadBadge" destination="uDI-ZC-4wx" id="fAf-cy-Ozn"/> <outlet property="downloadBadge" destination="uDI-ZC-4wx" id="fAf-cy-Ozn"/>
<outlet property="leftButton" destination="dzf-7Z-N6a" id="LMZ-H7-ftQ"/> <outlet property="leftButton" destination="dzf-7Z-N6a" id="LMZ-H7-ftQ"/>
<outlet property="leftButtonBadge" destination="0pe-0n-d1F" id="tmx-0P-tch"/>
<outlet property="moreButton" destination="svD-yi-GrZ" id="kjk-ZW-nZN"/> <outlet property="moreButton" destination="svD-yi-GrZ" id="kjk-ZW-nZN"/>
<outlet property="searchButton" destination="No0-ld-JX3" id="m5F-UT-j94"/> <outlet property="searchButton" destination="No0-ld-JX3" id="m5F-UT-j94"/>
<outlet property="searchConstraintWithLeftButton" destination="tDb-w1-ueQ" id="WaI-Xb-1bu"/> <outlet property="searchConstraintWithLeftButton" destination="tDb-w1-ueQ" id="WaI-Xb-1bu"/>
@@ -39,7 +38,7 @@
</constraints> </constraints>
<fontDescription key="fontDescription" type="system" pointSize="30"/> <fontDescription key="fontDescription" type="system" pointSize="30"/>
<inset key="imageEdgeInsets" minX="9" minY="9" maxX="9" maxY="9"/> <inset key="imageEdgeInsets" minX="9" minY="9" maxX="9" maxY="9"/>
<state key="normal" image="Logo"/> <state key="normal" image="info.circle" catalog="system"/>
<connections> <connections>
<action selector="onLeftButtonPressed:" destination="-1" eventType="touchUpInside" id="1gx-P2-sRJ"/> <action selector="onLeftButtonPressed:" destination="-1" eventType="touchUpInside" id="1gx-P2-sRJ"/>
</connections> </connections>
@@ -94,37 +93,21 @@
<userDefinedRuntimeAttribute type="string" keyPath="styleName" value="Badge"/> <userDefinedRuntimeAttribute type="string" keyPath="styleName" value="Badge"/>
</userDefinedRuntimeAttributes> </userDefinedRuntimeAttributes>
</view> </view>
<view userInteractionEnabled="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="0pe-0n-d1F" userLabel="LeftButtonBadge">
<rect key="frame" x="49.5" y="11" width="10" height="10"/>
<color key="backgroundColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<accessibility key="accessibilityConfiguration">
<accessibilityTraits key="traits" notEnabled="YES"/>
</accessibility>
<constraints>
<constraint firstAttribute="height" constant="10" id="FgD-lk-SxR"/>
<constraint firstAttribute="width" constant="10" id="OwT-jV-hqZ"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="styleName" value="Badge"/>
</userDefinedRuntimeAttributes>
</view>
</subviews> </subviews>
<accessibility key="accessibilityConfiguration" identifier="MainButtons"/> <accessibility key="accessibilityConfiguration" identifier="MainButtons"/>
<constraints> <constraints>
<constraint firstAttribute="height" constant="48" id="69A-eu-uLp"/> <constraint firstAttribute="height" constant="48" id="69A-eu-uLp"/>
<constraint firstItem="No0-ld-JX3" firstAttribute="centerY" secondItem="vum-s3-PHx" secondAttribute="centerY" id="8nL-zT-Y7b"/> <constraint firstItem="No0-ld-JX3" firstAttribute="centerY" secondItem="vum-s3-PHx" secondAttribute="centerY" id="8nL-zT-Y7b"/>
<constraint firstItem="No0-ld-JX3" firstAttribute="height" secondItem="vum-s3-PHx" secondAttribute="height" id="9eR-I7-7at"/> <constraint firstItem="No0-ld-JX3" firstAttribute="height" secondItem="vum-s3-PHx" secondAttribute="height" id="9eR-I7-7at"/>
<constraint firstItem="0pe-0n-d1F" firstAttribute="centerX" secondItem="dzf-7Z-N6a" secondAttribute="centerX" constant="8" id="Ab0-g9-N4P"/>
<constraint firstItem="svD-yi-GrZ" firstAttribute="height" secondItem="vum-s3-PHx" secondAttribute="height" id="Fde-um-JL6"/> <constraint firstItem="svD-yi-GrZ" firstAttribute="height" secondItem="vum-s3-PHx" secondAttribute="height" id="Fde-um-JL6"/>
<constraint firstItem="dgG-ki-3tB" firstAttribute="centerX" secondItem="vum-s3-PHx" secondAttribute="centerX" multiplier="1.25" id="Jc7-nc-elY"/> <constraint firstItem="dgG-ki-3tB" firstAttribute="centerX" secondItem="vum-s3-PHx" secondAttribute="centerX" multiplier="1.25" id="Jc7-nc-elY"/>
<constraint firstItem="dgG-ki-3tB" firstAttribute="centerY" secondItem="vum-s3-PHx" secondAttribute="centerY" id="JjT-sc-hIY"/> <constraint firstItem="dgG-ki-3tB" firstAttribute="centerY" secondItem="vum-s3-PHx" secondAttribute="centerY" id="JjT-sc-hIY"/>
<constraint firstItem="dgG-ki-3tB" firstAttribute="centerX" secondItem="vum-s3-PHx" secondAttribute="centerX" id="NRb-vj-MFg"/> <constraint firstItem="dgG-ki-3tB" firstAttribute="centerX" secondItem="vum-s3-PHx" secondAttribute="centerX" priority="900" id="NRb-vj-MFg"/>
<constraint firstItem="svD-yi-GrZ" firstAttribute="centerX" secondItem="vum-s3-PHx" secondAttribute="centerX" multiplier="1.75" id="Q0b-gd-HwS"/> <constraint firstItem="svD-yi-GrZ" firstAttribute="centerX" secondItem="vum-s3-PHx" secondAttribute="centerX" multiplier="1.75" id="Q0b-gd-HwS"/>
<constraint firstItem="dgG-ki-3tB" firstAttribute="height" secondItem="vum-s3-PHx" secondAttribute="height" id="Rs8-Hl-CAc"/> <constraint firstItem="dgG-ki-3tB" firstAttribute="height" secondItem="vum-s3-PHx" secondAttribute="height" id="Rs8-Hl-CAc"/>
<constraint firstItem="uDI-ZC-4wx" firstAttribute="centerX" secondItem="svD-yi-GrZ" secondAttribute="centerX" constant="8" id="XNb-Ba-Hn7"/> <constraint firstItem="uDI-ZC-4wx" firstAttribute="centerX" secondItem="svD-yi-GrZ" secondAttribute="centerX" constant="8" id="XNb-Ba-Hn7"/>
<constraint firstItem="dzf-7Z-N6a" firstAttribute="centerY" secondItem="vum-s3-PHx" secondAttribute="centerY" id="Zug-zY-KIX"/> <constraint firstItem="dzf-7Z-N6a" firstAttribute="centerY" secondItem="vum-s3-PHx" secondAttribute="centerY" id="Zug-zY-KIX"/>
<constraint firstItem="No0-ld-JX3" firstAttribute="centerX" secondItem="vum-s3-PHx" secondAttribute="centerX" multiplier="0.25" id="cQg-jW-uSD"/> <constraint firstItem="No0-ld-JX3" firstAttribute="centerX" secondItem="vum-s3-PHx" secondAttribute="centerX" multiplier="0.25" priority="900" id="cQg-jW-uSD"/>
<constraint firstItem="0pe-0n-d1F" firstAttribute="centerY" secondItem="dzf-7Z-N6a" secondAttribute="centerY" constant="-8" id="pgw-rN-LCe"/>
<constraint firstItem="svD-yi-GrZ" firstAttribute="centerY" secondItem="vum-s3-PHx" secondAttribute="centerY" id="sja-hO-YY3"/> <constraint firstItem="svD-yi-GrZ" firstAttribute="centerY" secondItem="vum-s3-PHx" secondAttribute="centerY" id="sja-hO-YY3"/>
<constraint firstItem="No0-ld-JX3" firstAttribute="centerX" secondItem="vum-s3-PHx" secondAttribute="centerX" multiplier="0.75" id="tDb-w1-ueQ"/> <constraint firstItem="No0-ld-JX3" firstAttribute="centerX" secondItem="vum-s3-PHx" secondAttribute="centerX" multiplier="0.75" id="tDb-w1-ueQ"/>
<constraint firstItem="dzf-7Z-N6a" firstAttribute="centerX" secondItem="vum-s3-PHx" secondAttribute="centerX" multiplier="0.25" id="u3G-gY-98J"/> <constraint firstItem="dzf-7Z-N6a" firstAttribute="centerX" secondItem="vum-s3-PHx" secondAttribute="centerX" multiplier="0.25" id="u3G-gY-98J"/>
@@ -157,9 +140,9 @@
</view> </view>
</objects> </objects>
<resources> <resources>
<image name="Logo" width="1024" height="1024"/>
<image name="ic_menu" width="48" height="48"/> <image name="ic_menu" width="48" height="48"/>
<image name="ic_menu_bookmark_list" width="48" height="48"/> <image name="ic_menu_bookmark_list" width="48" height="48"/>
<image name="ic_menu_search" width="48" height="48"/> <image name="ic_menu_search" width="48" height="48"/>
<image name="info.circle" catalog="system" width="128" height="123"/>
</resources> </resources>
</document> </document>