1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
|
#import "MWMBottomMenuView.h"
#import "EAGLView.h"
#import "MWMAvailableAreaAffectDirection.h"
#import "MWMBottomMenuViewController.h"
#import "MWMButton.h"
#import "MWMCommon.h"
#import "MWMRouter.h"
#import "MWMSideButtons.h"
#import "MapsAppDelegate.h"
#import "UIButton+RuntimeAttributes.h"
#import "UIImageView+Coloring.h"
#import "UIView+RuntimeAttributes.h"
#include "Framework.h"
#include "platform/local_country_file_utils.hpp"
namespace
{
CGFloat constexpr kAdditionalHeight = 64;
CGFloat constexpr kDefaultMainButtonsHeight = 48;
CGFloat constexpr kDefaultMenuButtonWidth = 60;
} // namespace
@interface MWMBottomMenuView ()
@property(weak, nonatomic) IBOutlet UICollectionView * additionalButtons;
@property(weak, nonatomic) IBOutlet NSLayoutConstraint * mainButtonsHeight;
@property(weak, nonatomic) IBOutlet NSLayoutConstraint * additionalButtonsHeight;
@property(weak, nonatomic) IBOutlet NSLayoutConstraint * separatorHeight;
@property(weak, nonatomic) IBOutlet UIView * downloadBadge;
@property(weak, nonatomic) IBOutlet MWMButton * searchButton;
@property(weak, nonatomic) IBOutlet MWMButton * menuButton;
@property(weak, nonatomic) IBOutlet NSLayoutConstraint * menuButtonWidth;
@property(nonatomic) IBOutletCollection(NSLayoutConstraint) NSArray * mainButtonConstraintsLeftToRight;
@property(weak, nonatomic) IBOutlet MWMBottomMenuViewController * owner;
@property(nonatomic) CGFloat layoutDuration;
@property(nonatomic) CGRect availableArea;
@end
@implementation MWMBottomMenuView
- (void)awakeFromNib
{
[super awakeFromNib];
self.additionalButtons.hidden = YES;
self.downloadBadge.hidden = YES;
if (isInterfaceRightToLeft())
{
for (NSLayoutConstraint * constraint in self.mainButtonConstraintsLeftToRight)
constraint.priority = UILayoutPriorityFittingSizeLevel;
}
}
- (void)didMoveToSuperview
{
[super didMoveToSuperview];
self.minY = self.superview.height;
self.width = self.superview.width;
}
- (void)layoutSubviews
{
if (self.layoutDuration > 0.0)
{
CGFloat const duration = self.layoutDuration;
self.layoutDuration = 0.0;
if (self.state != MWMBottomMenuStateHidden)
self.hidden = NO;
[self setNeedsLayout];
[UIView animateWithDuration:duration
animations:^{
[self updateAppearance];
[self layoutIfNeeded];
}
completion:^(BOOL finished) {
if (self.state == MWMBottomMenuStateHidden)
self.hidden = YES;
}];
}
[super layoutSubviews];
}
- (void)updateAppearance
{
[self updateAlphaAndColor];
[self updateGeometry];
}
- (void)updateAlphaAndColor
{
switch (self.state)
{
case MWMBottomMenuStateHidden: break;
case MWMBottomMenuStateInactive:
self.backgroundColor = [UIColor menuBackground];
self.downloadBadge.alpha = [self isCompact] ? 0.0 : 1.0;
self.additionalButtons.alpha = 0.0;
break;
case MWMBottomMenuStateActive:
self.backgroundColor = [UIColor white];
self.downloadBadge.alpha = 0.0;
self.additionalButtons.alpha = 1.0;
break;
}
}
- (void)updateGeometry
{
auto const availableArea = self.availableArea;
if (CGRectEqualToRect(availableArea, CGRectZero))
return;
self.separatorHeight.constant = 0.0;
self.additionalButtonsHeight.constant = 0.0;
self.menuButtonWidth.constant = kDefaultMenuButtonWidth;
self.mainButtonsHeight.constant = kDefaultMainButtonsHeight;
switch (self.state)
{
case MWMBottomMenuStateHidden: self.minY = self.superview.height; return;
case MWMBottomMenuStateInactive: break;
case MWMBottomMenuStateActive:
{
self.separatorHeight.constant = 1.0;
BOOL const isLandscape = self.width > self.layoutThreshold;
if (isLandscape)
{
self.additionalButtonsHeight.constant = kAdditionalHeight;
}
else
{
NSUInteger const additionalButtonsCount = [self.additionalButtons numberOfItemsInSection:0];
CGFloat const buttonHeight = 52.0;
self.additionalButtonsHeight.constant = additionalButtonsCount * buttonHeight;
}
}
break;
}
auto const additionalHeight = self.additionalButtonsHeight.constant;
auto const height =
self.mainButtonsHeight.constant + self.separatorHeight.constant + additionalHeight;
self.frame = {{availableArea.origin.x, availableArea.size.height - height},
{availableArea.size.width, height}};
}
- (void)morphMenuButtonTemplate:(NSString *)morphTemplate direct:(BOOL)direct
{
UIButton * btn = self.menuButton;
NSUInteger const morphImagesCount = 6;
NSUInteger const startValue = direct ? 1 : morphImagesCount;
NSUInteger const endValue = direct ? morphImagesCount + 1 : 0;
NSInteger const stepValue = direct ? 1 : -1;
NSMutableArray * morphImages = [NSMutableArray arrayWithCapacity:morphImagesCount];
for (NSUInteger i = startValue, j = 0; i != endValue; i += stepValue, j++)
{
UIImage * image =
[UIImage imageNamed:[NSString stringWithFormat:@"%@%@_%@", morphTemplate, @(i).stringValue,
[UIColor isNightMode] ? @"dark" : @"light"]];
morphImages[j] = image;
}
btn.imageView.animationImages = morphImages;
btn.imageView.animationRepeatCount = 1;
btn.imageView.image = morphImages.lastObject;
[btn.imageView startAnimating];
[self refreshMenuButtonState];
}
- (void)refreshMenuButtonState
{
dispatch_async(dispatch_get_main_queue(), ^{
if (self.menuButton.imageView.isAnimating)
{
[self refreshMenuButtonState];
}
else
{
NSString * name = nil;
switch (self.state)
{
case MWMBottomMenuStateHidden: name = @"ic_menu"; break;
case MWMBottomMenuStateInactive:
name = [self isCompact] ? @"ic_menu_left" : @"ic_menu";
break;
case MWMBottomMenuStateActive: name = @"ic_menu_down"; break;
}
[self.menuButton setImage:[UIImage imageNamed:name] forState:UIControlStateNormal];
}
});
}
- (void)refreshLayout
{
self.layoutDuration = kDefaultAnimationDuration;
[self setNeedsLayout];
}
- (void)updateBadge
{
auto & s = GetFramework().GetStorage();
storage::Storage::UpdateInfo updateInfo{};
s.GetUpdateInfo(s.GetRootId(), updateInfo);
self.downloadBadge.hidden =
(updateInfo.m_numberOfMwmFilesToUpdate == 0) && !platform::migrate::NeedMigrate();
}
#pragma mark - Properties
- (void)setState:(MWMBottomMenuState)state
{
if (_state == state)
return;
BOOL const isActive = (state == MWMBottomMenuStateActive);
self.additionalButtons.hidden = !isActive;
if (_state == MWMBottomMenuStateActive || isActive)
[self morphMenuButtonTemplate:@"ic_menu_" direct:isActive];
_state = state;
[self refreshLayout];
[self updateBadge];
}
- (void)updateAvailableArea:(CGRect)frame
{
if (CGRectEqualToRect(self.availableArea, frame))
return;
BOOL const wasCompact = [self isCompact];
self.availableArea = frame;
BOOL const isCompact = [self isCompact];
if (wasCompact || isCompact)
[self morphMenuButtonTemplate:@"ic_menu_rotate_" direct:isCompact];
[self refreshLayout];
}
- (BOOL)isCompact { return self.availableArea.origin.x > 0; }
#pragma mark - AvailableArea / PlacePageArea
- (MWMAvailableAreaAffectDirections)placePageAreaAffectDirections
{
return IPAD ? MWMAvailableAreaAffectDirectionsBottom : MWMAvailableAreaAffectDirectionsNone;
}
#pragma mark - AvailableArea / WidgetsArea
- (MWMAvailableAreaAffectDirections)widgetsAreaAffectDirections
{
return MWMAvailableAreaAffectDirectionsBottom;
}
#pragma mark - AvailableArea / SideButtonsArea
- (MWMAvailableAreaAffectDirections)sideButtonsAreaAffectDirections
{
return MWMAvailableAreaAffectDirectionsBottom;
}
@end
|