Skip to content

Commit

Permalink
Merge pull request #8 from pgs-dkanak/feature/scroll_fix
Browse files Browse the repository at this point in the history
Added new settings with functionality
  • Loading branch information
pgs-dkanak authored Apr 18, 2017
2 parents 0089101 + 8fcfe67 commit a7ce188
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 95 deletions.
21 changes: 7 additions & 14 deletions Demo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="15G1217" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12118" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12086"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -22,24 +21,18 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="25Z-aw-jBj" customClass="MessagesView" customModule="MessagesView">
<rect key="frame" x="0.0" y="0.0" width="375" height="409"/>
<rect key="frame" x="0.0" y="20" width="375" height="519"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="image" keyPath="rightButtonBackgroundImage" value="bubble_orange"/>
<userDefinedRuntimeAttribute type="string" keyPath="rightButtonText" value=" "/>
<userDefinedRuntimeAttribute type="color" keyPath="rightButtonTextColor">
<color key="value" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="rightButtonBackgroundColor">
<color key="value" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="backgroundColor" red="0.94117647058823528" green="0.95686274509803915" blue="0.94901960784313721" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="25Z-aw-jBj" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="GGl-8Z-VKD"/>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="25Z-aw-jBj" secondAttribute="bottom" constant="258" id="YWb-V3-Flr"/>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="25Z-aw-jBj" secondAttribute="bottom" constant="128" id="YWb-V3-Flr"/>
<constraint firstItem="25Z-aw-jBj" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" id="Ygx-82-ybx"/>
<constraint firstItem="25Z-aw-jBj" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="bws-AH-jdv"/>
<constraint firstAttribute="trailing" secondItem="25Z-aw-jBj" secondAttribute="trailing" id="jsy-dG-gY5"/>
</constraints>
Expand Down
13 changes: 6 additions & 7 deletions Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

messagesView.delegate = self
messagesView.dataSource = self

addCustomMessageBubbles()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.

override func viewDidAppear(_ animated: Bool) {
messagesView.scrollToLastMessage(animated: false)
}

