[ios] Removed MWMKeyboard

Signed-off-by: Alexander Borsuk <me@alex.bio>
This commit is contained in:
Alexander Borsuk 2022-02-11 14:32:22 +01:00
parent 3c1b2d1b2c
commit abc1b04481
16 changed files with 10 additions and 278 deletions

View file

@ -39,7 +39,6 @@ final class BookmarksListViewController: MWMViewController {
self?.presenter.toggleVisibility(in: viewModel)
}
presenter.viewDidLoad()
MWMKeyboard.add(self);
}
override func viewDidAppear(_ animated: Bool) {
@ -47,10 +46,6 @@ final class BookmarksListViewController: MWMViewController {
presenter.viewDidAppear()
}
deinit {
MWMKeyboard.remove(self);
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
updateInfoSize()
@ -243,10 +238,3 @@ extension BookmarksListViewController: BookmarksListInfoViewControllerDelegate {
updateInfoSize()
}
}
extension BookmarksListViewController: MWMKeyboardObserver {
func onKeyboardAnimation() {
let keyboardHeight = MWMKeyboard.keyboardHeight();
tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: keyboardHeight, right: 0)
}
}

View file

@ -27,7 +27,6 @@
#import "MWMController.h"
#import "MWMEditorHelper.h"
#import "MWMFrameworkListener.h"
#import "MWMKeyboard.h"
#import "MWMLocationManager.h"
#import "MWMLocationModeListener.h"
#import "MWMMailViewController.h"

View file

@ -39,12 +39,10 @@ final class BCCreateCategoryAlert: MWMAlert {
alert.callback = callback
alert.process(state: .tooFewSymbols)
alert.formatCharactersCountText()
MWMKeyboard.add(alert)
return alert
}
@IBAction private func leftButtonTap() {
MWMKeyboard.remove(self)
close(nil)
}
@ -55,7 +53,6 @@ final class BCCreateCategoryAlert: MWMAlert {
}
if callback(text) {
MWMKeyboard.remove(self)
close(nil)
} else {
process(state: .nameAlreadyExists)
@ -138,14 +135,3 @@ extension BCCreateCategoryAlert: UITextFieldDelegate {
return true
}
}
extension BCCreateCategoryAlert: MWMKeyboardObserver {
func onKeyboardAnimation() {
centerHorizontaly.constant = -MWMKeyboard.keyboardHeight() / 2
layoutIfNeeded()
}
func onKeyboardWillAnimate() {
setNeedsLayout()
}
}

View file

@ -1,7 +1,6 @@
#import "MWMPlaceDoesntExistAlert.h"
#import "MWMKeyboard.h"
@interface MWMPlaceDoesntExistAlert ()<MWMKeyboardObserver>
@interface MWMPlaceDoesntExistAlert()
@property(weak, nonatomic) IBOutlet UITextField * textField;
@property(weak, nonatomic) IBOutlet NSLayoutConstraint * centerHorizontaly;
@ -16,7 +15,6 @@
MWMPlaceDoesntExistAlert * alert =
[NSBundle.mainBundle loadNibNamed:[self className] owner:nil options:nil].firstObject;
alert.block = block;
[MWMKeyboard addObserver:alert];
return alert;
}
@ -34,13 +32,4 @@
[self close:nil];
}
#pragma mark - MWMKeyboard
- (void)onKeyboardAnimation
{
self.centerHorizontaly.constant = -[MWMKeyboard keyboardHeight] / 2;
[self layoutIfNeeded];
}
- (void)onKeyboardWillAnimate { [self setNeedsLayout]; }
@end

View file

