WIP: Modes

Signed-off-by: Yannik Bloscheck <git@yannikbloscheck.com>
This commit is contained in:
Yannik Bloscheck
2026-01-19 21:43:39 +01:00
parent fd581002fc
commit f8ddfb8dce
289 changed files with 2700 additions and 6487 deletions

View File

@@ -0,0 +1,11 @@
#import "MWMViewController.h"
@interface MWMModeButtonViewController : MWMViewController
+ (MWMModeButtonViewController *)controller;
@property(nonatomic) BOOL hidden;
+ (void)updateAvailableArea:(CGRect)frame;
@end

View File

@@ -0,0 +1,133 @@
#import "MWMModeButtonViewController.h"
#import <CoreApi/MWMMapOverlayManager.h>
#import "MWMAlertViewController.h"
#import "MWMButton.h"
#import "MWMMapViewControlsCommon.h"
#import "MWMMapViewControlsManager.h"
#import "MapViewController.h"
#import "SwiftBridge.h"
#import "base/assert.hpp"
namespace {
CGFloat const kTopOffset = 6;
} // namespace
@interface MWMMapViewControlsManager ()
@property(nonatomic) MWMModeButtonViewController *modeButton;
@end
@interface MWMModeButtonViewController () <MWMMapOverlayManagerObserver, ThemeListener>
@property(nonatomic) NSLayoutConstraint *topOffset;
@property(nonatomic) NSLayoutConstraint *leftOffset;
@property(nonatomic) CGRect availableArea;
@end
@implementation MWMModeButtonViewController
+ (MWMModeButtonViewController *)controller {
return [MWMMapViewControlsManager manager].modeButton;
}
- (instancetype)init {
self = [super init];
if (self) {
MapViewController *ovc = [MapViewController sharedController];
[ovc addChildViewController:self];
[ovc.controlsView addSubview:self.view];
[self configLayout];
[self applyTheme];
[StyleManager.shared addListener:self];
[MWMMapOverlayManager addObserver:self];
}
return self;
}
- (void)dealloc {
[StyleManager.shared removeListener:self];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[Toast hideAll];
}
- (void)configLayout {
UIView *sv = self.view;
UIView *ov = sv.superview;
self.topOffset = [sv.topAnchor constraintEqualToAnchor:ov.topAnchor constant:kTopOffset];
self.topOffset.active = YES;
self.leftOffset = [sv.leadingAnchor constraintEqualToAnchor:ov.leadingAnchor constant:kViewControlsOffsetToBounds];
self.leftOffset.active = YES;
}
- (void)setHidden:(BOOL)hidden {
_hidden = hidden;
[self refreshLayout];
}
- (void)refreshLayout {
dispatch_async(dispatch_get_main_queue(), ^{
auto const availableArea = self.availableArea;
auto const fitInAvailableArea = CGRectGetMaxY(self.view.frame) < CGRectGetMaxY(availableArea) + kTopOffset;
auto const shouldHide = self.hidden || !fitInAvailableArea;
auto const leftOffset = shouldHide ? -self.view.width : availableArea.origin.x + kViewControlsOffsetToBounds;
self.topOffset.constant = availableArea.origin.y + kTopOffset;
self.leftOffset.constant = leftOffset;
self.view.alpha = shouldHide ? 0 : 1;
});
}
- (void)applyTheme {
UIButton *btn = static_cast<UIButton *>(self.view);
NSString * postfix = [UIColor isNightMode] ? @"dark" : @"light";
[btn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_%@", @"btn_bg", postfix]] forState:UIControlStateNormal];
[btn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted_%@", @"btn_bg", postfix]] forState:UIControlStateHighlighted];
[btn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_%@", @"btn_bg", postfix]] forState:UIControlStateSelected];
NSString *imageName = @"map";
switch ([MWMMapOverlayManager mapMode]) {
case MWMMapModeHiking:
imageName = @"hiking";
break;
case MWMMapModeCycling:
imageName = @"cycling";
break;
case MWMMapModeDriving:
imageName = @"driving";
break;
case MWMMapModePublicTransport:
imageName = @"publictransport";
break;
default:
break;
}
[btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
btn.tintColor = [UIColor iconOpaqueGrayTint];
}
- (IBAction)buttonTouchUpInside {
MWMMapViewControlsManager.manager.menuState = MWMBottomMenuStateLayers;
}
+ (void)updateAvailableArea:(CGRect)frame {
auto controller = [self controller];
if (CGRectEqualToRect(controller.availableArea, frame))
return;
controller.availableArea = frame;
[controller refreshLayout];
}
#pragma mark - MWMMapOverlayManagerObserver
- (void)onMapModeUpdated {
[self applyTheme];
}
@end

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="24506" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="24504"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="MWMModeButtonViewController">
<connections>
<outlet property="view" destination="WVx-0E-RoH" id="0Ev-19-Sxq"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="WVx-0E-RoH" propertyAccessControl="all">
<rect key="frame" x="0.0" y="0.0" width="56" height="56"/>
<viewLayoutGuide key="safeArea" id="iUc-A7-STp"/>
<accessibility key="accessibilityConfiguration" identifier="layers_button"/>
<constraints>
<constraint firstAttribute="height" constant="56" id="24f-V4-Vuf"/>
<constraint firstAttribute="width" constant="56" id="hko-xz-hRz"/>
</constraints>
<connections>
<action selector="buttonTouchUpInside" destination="-1" eventType="touchUpInside" id="fKZ-g8-4ML"/>
</connections>
<point key="canvasLocation" x="0.0" y="0.0"/>
</button>
</objects>
</document>