Merge pull request #236 from vector-im/improve_chat_header

Improve chat header
This commit is contained in:
giomfo 2016-04-20 10:17:02 +02:00
commit ba2c8ce02d
3 changed files with 30 additions and 68 deletions

View file

@ -25,7 +25,6 @@
@interface RoomViewController : MXKRoomViewController <UISearchBarDelegate, UIGestureRecognizerDelegate, RoomTitleViewTapGestureDelegate>
// The expanded header
@property (weak, nonatomic) IBOutlet UIScrollView *expandedHeaderScrollView;
@property (weak, nonatomic) IBOutlet UIView *expandedHeaderContainer;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *expandedHeaderContainerHeightConstraint;

View file

@ -71,9 +71,6 @@
// The preview header
PreviewRoomTitleView *previewHeader;
// The content offset at the beginning of header scrolling
CGFloat beginDraggingHeaderContentOffset;
// The customized room data source for Vector
RoomDataSource *customizedRoomDataSource;
@ -210,6 +207,12 @@
[NSLayoutConstraint activateConstraints:@[leftConstraint, rightConstraint, topConstraint, bottomConstraint]];
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(onSwipeGesture:)];
[swipe setNumberOfTouchesRequired:1];
[swipe setDirection:UISwipeGestureRecognizerDirectionUp];
[self.expandedHeaderContainer addGestureRecognizer:swipe];
// Prepare preview header container
self.previewHeaderContainer.backgroundColor = kVectorColorLightGrey;
@ -345,7 +348,7 @@
contentInset.bottom = self.bottomLayoutGuide.length;
self.bubblesTableView.contentInset = contentInset;
if (self.expandedHeaderScrollView.isHidden == NO)
if (self.expandedHeaderContainer.isHidden == NO)
{
// Adjust the top constraint of the bubbles table
self.bubblesTableViewTopConstraint.constant = self.expandedHeaderContainerHeightConstraint.constant - self.bubblesTableView.contentInset.top;
@ -621,6 +624,18 @@
}
}
- (void)onSwipeGesture:(UISwipeGestureRecognizer*)swipeGestureRecognizer
{
UIView *view = swipeGestureRecognizer.view;
if (view == self.expandedHeaderContainer)
{
// Hide the expanded header when user swipes upward on expanded header.
// We reset here the property 'showExpandedHeader'. Then the header is not expanded automatically on viewWillAppear.
self.showExpandedHeader = NO;
}
}
#pragma mark - Hide/Show expanded header
- (void)showExpandedHeader:(BOOL)isVisible
@ -632,9 +647,9 @@
// - if the room data source does not manage a live timeline.
// - if the user's membership is not 'join'.
// - if the view controller is not embedded inside a split view controller yet.
if (self.expandedHeaderScrollView.isHidden == isVisible && isSizeTransitionInProgress == NO && self.roomDataSource && self.roomDataSource.isLive && self.roomDataSource.room.state.membership == MXMembershipJoin && self.splitViewController)
if (self.expandedHeaderContainer.isHidden == isVisible && isSizeTransitionInProgress == NO && self.roomDataSource && self.roomDataSource.isLive && self.roomDataSource.room.state.membership == MXMembershipJoin && self.splitViewController)
{
self.expandedHeaderScrollView.hidden = !isVisible;
self.expandedHeaderContainer.hidden = !isVisible;
// Consider the main navigation controller if the current view controller is embedded inside a split view controller.
UINavigationController *mainNavigationController = self.navigationController;
@ -1437,41 +1452,6 @@
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
if ([MXKRoomViewController instancesRespondToSelector:@selector(scrollViewWillBeginDragging:)])
{
[super scrollViewWillBeginDragging:scrollView];
}
if (scrollView == self.expandedHeaderScrollView)
{
// Store the current offset to detect scroll down
beginDraggingHeaderContentOffset = scrollView.contentOffset.y;
}
}
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
if ([MXKRoomViewController instancesRespondToSelector:@selector(scrollViewWillEndDragging:withVelocity:targetContentOffset:)])
{
[super scrollViewWillEndDragging:scrollView withVelocity:velocity targetContentOffset:targetContentOffset];
}
if (scrollView == self.expandedHeaderScrollView)
{
// Hide the expanded header on scroll down.
if (beginDraggingHeaderContentOffset < scrollView.contentOffset.y)
{
// We reset here the property 'showExpandedHeader'. Then the header is not expanded automatically on viewWillAppear.
self.showExpandedHeader = NO;
}
}
}
#pragma mark - MXKRoomTitleViewDelegate
- (BOOL)roomTitleViewShouldBeginEditing:(MXKRoomTitleView*)titleView
@ -1488,7 +1468,7 @@
if (view == titleView.titleMask)
{
if (self.expandedHeaderScrollView.isHidden)
if (self.expandedHeaderContainer.isHidden)
{
// Expand the header
[self showExpandedHeader:YES];

View file

@ -12,7 +12,6 @@
<outlet property="bubblesTableViewTopConstraint" destination="X14-4s-uGM" id="Hic-6h-N05"/>
<outlet property="expandedHeaderContainer" destination="uK2-9a-rZj" id="0lY-NB-cR1"/>
<outlet property="expandedHeaderContainerHeightConstraint" destination="w9z-HS-7wJ" id="6uK-Bn-TcU"/>
<outlet property="expandedHeaderScrollView" destination="IUM-JV-dby" id="Ncv-kA-ZBq"/>
<outlet property="previewHeaderContainer" destination="54r-18-K1g" id="Klt-RV-V1E"/>
<outlet property="previewHeaderContainerHeightConstraint" destination="goj-GZ-IkD" id="GbA-T9-kiL"/>
<outlet property="roomActivitiesContainer" destination="XX4-n6-hCm" id="uD0-ab-8s8"/>
@ -32,29 +31,13 @@
<rect key="frame" x="0.0" y="0.0" width="600" height="559"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</tableView>
<scrollView hidden="YES" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" showsHorizontalScrollIndicator="NO" translatesAutoresizingMaskIntoConstraints="NO" id="IUM-JV-dby">
<rect key="frame" x="0.0" y="0.0" width="600" height="239"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="uK2-9a-rZj" userLabel="Expanded Header Container" customClass="ExpandedRoomTitleView">
<rect key="frame" x="0.0" y="0.0" width="600" height="240"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" constant="240" id="w9z-HS-7wJ"/>
</constraints>
</view>
</subviews>
<view hidden="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="uK2-9a-rZj" userLabel="Expanded Header Container" customClass="ExpandedRoomTitleView">
<rect key="frame" x="0.0" y="0.0" width="600" height="240"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="uK2-9a-rZj" firstAttribute="leading" secondItem="IUM-JV-dby" secondAttribute="leading" id="CG2-bd-fub"/>
<constraint firstAttribute="height" constant="239" id="KfF-yg-HjH"/>
<constraint firstItem="uK2-9a-rZj" firstAttribute="centerX" secondItem="IUM-JV-dby" secondAttribute="centerX" id="VDg-jZ-ZBu"/>
<constraint firstAttribute="trailing" secondItem="uK2-9a-rZj" secondAttribute="trailing" id="W7t-FM-Ibo"/>
<constraint firstAttribute="bottom" secondItem="uK2-9a-rZj" secondAttribute="bottom" id="jTU-0Z-y2J"/>
<constraint firstItem="uK2-9a-rZj" firstAttribute="top" secondItem="IUM-JV-dby" secondAttribute="top" id="wgT-kJ-vKl"/>
<constraint firstAttribute="height" constant="240" id="w9z-HS-7wJ"/>
</constraints>
<connections>
<outlet property="delegate" destination="-1" id="jPm-tb-GxK"/>
</connections>
</scrollView>
</view>
<view hidden="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="54r-18-K1g">
<rect key="frame" x="0.0" y="0.0" width="600" height="368"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
@ -81,8 +64,7 @@
<constraints>
<constraint firstAttribute="trailing" secondItem="BGD-sd-SQR" secondAttribute="trailing" id="0la-ok-MBr"/>
<constraint firstItem="nLd-BP-JAE" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" id="4Q7-hr-rqi"/>
<constraint firstItem="IUM-JV-dby" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" id="6xF-AH-Lzh"/>
<constraint firstItem="IUM-JV-dby" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" id="I5M-01-LVc"/>
<constraint firstAttribute="trailing" secondItem="uK2-9a-rZj" secondAttribute="trailing" id="HbF-85-ctI"/>
<constraint firstAttribute="bottom" secondItem="BGD-sd-SQR" secondAttribute="bottom" constant="41" id="Ksk-39-kfi"/>
<constraint firstItem="54r-18-K1g" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" id="QGq-T0-Epo"/>
<constraint firstItem="XX4-n6-hCm" firstAttribute="bottom" secondItem="nLd-BP-JAE" secondAttribute="top" id="QO8-nF-xys"/>
@ -93,8 +75,9 @@
<constraint firstItem="XX4-n6-hCm" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" id="csl-KT-4s9"/>
<constraint firstItem="BGD-sd-SQR" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" id="haP-Kv-OLI"/>
<constraint firstAttribute="bottom" secondItem="nLd-BP-JAE" secondAttribute="bottom" id="kQ6-Cg-FMi"/>
<constraint firstAttribute="trailing" secondItem="IUM-JV-dby" secondAttribute="trailing" id="mq8-kD-ZVW"/>
<constraint firstItem="54r-18-K1g" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" id="t02-d3-Zyf"/>
<constraint firstItem="uK2-9a-rZj" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" id="u8r-eN-1g8"/>
<constraint firstItem="uK2-9a-rZj" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" id="y6b-JK-CF5"/>
</constraints>
<nil key="simulatedStatusBarMetrics"/>
</view>