@ -67,7 +67,6 @@ NSString *const kPP2BookmarkEditingSegue = @"PP2BookmarkEditing";
@end
@interface MapViewController () <MWMFrameworkDrapeObserver,
MWMKeyboardObserver,
MWMBookmarksObserver>
@property(nonatomic, readwrite) MWMMapViewControlsManager *controlsManager;
@ -320,7 +319,6 @@ NSString *const kPP2BookmarkEditingSegue = @"PP2BookmarkEditing";
[MWMRouter restoreRouteIfNeeded];
self.view.clipsToBounds = YES;
[MWMKeyboard addObserver:self];
if ([FirstSession isFirstSession])
{
@ -608,19 +606,6 @@ NSString *const kPP2BookmarkEditingSegue = @"PP2BookmarkEditing";
}
}
#pragma mark - MWMKeyboard
- (void)onKeyboardWillAnimate {
[self.view setNeedsLayout];
}
- (void)onKeyboardAnimation {
auto const kbHeight = [MWMKeyboard keyboardHeight];
self.sideButtonsAreaKeyboard.constant = kbHeight;
if (IPAD) {
self.visibleAreaKeyboard.constant = kbHeight;
self.placePageAreaKeyboard.constant = kbHeight;
}
}
#pragma mark - Properties
- (MWMMapViewControlsManager *)controlsManager {

View file

@ -224,7 +224,6 @@ using namespace osm_auth_ios;
}
[MWMLocationManager applicationDidBecomeActive];
[MWMSearch addCategoriesToSpotlight];
[MWMKeyboard applicationDidBecomeActive];
[MWMTextToSpeech applicationDidBecomeActive];
LOG(LINFO, ("applicationDidBecomeActive - end"));
}

View file

@ -1,18 +0,0 @@
#import "MWMKeyboardObserver.h"
@interface MWMKeyboard : NSObject
+ (void)applicationDidBecomeActive;
+ (void)addObserver:(id<MWMKeyboardObserver>)observer;
+ (void)removeObserver:(id<MWMKeyboardObserver>)observer;
+ (CGFloat)keyboardHeight;
- (instancetype)init __attribute__((unavailable("call +manager instead")));
- (instancetype)copy __attribute__((unavailable("call +manager instead")));
- (instancetype)copyWithZone:(NSZone *)zone __attribute__((unavailable("call +manager instead")));
+ (instancetype)allocWithZone:(struct _NSZone *)zone __attribute__((unavailable("call +manager instead")));
+ (instancetype)new __attribute__((unavailable("call +manager instead")));
@end

View file

