Skip to content

Commit

Permalink
Merge pull request #1810 from vector-im/riot_1645_2
Browse files Browse the repository at this point in the history
 BF: Cannot join from a room preview for room with a long topic
  • Loading branch information
manuroe authored Mar 12, 2018
2 parents eb23bd1 + 11378ea commit 4c014e4
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 19 deletions.
37 changes: 30 additions & 7 deletions Riot/ViewController/RoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1227,11 +1227,8 @@ - (void)refreshRoomTitle
// Set the right room title view
if (self.isRoomPreview)
{
// Disable the right buttons
for (UIBarButtonItem *barButtonItem in self.navigationItem.rightBarButtonItems)
{
barButtonItem.enabled = NO;
}
// Do not show the right buttons
self.navigationItem.rightBarButtonItems = nil;

[self showPreviewHeader:YES];
}
Expand Down Expand Up @@ -1583,7 +1580,8 @@ - (void)refreshPreviewHeader:(BOOL)isLandscapeOriented
{
if (previewHeader)
{
if (isLandscapeOriented)
if (isLandscapeOriented
&& [GBDeviceInfo deviceInfo].family != GBDeviceFamilyiPad)
{
CGRect frame = self.navigationController.navigationBar.frame;

Expand All @@ -1605,7 +1603,32 @@ - (void)refreshPreviewHeader:(BOOL)isLandscapeOriented
{
previewHeader.mainHeaderContainer.hidden = NO;
previewHeader.mainHeaderBackgroundHeightConstraint.constant = previewHeader.mainHeaderContainer.frame.size.height;


if ([previewHeader isKindOfClass:PreviewRoomTitleView.class])
{
// In case of preview, update the header height so that we can
// display as much as possible the room topic in this header.
// Note: the header height is handled by the previewHeader.mainHeaderBackgroundHeightConstraint.
PreviewRoomTitleView *previewRoomTitleView = (PreviewRoomTitleView *)previewHeader;

// Compute the height required to display all the room topic
CGSize sizeThatFitsTextView = [previewRoomTitleView.roomTopic sizeThatFits:CGSizeMake(previewRoomTitleView.roomTopic.frame.size.width, MAXFLOAT)];

// Increase the preview header height according to the room topic height
// but limit it in order to let room for room messages at the screen bottom.
// This free space depends on the device.
// On an iphone 5 screen, the room topic height cannot be more than 50px.
// Then, on larger screen, we can allow it a bit more height but we
// apply a factor to give more priority to the display of more messages.
CGFloat screenHeight = [[UIScreen mainScreen] bounds].size.height;
CGFloat maxRoomTopicHeight = 50 + (screenHeight - 568) / 3;

CGFloat additionalHeight = MIN(maxRoomTopicHeight, sizeThatFitsTextView.height)
- previewRoomTitleView.roomTopic.frame.size.height;

previewHeader.mainHeaderBackgroundHeightConstraint.constant += additionalHeight;
}

[self setRoomTitleViewClass:RoomAvatarTitleView.class];
// Note the avatar title view does not define tap gesture.

Expand Down
2 changes: 1 addition & 1 deletion Riot/Views/RoomTitle/PreviewRoomTitleView.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@property (weak, nonatomic) IBOutlet UIView *mainHeaderContainer;

@property (weak, nonatomic) IBOutlet MXKImageView *roomAvatar;
@property (weak, nonatomic) IBOutlet UILabel *roomTopic;
@property (weak, nonatomic) IBOutlet UITextView *roomTopic;
@property (weak, nonatomic) IBOutlet UILabel *roomMembers;
@property (weak, nonatomic) IBOutlet UIView *roomMembersDetailsIcon;

Expand Down
13 changes: 12 additions & 1 deletion Riot/Views/RoomTitle/PreviewRoomTitleView.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ -(void)customizeViewRendering
self.displayNameTextField.textColor = (self.mxRoom.summary.displayname.length ? kRiotPrimaryTextColor : kRiotSecondaryTextColor);

self.roomTopic.textColor = kRiotTopicTextColor;
self.roomTopic.numberOfLines = 0;

self.roomMembers.textColor = kRiotColorGreen;

Expand Down Expand Up @@ -106,6 +105,10 @@ - (void)refreshDisplay

// Room topic
self.roomTopic.text = self.roomPreviewData.roomTopic;

[UIView setAnimationsEnabled:NO];
[self.roomTopic scrollRangeToVisible:NSMakeRange(0, 0)];
[UIView setAnimationsEnabled:YES];

// Joined members count
if (self.roomPreviewData.numJoinedMembers > 1)
Expand Down Expand Up @@ -148,6 +151,14 @@ - (void)refreshDisplay
{
roomName = NSLocalizedStringFromTable(@"room_preview_try_join_an_unknown_room_default", @"Vector", nil);
}
else if (roomName.length > 20)
{
// Would have been nice to get the cropped string displayed by
// self.displayNameTextField but the value is not accessible.
// Cut it off by hand
roomName = [NSString stringWithFormat:@"%@",[roomName substringToIndex:20]];
}

self.previewLabel.text = [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_preview_try_join_an_unknown_room", @"Vector", nil), roomName];
}
}
Expand Down
22 changes: 12 additions & 10 deletions Riot/Views/RoomTitle/PreviewRoomTitleView.xib
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand Down Expand Up @@ -47,22 +47,22 @@
<outlet property="delegate" destination="Cpa-Xt-cwB" id="BIq-nD-Pb9"/>
</connections>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Tk0-pA-9a0">
<rect key="frame" x="282" y="153" width="36" height="17"/>
<textView opaque="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" editable="NO" text="Room Topic" textAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="Tk0-pA-9a0">
<rect key="frame" x="31" y="153" width="538" height="17"/>
<accessibility key="accessibilityConfiguration" identifier="RoomTopic"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ou0-3Z-weL">
<rect key="frame" x="282" y="184" width="36" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="X members" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ou0-3Z-weL">
<rect key="frame" x="262" y="184" width="76" height="17"/>
<accessibility key="accessibilityConfiguration" identifier="RoomMembers"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<imageView hidden="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="details_icon" translatesAutoresizingMaskIntoConstraints="NO" id="S3Y-wJ-HOe">
<rect key="frame" x="325" y="187" width="6" height="12"/>
<rect key="frame" x="345" y="187" width="6" height="12"/>
<accessibility key="accessibilityConfiguration" identifier="RoomMembersDetailsIcon"/>
<constraints>
<constraint firstAttribute="width" constant="6" id="XTx-6p-2wB"/>
Expand All @@ -87,6 +87,7 @@
<constraint firstItem="Tk0-pA-9a0" firstAttribute="top" secondItem="6uH-I3-RQg" secondAttribute="bottom" constant="5" id="TUS-xE-O6O"/>
<constraint firstItem="6uH-I3-RQg" firstAttribute="top" secondItem="4yt-FK-V2Z" secondAttribute="bottom" constant="8" id="Wsd-KT-hxy"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="6uH-I3-RQg" secondAttribute="trailing" constant="31" id="aK3-vQ-EVu"/>
<constraint firstItem="Tk0-pA-9a0" firstAttribute="width" secondItem="BkF-x3-7fX" secondAttribute="width" priority="750" id="bWP-2y-KTg"/>
<constraint firstItem="ou0-3Z-weL" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="BkF-x3-7fX" secondAttribute="leading" constant="31" id="c9h-h2-VEs"/>
<constraint firstItem="6uH-I3-RQg" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="BkF-x3-7fX" secondAttribute="leading" constant="31" id="gnq-cO-l4Y"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="ou0-3Z-weL" secondAttribute="trailing" constant="31" id="sPZ-Hp-JeH"/>
Expand Down Expand Up @@ -166,6 +167,7 @@
<constraint firstItem="BkF-x3-7fX" firstAttribute="leading" secondItem="Cpa-Xt-cwB" secondAttribute="leading" id="Uvb-cK-dQf"/>
<constraint firstItem="BkF-x3-7fX" firstAttribute="top" secondItem="Cpa-Xt-cwB" secondAttribute="top" id="Zru-9A-ifB"/>
<constraint firstAttribute="trailing" secondItem="y5s-FK-My4" secondAttribute="trailing" id="d4g-19-C58"/>
<constraint firstItem="BkF-x3-7fX" firstAttribute="bottom" secondItem="y5s-FK-My4" secondAttribute="bottom" id="gzp-8c-3iR"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="IwA-0X-IYb" secondAttribute="trailing" constant="31" id="iGR-eh-0e9"/>
<constraint firstItem="WmW-5h-jL1" firstAttribute="top" secondItem="gIX-nY-f6M" secondAttribute="bottom" constant="17" id="ioD-jo-XQe"/>
<constraint firstItem="IwA-0X-IYb" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="Cpa-Xt-cwB" secondAttribute="leading" constant="31" id="lpD-yd-qgt"/>
Expand Down

0 comments on commit 4c014e4

Please sign in to comment.