Files
comaps/iphone/Maps/Classes/CustomViews/MapViewControls/SideButtons/MWMSideButtons.mm
Kiryl Kaveryn 103d660603 [ios] refactor Toast class and improve toast message style
1. update style: bigger fonts and insets
2. update background blur
3. get rid of MWM prefix
4. replace the timer with the simplier dispatch async after. In this case there is no needed to create a timer for each toasts message just to add a timeout
5. reorder Toast class methods
6. replace the instance `show` method with a `static show`. Because there non needed to call show every time. We do not have stored toast that will be showed in different places thane created.
Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>

Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
2025-05-19 10:52:42 +02:00

150 lines
3.8 KiB
Plaintext

#import "MWMSideButtons.h"
#import "MWMButton.h"
#import "MWMLocationManager.h"
#import "MWMMapViewControlsManager.h"
#import "MWMRouter.h"
#import "MWMSettings.h"
#import "MWMSideButtonsView.h"
#import "SwiftBridge.h"
#include <CoreApi/Framework.h>
namespace
{
NSString * const kMWMSideButtonsViewNibName = @"MWMSideButtonsView";
NSString * const kUDDidShowLongTapToShowSideButtonsToast = @"kUDDidShowLongTapToShowSideButtonsToast";
} // namespace
@interface MWMMapViewControlsManager ()
@property(nonatomic) MWMSideButtons * sideButtons;
@end
@interface MWMSideButtons ()
@property(nonatomic) IBOutlet MWMSideButtonsView * sideView;
@property(weak, nonatomic) IBOutlet MWMButton * zoomInButton;
@property(weak, nonatomic) IBOutlet MWMButton * zoomOutButton;
@property(weak, nonatomic) IBOutlet MWMButton * locationButton;
@property(nonatomic) BOOL zoomSwipeEnabled;
@property(nonatomic, readonly) BOOL isZoomEnabled;
@property(nonatomic) MWMMyPositionMode locationMode;
@end
@implementation MWMSideButtons
- (UIView *)view {
return self.sideView;
}
+ (MWMSideButtons *)buttons { return [MWMMapViewControlsManager manager].sideButtons; }
- (instancetype)initWithParentView:(UIView *)view
{
self = [super init];
if (self)
{
[NSBundle.mainBundle loadNibNamed:kMWMSideButtonsViewNibName owner:self options:nil];
[view addSubview:self.sideView];
[self.sideView setNeedsLayout];
self.zoomSwipeEnabled = NO;
self.zoomHidden = NO;
}
return self;
}
+ (void)updateAvailableArea:(CGRect)frame { [[self buttons].sideView updateAvailableArea:frame]; }
- (void)zoomIn
{
GetFramework().Scale(Framework::SCALE_MAG, true);
}
- (void)zoomOut
{
GetFramework().Scale(Framework::SCALE_MIN, true);
}
- (void)processMyPositionStateModeEvent:(MWMMyPositionMode)mode
{
[self refreshLocationButtonState:mode];
self.locationMode = mode;
}
#pragma mark - Location button
- (void)refreshLocationButtonState:(MWMMyPositionMode)state
{
MWMButton * locBtn = self.locationButton;
[locBtn.imageView stopRotation];
switch (state)
{
case MWMMyPositionModePendingPosition:
{
[locBtn setStyleNameAndApply: @"ButtonPending"];
[locBtn.imageView startRotation:1];
break;
}
case MWMMyPositionModeNotFollow:
case MWMMyPositionModeNotFollowNoPosition: [locBtn setStyleNameAndApply: @"ButtonGetPosition"]; break;
case MWMMyPositionModeFollow: [locBtn setStyleNameAndApply: @"ButtonFollow"]; break;
case MWMMyPositionModeFollowAndRotate: [locBtn setStyleNameAndApply: @"ButtonFollowAndRotate"]; break;
}
}
#pragma mark - Actions
- (IBAction)zoomTouchDown:(UIButton *)sender { self.zoomSwipeEnabled = YES; }
- (IBAction)zoomTouchUpInside:(UIButton *)sender
{
self.zoomSwipeEnabled = NO;
if ([sender isEqual:self.zoomInButton])
[self zoomIn];
else
[self zoomOut];
}
- (IBAction)zoomTouchUpOutside:(UIButton *)sender { self.zoomSwipeEnabled = NO; }
- (IBAction)zoomSwipe:(UIPanGestureRecognizer *)sender
{
if (!self.zoomSwipeEnabled)
return;
UIView * const superview = self.sideView.superview;
CGFloat const translation =
-[sender translationInView:superview].y / superview.bounds.size.height;
CGFloat const scaleFactor = exp(translation);
GetFramework().Scale(scaleFactor, false);
}
- (IBAction)locationTouchUpInside
{
[MWMLocationManager enableLocationAlert];
GetFramework().SwitchMyPositionNextMode();
}
#pragma mark - Properties
- (BOOL)zoomHidden { return self.sideView.zoomHidden; }
- (void)setZoomHidden:(BOOL)zoomHidden
{
if ([MWMRouter isRoutingActive])
self.sideView.zoomHidden = NO;
else
self.sideView.zoomHidden = [MWMSettings zoomButtonsEnabled] ? zoomHidden : YES;
}
- (BOOL)hidden { return self.sideView.hidden; }
- (void)setHidden:(BOOL)hidden
{
if (!self.hidden && hidden)
[Toast showWithText:L(@"long_tap_toast")];
return [self.sideView setHidden:hidden animated:YES];
}
@end