@ -1,98 +0,0 @@
#import "MWMKeyboard.h"
@interface MWMKeyboard ()
@property(nonatomic) NSHashTable *observers;
@property(nonatomic) CGFloat keyboardHeight;
@end
@implementation MWMKeyboard
+ (void)applicationDidBecomeActive {
[self manager];
}
+ (MWMKeyboard *)manager {
static MWMKeyboard *manager;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
manager = [[self alloc] initManager];
});
return manager;
}
- (instancetype)initManager {
self = [super init];
if (self) {
_observers = [NSHashTable weakObjectsHashTable];
NSNotificationCenter *nc = NSNotificationCenter.defaultCenter;
[nc addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[nc addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
return self;
}
- (void)dealloc {
[NSNotificationCenter.defaultCenter removeObserver:self];
}
+ (CGFloat)keyboardHeight {
return [self manager].keyboardHeight;
}
#pragma mark - Add/Remove Observers
+ (void)addObserver:(id<MWMKeyboardObserver>)observer {
[[self manager].observers addObject:observer];
}
+ (void)removeObserver:(id<MWMKeyboardObserver>)observer {
[[self manager].observers removeObject:observer];
}
#pragma mark - Notifications
- (void)onKeyboardWillAnimate {
for (id<MWMKeyboardObserver> observer in self.observers) {
if ([observer respondsToSelector:@selector(onKeyboardWillAnimate)])
[observer onKeyboardWillAnimate];
}
}
- (void)onKeyboardAnimation {
for (id<MWMKeyboardObserver> observer in self.observers) {
[observer onKeyboardAnimation];
}
}
- (void)keyboardWillShow:(NSNotification *)notification {
[self onKeyboardWillAnimate];
CGSize keyboardSize = [notification.userInfo[UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
self.keyboardHeight = MIN(keyboardSize.height, keyboardSize.width);
NSNumber *duration = notification.userInfo[UIKeyboardAnimationDurationUserInfoKey];
NSNumber *curve = notification.userInfo[UIKeyboardAnimationCurveUserInfoKey];
[UIView animateWithDuration:duration.doubleValue
delay:0
options:curve.integerValue
animations:^{
[self onKeyboardAnimation];
}
completion:nil];
}
- (void)keyboardWillHide:(NSNotification *)notification {
[self onKeyboardWillAnimate];
self.keyboardHeight = 0;
NSNumber *duration = notification.userInfo[UIKeyboardAnimationDurationUserInfoKey];
NSNumber *curve = notification.userInfo[UIKeyboardAnimationCurveUserInfoKey];
[UIView animateWithDuration:duration.doubleValue
delay:0
options:curve.integerValue
animations:^{
[self onKeyboardAnimation];
}
completion:nil];
}
@end

View file

@ -1,8 +0,0 @@
@protocol MWMKeyboardObserver<NSObject>
- (void)onKeyboardAnimation;
@optional
- (void)onKeyboardWillAnimate;
@end

View file

@ -17,7 +17,6 @@
337F98B821D3D67E00C8AC27 /* SearchHistoryQueryCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 337F98B721D3D67E00C8AC27 /* SearchHistoryQueryCell.swift */; };
340416481E7BF28E00E2B6D6 /* UIView+Snapshot.swift in Sources */ = {isa = PBXBuildFile; fileRef = 340416461E7BF28E00E2B6D6 /* UIView+Snapshot.swift */; };
3404164C1E7BF42E00E2B6D6 /* UIView+Coordinates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3404164A1E7BF42D00E2B6D6 /* UIView+Coordinates.swift */; };
3404754D1E081A4600C92850 /* MWMKeyboard.m in Sources */ = {isa = PBXBuildFile; fileRef = 340475191E081A4600C92850 /* MWMKeyboard.m */; };
340475591E081A4600C92850 /* WebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 340475271E081A4600C92850 /* WebViewController.m */; };
3404755C1E081A4600C92850 /* MWMLocationManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3404752C1E081A4600C92850 /* MWMLocationManager.mm */; };
3404755F1E081A4600C92850 /* MWMLocationPredictor.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3404752F1E081A4600C92850 /* MWMLocationPredictor.mm */; };
@ -703,9 +702,6 @@
337F98B721D3D67E00C8AC27 /* SearchHistoryQueryCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchHistoryQueryCell.swift; sourceTree = "<group>"; };
340416461E7BF28E00E2B6D6 /* UIView+Snapshot.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+Snapshot.swift"; sourceTree = "<group>"; };
3404164A1E7BF42D00E2B6D6 /* UIView+Coordinates.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+Coordinates.swift"; sourceTree = "<group>"; };
340475181E081A4600C92850 /* MWMKeyboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMKeyboard.h; sourceTree = "<group>"; };
340475191E081A4600C92850 /* MWMKeyboard.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MWMKeyboard.m; sourceTree = "<group>"; };
3404751A1E081A4600C92850 /* MWMKeyboardObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMKeyboardObserver.h; sourceTree = "<group>"; };
3404751C1E081A4600C92850 /* MWMMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMMacros.h; sourceTree = "<group>"; };
340475261E081A4600C92850 /* WebViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebViewController.h; sourceTree = "<group>"; };
340475271E081A4600C92850 /* WebViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebViewController.m; sourceTree = "<group>"; };
@ -1841,7 +1837,6 @@
isa = PBXGroup;
children = (
34845DB51E166084003D55B9 /* Common.swift */,
340475171E081A4600C92850 /* Keyboard */,
3404751C1E081A4600C92850 /* MWMMacros.h */,
340475261E081A4600C92850 /* WebViewController.h */,
340475271E081A4600C92850 /* WebViewController.m */,
@ -1850,16 +1845,6 @@
path = Common;
sourceTree = "<group>";
};
340475171E081A4600C92850 /* Keyboard */ = {
isa = PBXGroup;
children = (
340475181E081A4600C92850 /* MWMKeyboard.h */,
340475191E081A4600C92850 /* MWMKeyboard.m */,
3404751A1E081A4600C92850 /* MWMKeyboardObserver.h */,
);
path = Keyboard;
sourceTree = "<group>";
};
340475281E081A4600C92850 /* Core */ = {
isa = PBXGroup;
children = (
@ -4290,7 +4275,6 @@
993DF0C923F6BD0600AC231A /* ElevationDetailsBuilder.swift in Sources */,
674A7E301C0DB10B003D48E1 /* MWMMapWidgets.mm in Sources */,
34AB66291FC5AA330078E451 /* RouteManagerViewController.swift in Sources */,
3404754D1E081A4600C92850 /* MWMKeyboard.m in Sources */,
993DF10C23F6BDB100AC231A /* MWMTableViewCellRenderer.swift in Sources */,
3457C4261F680F1900028233 /* String+BoundingRect.swift in Sources */,
34EF94291C05A6F30050B714 /* MWMSegue.m in Sources */,

View file

@ -1,7 +1,6 @@
#import "MWMNoMapsView.h"
#import "MWMKeyboard.h"
@interface MWMNoMapsView ()<MWMKeyboardObserver>
@interface MWMNoMapsView ()
@property(weak, nonatomic) IBOutlet UIImageView * image;
@property(weak, nonatomic) IBOutlet UILabel * title;
@ -33,7 +32,6 @@
{
self.containerTopOffset.active = NO;
}
[MWMKeyboard addObserver:self];
}
- (void)layoutSubviews
@ -68,14 +66,4 @@
self.containerHeight.constant = height;
}
}
#pragma mark - MWMKeyboard
- (void)onKeyboardAnimation
{
self.containerBottomOffset.constant = [MWMKeyboard keyboardHeight];
[self.superview layoutIfNeeded];
}
- (void)onKeyboardWillAnimate { [self.superview layoutIfNeeded]; }
@end

