forked from organicmaps/organicmaps
[MAPSME-3126] [ios] Fixed PP opening bug.
This commit is contained in:
parent
b4b1cbd602
commit
6f0e188b14
6 changed files with 102 additions and 90 deletions
|
@ -25,6 +25,4 @@
|
|||
@property(nonatomic) CGFloat currentContentHeight;
|
||||
@property(nonatomic) id<MWMPlacePageViewUpdateProtocol> delegate;
|
||||
|
||||
- (void)hideTableView:(BOOL)isHidden;
|
||||
|
||||
@end
|
||||
|
|
|
@ -39,20 +39,6 @@ CGFloat const kTableViewTopInset = -36;
|
|||
|
||||
@implementation MWMPPView
|
||||
|
||||
- (void)hideTableView:(BOOL)isHidden
|
||||
{
|
||||
if (isHidden)
|
||||
{
|
||||
self.tableView.alpha = 0.;
|
||||
self.anchorImage.hidden = YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
self.tableView.alpha = 1.;
|
||||
self.anchorImage.hidden = NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath
|
||||
ofObject:(id)object
|
||||
change:(NSDictionary *)change
|
||||
|
|
|
@ -77,6 +77,7 @@ array<NSString *, 1> const kButtonsCells = {{@"MWMPlacePageButtonCell"}};
|
|||
_delegate = delegate;
|
||||
_dataSource = dataSource;
|
||||
[[NSBundle mainBundle] loadNibNamed:[MWMPPView className] owner:self options:nil];
|
||||
[_placePageView layoutIfNeeded];
|
||||
_placePageView.delegate = self;
|
||||
auto const Impl = IPAD ? [MWMiPadPlacePageLayoutImpl class] : [MWMiPhonePlacePageLayoutImpl class];
|
||||
_layoutImpl = [[Impl alloc] initOwnerView:view placePageView:_placePageView delegate:delegate];
|
||||
|
@ -121,7 +122,6 @@ array<NSString *, 1> const kButtonsCells = {{@"MWMPlacePageButtonCell"}};
|
|||
self.isPlacePageButtonsEnabled = YES;
|
||||
self.data = data;
|
||||
self.bookmarkCell = nil;
|
||||
[self.layoutImpl onShow];
|
||||
|
||||
[self.actionBar configureWithData:static_cast<id<MWMActionBarSharedData>>(data)];
|
||||
[self.previewLayoutHelper configWithData:data];
|
||||
|
@ -132,8 +132,7 @@ array<NSString *, 1> const kButtonsCells = {{@"MWMPlacePageButtonCell"}};
|
|||
[self.placePageView.tableView reloadData];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if ([self.layoutImpl respondsToSelector:@selector(onExpandWithPlacePagePreviewHeight:)])
|
||||
[self.layoutImpl onExpandWithPlacePagePreviewHeight:self.previewLayoutHelper.height];
|
||||
[self.layoutImpl onShow];
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -152,7 +151,7 @@ array<NSString *, 1> const kButtonsCells = {{@"MWMPlacePageButtonCell"}};
|
|||
if (!_actionBar)
|
||||
{
|
||||
_actionBar = [MWMPlacePageActionBar actionBarWithDelegate:self.delegate];
|
||||
[self.layoutImpl onActionBarInit:_actionBar];
|
||||
self.layoutImpl.actionBar = _actionBar;
|
||||
}
|
||||
return _actionBar;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ inline void animate(TMWMVoidBlock animate, TMWMVoidBlock completion = nil)
|
|||
- (void)onClose;
|
||||
- (void)onScreenResize:(CGSize const &)size;
|
||||
- (void)onUpdatePlacePageWithHeight:(CGFloat)height;
|
||||
- (void)onActionBarInit:(MWMPlacePageActionBar *)actionBar;
|
||||
|
||||
@property(weak, nonatomic) UIView * ownerView;
|
||||
@property(weak, nonatomic) MWMPPView * placePageView;
|
||||
|
@ -40,7 +39,6 @@ inline void animate(TMWMVoidBlock animate, TMWMVoidBlock completion = nil)
|
|||
@property(weak, nonatomic) MWMPlacePageActionBar * actionBar;
|
||||
|
||||
@optional
|
||||
- (void)onExpandWithPlacePagePreviewHeight:(CGFloat)height;
|
||||
- (void)updateLayoutWithTopBound:(CGFloat)topBound;
|
||||
- (void)updateLayoutWithLeftBound:(CGFloat)leftBound;
|
||||
- (void)setInitialTopBound:(CGFloat)topBound leftBound:(CGFloat)leftBound;
|
||||
|
|
|
@ -54,13 +54,9 @@ CGFloat const kBottomOffset = 60;
|
|||
if (self)
|
||||
{
|
||||
_ownerView = ownerView;
|
||||
_placePageView = placePageView;
|
||||
self.placePageView = placePageView;
|
||||
_delegate = delegate;
|
||||
placePageView.width = kPlacePageWidth;
|
||||
placePageView.anchorImage.hidden = YES;
|
||||
[self addShadow];
|
||||
auto pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(didPan:)];
|
||||
[placePageView addGestureRecognizer:pan];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -97,15 +93,16 @@ CGFloat const kBottomOffset = 60;
|
|||
- (void)onClose
|
||||
{
|
||||
auto ppView = self.placePageView;
|
||||
place_page_layout::animate(^{
|
||||
ppView.maxX = 0;
|
||||
ppView.alpha = 0;
|
||||
},^{
|
||||
[self.placePageView removeFromSuperview];
|
||||
[self.actionBar removeFromSuperview];
|
||||
self.actionBar = nil;
|
||||
[self.delegate shouldDestroyLayout];
|
||||
});
|
||||
place_page_layout::animate(
|
||||
^{
|
||||
ppView.maxX = 0;
|
||||
ppView.alpha = 0;
|
||||
},
|
||||
^{
|
||||
self.placePageView = nil;
|
||||
self.actionBar = nil;
|
||||
[self.delegate shouldDestroyLayout];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)onScreenResize:(CGSize const &)size
|
||||
|
@ -118,14 +115,6 @@ CGFloat const kBottomOffset = 60;
|
|||
[self layoutPlacePage:height onScreen:self.ownerView.height];
|
||||
}
|
||||
|
||||
- (void)onActionBarInit:(MWMPlacePageActionBar *)actionBar
|
||||
{
|
||||
UIView * superview = self.placePageView;
|
||||
self.actionBar = actionBar;
|
||||
[superview addSubview:actionBar];
|
||||
actionBar.origin = {0., superview.height - actionBar.height};
|
||||
}
|
||||
|
||||
- (void)setInitialTopBound:(CGFloat)topBound leftBound:(CGFloat)leftBound
|
||||
{
|
||||
self.topBound = topBound;
|
||||
|
@ -216,5 +205,37 @@ CGFloat const kBottomOffset = 60;
|
|||
|
||||
- (CGFloat)topBound { return _topBound + kTopOffset; }
|
||||
- (CGFloat)leftBound { return _leftBound + kLeftOffset; }
|
||||
#pragma mark - Properties
|
||||
|
||||
- (void)setPlacePageView:(MWMPPView *)placePageView
|
||||
{
|
||||
if (placePageView)
|
||||
{
|
||||
placePageView.width = kPlacePageWidth;
|
||||
placePageView.anchorImage.hidden = YES;
|
||||
auto pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(didPan:)];
|
||||
[placePageView addGestureRecognizer:pan];
|
||||
}
|
||||
else
|
||||
{
|
||||
[_placePageView removeFromSuperview];
|
||||
}
|
||||
_placePageView = placePageView;
|
||||
}
|
||||
|
||||
- (void)setActionBar:(MWMPlacePageActionBar *)actionBar
|
||||
{
|
||||
if (actionBar)
|
||||
{
|
||||
auto superview = self.placePageView;
|
||||
actionBar.origin = {0., superview.height - actionBar.height};
|
||||
[superview addSubview:actionBar];
|
||||
}
|
||||
else
|
||||
{
|
||||
[_actionBar removeFromSuperview];
|
||||
}
|
||||
_actionBar = actionBar;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -16,8 +16,6 @@ enum class State
|
|||
Top
|
||||
};
|
||||
|
||||
// Minimal offset for collapse. If place page offset is below this value we should hide place page.
|
||||
CGFloat const kMinOffset = 1;
|
||||
CGFloat const kOpenPlacePageStopValue = 0.7;
|
||||
CGFloat const kLuftDraggingOffset = 30;
|
||||
} // namespace
|
||||
|
@ -55,13 +53,11 @@ CGFloat const kLuftDraggingOffset = 30;
|
|||
_placePageView = placePageView;
|
||||
placePageView.tableView.delegate = self;
|
||||
_delegate = delegate;
|
||||
_scrollView = [[MWMPPScrollView alloc] initWithFrame:ownerView.frame inactiveView:placePageView];
|
||||
_scrollView.delegate = self;
|
||||
self.scrollView =
|
||||
[[MWMPPScrollView alloc] initWithFrame:ownerView.frame inactiveView:placePageView];
|
||||
_portraitOpenContentOffset = MAX(size.width, size.height) * kOpenPlacePageStopValue;
|
||||
_landscapeOpenContentOffset = MIN(size.width, size.height) * kOpenPlacePageStopValue;
|
||||
placePageView.frame = {{0, size.height}, size};
|
||||
[ownerView addSubview:self.scrollView];
|
||||
[_scrollView addSubview:placePageView];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -69,7 +65,24 @@ CGFloat const kLuftDraggingOffset = 30;
|
|||
- (void)onShow
|
||||
{
|
||||
self.state = State::Bottom;
|
||||
[self collapse];
|
||||
|
||||
auto scrollView = self.scrollView;
|
||||
scrollView.scrollEnabled = NO;
|
||||
|
||||
place_page_layout::animate(
|
||||
^{
|
||||
auto actionBar = self.actionBar;
|
||||
actionBar.maxY = actionBar.superview.height;
|
||||
|
||||
self.expandedContentOffset =
|
||||
self.previewLayoutHelper.height + actionBar.height - self.placePageView.top.height;
|
||||
auto const targetOffset =
|
||||
self.state == State::Bottom ? self.expandedContentOffset : self.topContentOffset;
|
||||
[scrollView setContentOffset:{ 0, targetOffset } animated:YES];
|
||||
},
|
||||
^{
|
||||
scrollView.scrollEnabled = YES;
|
||||
});
|
||||
}
|
||||
|
||||
- (void)onClose
|
||||
|
@ -78,8 +91,8 @@ CGFloat const kLuftDraggingOffset = 30;
|
|||
self.actionBar.minY = self.ownerView.height;
|
||||
[self.scrollView setContentOffset:{} animated:YES];
|
||||
},^{
|
||||
[self.actionBar removeFromSuperview];
|
||||
self.actionBar = nil;
|
||||
self.scrollView = nil;
|
||||
[self.delegate shouldDestroyLayout];
|
||||
});
|
||||
}
|
||||
|
@ -100,41 +113,6 @@ CGFloat const kLuftDraggingOffset = 30;
|
|||
self.scrollView.contentSize = {size.width, size.height + self.placePageView.height};
|
||||
}
|
||||
|
||||
- (void)onActionBarInit:(MWMPlacePageActionBar *)actionBar
|
||||
{
|
||||
auto superview = self.ownerView;
|
||||
self.actionBar = actionBar;
|
||||
actionBar.minY = superview.height;
|
||||
[superview addSubview:_actionBar];
|
||||
}
|
||||
|
||||
- (void)onExpandWithPlacePagePreviewHeight:(CGFloat)height
|
||||
{
|
||||
self.actionBar.hidden = NO;
|
||||
self.scrollView.scrollEnabled = YES;
|
||||
|
||||
place_page_layout::animate(^{
|
||||
auto ppView = self.placePageView;
|
||||
[ppView hideTableView:NO];
|
||||
auto actionBar = self.actionBar;
|
||||
actionBar.minY = actionBar.superview.height - actionBar.height;
|
||||
|
||||
self.expandedContentOffset = height + actionBar.height - ppView.top.height;
|
||||
auto const targetOffset = self.state == State::Bottom ? self.expandedContentOffset : self.topContentOffset;
|
||||
[self.scrollView setContentOffset:{ 0, targetOffset } animated:YES];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)collapse
|
||||
{
|
||||
self.scrollView.scrollEnabled = NO;
|
||||
[self.placePageView hideTableView:YES];
|
||||
|
||||
place_page_layout::animate(^{
|
||||
[self.scrollView setContentOffset:{ 0., kMinOffset } animated:YES];
|
||||
});
|
||||
}
|
||||
|
||||
#pragma mark - UIScrollViewDelegate
|
||||
|
||||
- (BOOL)isPortrait
|
||||
|
@ -165,9 +143,7 @@ CGFloat const kLuftDraggingOffset = 30;
|
|||
id<MWMPlacePageLayoutDelegate> delegate = self.delegate;
|
||||
if (offset.y <= 0)
|
||||
{
|
||||
[self.scrollView removeFromSuperview];
|
||||
[self.actionBar removeFromSuperview];
|
||||
[delegate shouldDestroyLayout];
|
||||
[self onClose];
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -279,5 +255,39 @@ CGFloat const kLuftDraggingOffset = 30;
|
|||
place_page_layout::animate(^{ [self.scrollView setContentOffset:{0, offset} animated:YES]; });
|
||||
}
|
||||
|
||||
#pragma mark - Properties
|
||||
|
||||
- (void)setScrollView:(MWMPPScrollView *)scrollView
|
||||
{
|
||||
if (scrollView)
|
||||
{
|
||||
scrollView.delegate = self;
|
||||
[self.ownerView addSubview:scrollView];
|
||||
[scrollView addSubview:self.placePageView];
|
||||
}
|
||||
else
|
||||
{
|
||||
_scrollView.delegate = nil;
|
||||
[_scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
|
||||
[_scrollView removeFromSuperview];
|
||||
}
|
||||
_scrollView = scrollView;
|
||||
}
|
||||
|
||||
- (void)setActionBar:(MWMPlacePageActionBar *)actionBar
|
||||
{
|
||||
if (actionBar)
|
||||
{
|
||||
auto superview = self.ownerView;
|
||||
actionBar.minY = superview.height;
|
||||
[superview addSubview:actionBar];
|
||||
}
|
||||
else
|
||||
{
|
||||
[_actionBar removeFromSuperview];
|
||||
}
|
||||
_actionBar = actionBar;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue