Skip to content

Commit

Permalink
fixed #146
Browse files Browse the repository at this point in the history
  • Loading branch information
pro100andrey committed Apr 17, 2018
1 parent 5e7d245 commit 7624f65
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 56 deletions.
6 changes: 5 additions & 1 deletion ChatExample/ChatExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 0920;
LastUpgradeCheck = 0930;
ORGANIZATIONNAME = "Andrey Ivanov";
TargetAttributes = {
FB9EA92320614E2300E3FF45 = {
Expand Down Expand Up @@ -282,13 +282,15 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -339,13 +341,15 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down
75 changes: 56 additions & 19 deletions ChatExample/ChatExample/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@
<segue destination="LGg-GY-vP7" kind="show" id="HsO-Nd-FiP"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" textLabel="bWj-P4-OW7" style="IBUITableViewCellStyleDefault" id="P7G-27-qdQ">
<rect key="frame" x="0.0" y="123" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="P7G-27-qdQ" id="J6o-I9-PWF">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Embed" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="bWj-P4-OW7">
<rect key="frame" x="16" y="0.0" width="343" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="sTD-cH-6YX" kind="show" id="gzl-NH-7x6"/>
</connections>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
Expand All @@ -85,43 +105,57 @@
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</tabBar>
<connections>
<segue destination="ZTm-6m-m1n" kind="relationship" relationship="viewControllers" id="pna-hZ-JB6"/>
<segue destination="Sj9-Ac-pHW" kind="relationship" relationship="viewControllers" id="aEJ-hB-6tA"/>
</connections>
</tabBarController>
<placeholder placeholderIdentifier="IBFirstResponder" id="jpQ-gy-C7Q" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="742" y="989"/>
<point key="canvasLocation" x="742" y="1008"/>
</scene>
<!--Chat View Controller-->
<scene sceneID="gjs-cb-kls">
<!--View Controller-->
<scene sceneID="t4J-uw-Z1U">
<objects>
<viewController id="Sj9-Ac-pHW" customClass="ChatViewController" customModule="ChatExample" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="phq-JM-P46">
<viewController id="sTD-cH-6YX" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="oEa-8W-VCm">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<viewLayoutGuide key="safeArea" id="HM3-CI-svk"/>
<subviews>
<containerView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="EMN-nq-vm2">
<rect key="frame" x="0.0" y="0.0" width="375" height="527"/>
<connections>
<segue destination="Sj9-Ac-pHW" kind="embed" id="nGO-qT-EUX"/>
</connections>
</containerView>
</subviews>
<color key="backgroundColor" red="1" green="0.0" blue="0.50196081400000003" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="EMN-nq-vm2" firstAttribute="trailing" secondItem="H4m-4h-YG0" secondAttribute="trailing" id="Brr-4K-1ja"/>
<constraint firstItem="H4m-4h-YG0" firstAttribute="bottom" secondItem="EMN-nq-vm2" secondAttribute="bottom" constant="140" id="H9I-yA-KUQ"/>
<constraint firstItem="EMN-nq-vm2" firstAttribute="top" secondItem="oEa-8W-VCm" secondAttribute="top" id="Sej-xe-F2R"/>
<constraint firstItem="EMN-nq-vm2" firstAttribute="leading" secondItem="H4m-4h-YG0" secondAttribute="leading" id="pMD-x2-auT"/>
</constraints>
<viewLayoutGuide key="safeArea" id="H4m-4h-YG0"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="hBk-YS-k5X" userLabel="First Responder" sceneMemberID="firstResponder"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="HKk-sI-3kB" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1524" y="184"/>
<point key="canvasLocation" x="1809" y="-355"/>
</scene>
<!--Chat-->
<scene sceneID="wPl-gj-UfW">
<!--Item-->
<scene sceneID="gjs-cb-kls">
<objects>
<viewController id="ZTm-6m-m1n" customClass="ChatViewController" customModule="ChatExample" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="E1Z-Jm-55K">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<viewController id="Sj9-Ac-pHW" customClass="ChatViewController" customModule="ChatExample" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="phq-JM-P46">
<rect key="frame" x="0.0" y="0.0" width="375" height="527"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<viewLayoutGuide key="safeArea" id="fdb-AU-LLx"/>
<viewLayoutGuide key="safeArea" id="HM3-CI-svk"/>
</view>
<tabBarItem key="tabBarItem" title="Chat" id="Y2l-5X-caR"/>
<tabBarItem key="tabBarItem" title="Item" id="h30-k5-goz"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="t5s-s6-Scp" userLabel="First Responder" sceneMemberID="firstResponder"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="hBk-YS-k5X" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1524" y="988"/>
<point key="canvasLocation" x="1729" y="432"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="loI-pp-4ro">
Expand All @@ -140,4 +174,7 @@
<point key="canvasLocation" x="-209" y="184"/>
</scene>
</scenes>
<inferredMetricsTieBreakers>
<segue reference="nGO-qT-EUX"/>
</inferredMetricsTieBreakers>
</document>
11 changes: 5 additions & 6 deletions ChatExample/ChatExample/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ class ChatViewController: QMChatViewController {
self.finishSendingMessage(animated: true)
}

// override inputtoolbar

override func viewClass(forItem item: QBChatMessage) -> AnyClass {

if item.isDateDividerMessage {
Expand All @@ -60,17 +58,18 @@ class ChatViewController: QMChatViewController {
}
}



override func collectionView(_ collectionView: QMChatCollectionView!, dynamicSizeAt indexPath: IndexPath!, maxWidth: CGFloat) -> CGSize {
override func collectionView(_ collectionView: QMChatCollectionView!,
dynamicSizeAt indexPath: IndexPath!,
maxWidth: CGFloat) -> CGSize {

let size = TTTAttributedLabel.sizeThatFitsAttributedString(self.attributedString(forItem: self.chatDataSource.message(for: indexPath)),
withConstraints: CGSize(width:maxWidth, height:1000),
limitedToNumberOfLines: 0)
return size
}

override func collectionView(_ collectionView: QMChatCollectionView!, minWidthAt indexPath: IndexPath!) -> CGFloat {
override func collectionView(_ collectionView: QMChatCollectionView!,
minWidthAt indexPath: IndexPath!) -> CGFloat {

let msg = self.chatDataSource.message(for: indexPath)
let viewClass: AnyClass = self.viewClass(forItem: msg!)
Expand Down
16 changes: 12 additions & 4 deletions QMChatViewController/QMChatViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
#import "QMChatIncomingLinkPreviewCell.h"
#import "QMChatOutgoingLinkPreviewCell.h"

@interface QMChatViewController : UIViewController <QMChatCollectionViewDataSource, QMChatCollectionViewDelegateFlowLayout, UITextViewDelegate>
NS_ASSUME_NONNULL_BEGIN

@interface QMChatViewController : UIViewController <QMChatCollectionViewDataSource, QMChatCollectionViewDelegateFlowLayout, UITextViewDelegate>

@property (strong, nonatomic) QMChatDataSource *chatDataSource;
/**
Expand Down Expand Up @@ -108,7 +109,7 @@
*
* @return Configured attributed string.
*/
- (NSAttributedString *)attributedStringForItem:(QBChatMessage *)messageItem;
- (nullable NSAttributedString *)attributedStringForItem:(QBChatMessage *)messageItem;

/**
* Method to create chat message top label attributed string (Usually - chat message owner name). Have to be overriden in subclasses.
Expand All @@ -117,7 +118,7 @@
*
* @return Configured attributed string.
*/
- (NSAttributedString *)topLabelAttributedStringForItem:(QBChatMessage *)messageItem;
- (nullable NSAttributedString *)topLabelAttributedStringForItem:(QBChatMessage *)messageItem;

/**
* Method to create chat message bottom label attributed string (Usually - chat message date sent). Have to be overriden in subclasses.
Expand All @@ -126,7 +127,7 @@
*
* @return Configured attributed string.
*/
- (NSAttributedString *)bottomLabelAttributedStringForItem:(QBChatMessage *)messageItem;
- (nullable NSAttributedString *)bottomLabelAttributedStringForItem:(QBChatMessage *)messageItem;

/**
* Collection Cell View class for specific message. Have to be overriden in subclasses. Defaults cells are supplied with QMChatViewController.
Expand Down Expand Up @@ -250,6 +251,11 @@
*/
- (void)finishReceivingMessageAnimated:(BOOL)animated;

/**
Input bar start pos
*/
- (NSUInteger)inputToolBarStartPos;

/**
* Scrolls the collection view such that the bottom most cell is completely visible, above the `inputToolbar`.
*
Expand Down Expand Up @@ -280,3 +286,5 @@
- (void)viewWillAppear:(BOOL)animated NS_REQUIRES_SUPER;

@end

NS_ASSUME_NONNULL_END
17 changes: 6 additions & 11 deletions QMChatViewController/QMChatViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ - (void)viewDidLoad {
self.systemInputToolbar.frame = CGRectMake(0, 0, 0, kQMSystemInputToolbarDebugHeight);
self.systemInputToolbar.hostViewFrameChangeBlock = ^(UIView *view, BOOL animated) {

CGFloat pos = view.superview.frame.size.height - view.frame.origin.y ;
CGFloat pos = weakSelf.view.frame.size.height - [view.superview convertPoint:view.frame.origin toView:weakSelf.view].y;

if (weakSelf.inputToolbar.contentView.textView.isFirstResponder) {

if (view.superview.frame.origin.y > 0 && pos == 0) {
Expand All @@ -103,11 +103,11 @@ - (void)viewDidLoad {
}

const CGFloat v = [weakSelf inputToolBarStartPos];
if (pos < v ) {

if (pos < v || !view) {
pos = v;
}

[weakSelf setToolbarBottomConstraintValue:pos animated:animated];
};

Expand Down Expand Up @@ -282,11 +282,7 @@ - (void)chatDataSource:(QMChatDataSource *)chatDataSource willBeChangedWithMessa
#pragma mark - View lifecycle

- (NSUInteger)inputToolBarStartPos {

if (self.tabBarItem) {
return self.tabBarController.tabBar.frame.size.height;
}


return 0;
}

Expand Down Expand Up @@ -798,7 +794,6 @@ - (void)setToolbarBottomConstraintValue:(CGFloat)constraintValue animated:(BOOL)
self.toolbarBottomLayoutGuide.constant = constraintValue;

if (animated) {

self.navigationController.interactivePopGestureRecognizer.enabled = NO;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

Expand Down
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="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment version="2048" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<deployment version="2320" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -25,10 +25,10 @@
<rect key="frame" x="0.0" y="0.0" width="319" height="130"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="KnC-yv-rzb">
<rect key="frame" x="0.0" y="47.5" width="319" height="83.5"/>
<rect key="frame" x="0.0" y="47" width="319" height="84"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="bNF-b6-DLb">
<rect key="frame" x="16" y="20" width="135" height="44"/>
<rect key="frame" x="16" y="20.5" width="135" height="44"/>
<color key="backgroundColor" red="0.64313725489999995" green="0.66666666669999997" blue="0.70196078429999997" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="W5G-FE-DKL"/>
Expand All @@ -47,7 +47,7 @@
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Hjd-BD-U0M">
<rect key="frame" x="168" y="20" width="135" height="44"/>
<rect key="frame" x="168" y="20.5" width="135" height="44"/>
<color key="backgroundColor" red="0.0" green="0.74901960779999999" blue="0.15686274510000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="44" id="Rd3-Et-X1c"/>
Expand Down Expand Up @@ -76,7 +76,7 @@
</constraints>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" usesAttributedText="YES" lineBreakMode="tailTruncation" numberOfLines="3" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="xj9-MU-4a2" customClass="TTTAttributedLabel">
<rect key="frame" x="40" y="8" width="239" height="37.5"/>
<rect key="frame" x="40" y="8" width="239" height="37"/>
<color key="backgroundColor" red="0.0" green="0.77721782169999998" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" constant="239" id="5jt-T8-Upn"/>
Expand Down
Loading

0 comments on commit 7624f65

Please sign in to comment.