View file

@ -1,5 +1,4 @@
#import "MWMCuisineEditorViewController.h"
#import "MWMKeyboard.h"
#import "MWMTableViewCell.h"
#import "SwiftBridge.h"
@ -19,7 +18,7 @@ std::vector<std::string> SliceKeys(std::vector<std::pair<std::string, std::strin
}
} // namespace
@interface MWMCuisineEditorViewController ()<UISearchBarDelegate, MWMKeyboardObserver>
@interface MWMCuisineEditorViewController ()<UISearchBarDelegate>
{
osm::AllCuisines m_allCuisines;
std::vector<std::string> m_selectedCuisines;
@ -42,7 +41,6 @@ std::vector<std::string> SliceKeys(std::vector<std::pair<std::string, std::strin
[self configSearchBar];
[self configData];
[self configTable];
[MWMKeyboard addObserver:self];
}
- (UIStatusBarStyle)preferredStatusBarStyle
@ -50,15 +48,6 @@ std::vector<std::string> SliceKeys(std::vector<std::pair<std::string, std::strin
return UIStatusBarStyleLightContent;
}
#pragma mark - MWMKeyboard
- (void)onKeyboardAnimation
{
UIEdgeInsets const contentInsets = {.bottom = [MWMKeyboard keyboardHeight]};
self.tableView.contentInset = contentInsets;
self.tableView.scrollIndicatorInsets = contentInsets;
}
#pragma mark - UISearchBarDelegate
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText

View file

@ -2,7 +2,6 @@
#import "MWMAuthorizationCommon.h"
#import "MWMObjectsCategorySelectorDataSource.h"
#import "MWMEditorViewController.h"
#import "MWMKeyboard.h"
#import "MWMTableViewCell.h"
#import "SwiftBridge.h"
@ -16,7 +15,7 @@ NSString * const kToEditorSegue = @"CategorySelectorToEditorSegue";
} // namespace
@interface MWMObjectsCategorySelectorController ()<UISearchBarDelegate, UITableViewDelegate,
UITableViewDataSource, MWMKeyboardObserver>
UITableViewDataSource>
{
}
@ -43,7 +42,6 @@ NSString * const kToEditorSegue = @"CategorySelectorToEditorSegue";
[self configTable];
[self configNavBar];
[self configSearchBar];
[MWMKeyboard addObserver:self];
self.dataSource = [[MWMObjectsCategorySelectorDataSource alloc] init];
}
@ -90,15 +88,6 @@ NSString * const kToEditorSegue = @"CategorySelectorToEditorSegue";
[dest setEditableMapObject:object];
}
#pragma mark - MWMKeyboard
- (void)onKeyboardAnimation
{
UIEdgeInsets const contentInsets = {.bottom = [MWMKeyboard keyboardHeight]};
self.tableView.contentInset = contentInsets;
self.tableView.scrollIndicatorInsets = contentInsets;
}
#pragma mark - Create object
- (EditableMapObject)createdObject

View file

@ -15,15 +15,5 @@ final class SearchNoResultsViewController: MWMViewController {
container.addSubview(MWMSearchNoResults.view(with: nil,
title: L("search_not_found"),
text: L("search_not_found_query")))
MWMKeyboard.add(self)
onKeyboardAnimation()
}
}
extension SearchNoResultsViewController: MWMKeyboardObserver {
func onKeyboardAnimation() {
containerBottomOffset.constant = MWMKeyboard.keyboardHeight()
view.layoutIfNeeded()
}
}

View file