func addCustomMessageBubbles() {
Expand Down Expand Up @@ -72,7 +71,7 @@ extension ViewController: MessagesViewDelegate {
func didTapRightButton() {
let text = messagesView.inputText
TestData.exampleMessageText.append(text)
messagesView.refresh()
messagesView.refresh(scrollToLastMessage: true)
}
}

Expand Down
6 changes: 4 additions & 2 deletions MessagesView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 36CHZQXF4C;
INFOPLIST_FILE = Demo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.pgs.Demo;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -449,6 +450,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 36CHZQXF4C;
INFOPLIST_FILE = Demo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.pgs.Demo;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -497,7 +499,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.2;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -544,7 +546,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.2;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand Down
78 changes: 49 additions & 29 deletions MessagesView/MessagesToolbarContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ import UIKit

class MessagesToolbarContentView: UIView {

/*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
// Drawing code
}
*/
@IBOutlet weak var topSeparatorLineView: UIView!
@IBOutlet weak var topSeparatorLineViewHeightConstraint: NSLayoutConstraint!

Expand All @@ -38,6 +31,17 @@ class MessagesToolbarContentView: UIView {
private var originalRightButtonContainerViewMargin = CGFloat(0)
private var originalRightButtonContainerViewWidth = CGFloat(0)

private var leftButtonEnabled: Bool = true
private var rightButtonEnabled: Bool = true

private var leftTintColor: UIColor {
return leftButtonEnabled ? settings.leftButtonTextColor : settings.leftButtonDisabledColor
}

private var rightTintColor: UIColor {
return rightButtonEnabled ? settings.rightButtonTextColor : settings.rightButtonDisabledColor
}

override func awakeFromNib() {
super.awakeFromNib()
saveOriginalConstraintValues()
Expand All @@ -50,16 +54,24 @@ class MessagesToolbarContentView: UIView {
originalRightButtonContainerViewWidth = rightButtonContainerViewWidthConstraint.constant
}

@IBAction func didPressRightButton(_ sender: AnyObject) {
settings.rightButtonAction()
if settings.rightButtonHidesKeyboard {
@IBAction func didPressLeftButton(_ sender: AnyObject) {

if leftButtonEnabled {
settings.leftButtonAction()
}

if settings.leftButtonHidesKeyboard {
messageEditorTextView.resignFirstResponder()
}
}

@IBAction func didPressLeftButton(_ sender: AnyObject) {
settings.leftButtonAction()
if settings.leftButtonHidesKeyboard {
@IBAction func didPressRightButton(_ sender: AnyObject) {

if rightButtonEnabled {
settings.rightButtonAction()
}

if settings.rightButtonHidesKeyboard {
messageEditorTextView.resignFirstResponder()
}
}
Expand Down Expand Up @@ -89,6 +101,20 @@ class MessagesToolbarContentView: UIView {
move(view: self.leftButtonContainerView, animated: animated, constraint: self.leftButtonContainerViewLeadingConstraint, value: destination.margin, alpha: destination.alpha)
}

func setLeftButton(enabled: Bool) {
leftButtonEnabled = enabled

leftButtonLabel.textColor = leftTintColor
leftButtonContainerView.tintColor = leftTintColor
}

func setRightButton(enabled: Bool) {
rightButtonEnabled = enabled

rightButtonLabel.textColor = rightTintColor
rightButtonContainerView.tintColor = rightTintColor
}

private func calculateDestination(side: Side, show: Bool) -> (margin: CGFloat, alpha: CGFloat) {
let xMargin: CGFloat
let alpha: CGFloat
Expand All @@ -110,7 +136,7 @@ class MessagesToolbarContentView: UIView {
return (xMargin, alpha)
}

private func move( view: UIView, animated: Bool, constraint: NSLayoutConstraint, value: CGFloat, alpha: CGFloat) {
private func move(view: UIView, animated: Bool, constraint: NSLayoutConstraint, value: CGFloat, alpha: CGFloat) {
let performTransition = {
constraint.constant = value
view.alpha = alpha
Expand All @@ -127,7 +153,7 @@ class MessagesToolbarContentView: UIView {
}
}

func apply(settings: MessagesViewSettings) {
private func apply(settings: MessagesViewSettings) {
messageEditorTextView.applySettings(settings: settings)

backgroundColor = settings.inputToolbarBackgroundColor
Expand All @@ -137,37 +163,31 @@ class MessagesToolbarContentView: UIView {
topSeparatorLineViewHeightConstraint.constant = settings.textInputFieldTopSeparatorLineHeight

leftButtonLabel.text = settings.leftButtonText
leftButtonLabel.textColor = settings.leftButtonTextColor
leftButtonLabel.textColor = leftTintColor
leftButtonContainerView.tintColor = leftTintColor
leftButtonContainerView.backgroundColor = settings.leftButtonBackgroundColor
leftButtonContainerView.image = settings.leftButtonBackgroundImage
leftButtonContainerView.image = settings.leftButtonBackgroundImage?.withRenderingMode(.alwaysTemplate)
leftButtonContainerView.layer.cornerRadius = settings.leftButtonCornerRadius

rightButtonLabel.text = settings.rightButtonText
rightButtonLabel.textColor = settings.rightButtonTextColor
rightButtonLabel.textColor = rightTintColor
rightButtonContainerView.tintColor = rightTintColor
rightButtonContainerView.backgroundColor = settings.rightButtonBackgroundColor
rightButtonContainerView.image = settings.rightButtonBackgroundImage
rightButtonContainerView.layer.cornerRadius = settings.rightButtonCornerRadius
rightButtonContainerView.image = settings.rightButtonBackgroundImage?.withRenderingMode(.alwaysTemplate)
rightButtonContainerView.layer.cornerRadius = settings.rightButtonCornerRadius
}
}

extension MessagesToolbarContentView : UITextFieldDelegate {
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
#if DEBUG
print(#function)
#endif
return true
}

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
#if DEBUG
print(#function)
#endif
return true
}

func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
#if DEBUG
print(#function)
#endif
return true
}
}
Expand Down
Loading

0 comments on commit a7ce188

Please sign in to comment.