@ -1,8 +1,7 @@
#import "MWMSearchTableView.h"
#import "MWMKeyboard.h"
#import "MWMSearchNoResults.h"
@interface MWMSearchTableView ()<MWMKeyboardObserver>
@interface MWMSearchTableView ()
@property(weak, nonatomic) IBOutlet NSLayoutConstraint * noResultsBottomOffset;
@ -20,7 +19,6 @@
CALayer * sl = self.layer;
sl.shouldRasterize = YES;
sl.rasterizationScale = UIScreen.mainScreen.scale;
[MWMKeyboard addObserver:self];
}
- (void)hideNoResultsView:(BOOL)hide
@ -34,29 +32,9 @@
{
self.noResultsContainer.hidden = NO;
[self.noResultsWrapper addSubview:self.noResultsView];
[self onKeyboardAnimation];
}
}
#pragma mark - MWMKeyboard
- (void)onKeyboardAnimation
{
CGFloat const keyboardHeight = [MWMKeyboard keyboardHeight];
if (keyboardHeight >= self.height)
return;
self.noResultsBottomOffset.constant = keyboardHeight;
if (self.superview)
[self layoutIfNeeded];
}
- (void)onKeyboardWillAnimate
{
if (self.superview)
[self layoutIfNeeded];
}
- (MWMSearchNoResults *)noResultsView
{
if (!_noResultsView)

View file

@ -1058,11 +1058,8 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="EbW-Mp-c6s">
<rect key="frame" x="0.0" y="0.0" width="896" height="393"/>
<rect key="frame" x="44" y="0.0" width="808" height="393"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" secondItem="EbW-Mp-c6s" secondAttribute="height" multiplier="1:1" id="tBC-sb-Q3g"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="styleName" value="Background"/>
</userDefinedRuntimeAttributes>
@ -1071,14 +1068,10 @@
<viewLayoutGuide key="safeArea" id="yK4-pW-Ads"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="EbW-Mp-c6s" firstAttribute="centerY" secondItem="9jm-RW-DZK" secondAttribute="centerY" priority="250" id="BHf-cB-UbU"/>
<constraint firstItem="EbW-Mp-c6s" firstAttribute="height" relation="lessThanOrEqual" secondItem="9jm-RW-DZK" secondAttribute="height" id="JtV-po-tD6"/>
<constraint firstItem="EbW-Mp-c6s" firstAttribute="top" relation="greaterThanOrEqual" secondItem="9jm-RW-DZK" secondAttribute="top" id="O71-EO-9LT"/>
<constraint firstItem="EbW-Mp-c6s" firstAttribute="width" relation="lessThanOrEqual" secondItem="9jm-RW-DZK" secondAttribute="width" id="aCG-RN-DSJ"/>
<constraint firstItem="yK4-pW-Ads" firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="EbW-Mp-c6s" secondAttribute="bottom" id="i0h-xR-pPI"/>
<constraint firstItem="EbW-Mp-c6s" firstAttribute="height" secondItem="9jm-RW-DZK" secondAttribute="height" priority="750" id="r08-2f-jwK"/>
<constraint firstItem="EbW-Mp-c6s" firstAttribute="centerX" secondItem="yK4-pW-Ads" secondAttribute="centerX" id="xbz-FB-nZl"/>
<constraint firstItem="EbW-Mp-c6s" firstAttribute="width" secondItem="9jm-RW-DZK" secondAttribute="width" priority="750" id="zcx-oD-0Uk"/>
<constraint firstItem="EbW-Mp-c6s" firstAttribute="bottom" secondItem="yK4-pW-Ads" secondAttribute="bottom" id="BHf-cB-UbU"/>
<constraint firstItem="EbW-Mp-c6s" firstAttribute="top" secondItem="yK4-pW-Ads" secondAttribute="top" id="O71-EO-9LT"/>
<constraint firstItem="yK4-pW-Ads" firstAttribute="trailing" secondItem="EbW-Mp-c6s" secondAttribute="trailing" id="Tqg-dZ-SaB"/>
<constraint firstItem="EbW-Mp-c6s" firstAttribute="leading" secondItem="yK4-pW-Ads" secondAttribute="leading" id="xbz-FB-nZl"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="styleName" value="Background"/>
@ -1086,7 +1079,6 @@
</view>
<connections>
<outlet property="container" destination="EbW-Mp-c6s" id="T6K-0M-IAe"/>
<outlet property="containerBottomOffset" destination="i0h-xR-pPI" id="TpT-gj-gr2"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="rxe-Bw-br6" userLabel="First Responder" sceneMemberID="firstResponder"/>