Skip to content

Commit

Permalink
Merge pull request #13 from PGSSoft/feature/keyboard_fixes
Browse files Browse the repository at this point in the history
Feature/keyboard fixes
  • Loading branch information
pgs-dkanak authored Oct 20, 2017
2 parents 2a17c08 + eab28f3 commit 5945df6
Show file tree
Hide file tree
Showing 11 changed files with 454 additions and 239 deletions.
8 changes: 7 additions & 1 deletion Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ extension ViewController: MessagesViewDelegate {
}

func didTapRightButton() {
let text = messagesView.inputText

let text = messagesView.inputText.trimmingCharacters(in: .whitespaces)

guard !text.isEmpty else {
return
}

TestData.exampleMessageText.append(text)
messagesView.refresh(scrollToLastMessage: true, animateLastMessage: true)
}
Expand Down
14 changes: 13 additions & 1 deletion MessagesView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0820;
LastUpgradeCheck = 0820;
LastUpgradeCheck = 0900;
ORGANIZATIONNAME = "pgs-dkanak";
TargetAttributes = {
055DA17B1E9296600091279C = {
Expand Down Expand Up @@ -471,15 +471,21 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = 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_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -524,15 +530,21 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = 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_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -55,6 +56,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
4 changes: 2 additions & 2 deletions MessagesView/BubbleImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class BubbleImage {
public lazy var middle: UIImage? = self.cropAndResize(slice: .middle)
public lazy var bottom: UIImage? = self.cropAndResize(slice: .bottom)

var flipped: BubbleImage {
public var flipped: BubbleImage {

let flippedImage = image.flipped
let flippedResizeInsets = insetsFlippedHorizontally(resizeInsets)
Expand Down Expand Up @@ -132,7 +132,7 @@ public class BubbleImage {
return result
}

public static func createTailPathIn(origin: CGPoint, size: CGSize) -> UIBezierPath {
private static func createTailPathIn(origin: CGPoint, size: CGSize) -> UIBezierPath {
let width = size.width
let height = size.height

Expand Down
33 changes: 12 additions & 21 deletions MessagesView/MessageEditorTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,20 @@

import UIKit

class MessageEditorTextView: UITextView {
class MessageEditorTextView: UITextField {

/*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
// Drawing code
}
*/

override func awakeFromNib() {
super.awakeFromNib()
setupTextView()
}

func setupTextView() {
self.backgroundColor = UIColor.yellow
}

func applySettings(settings: MessagesViewSettings) {
self.textColor = settings.textInputFieldTextColor
self.backgroundColor = settings.textInputFieldBackgroundColor
self.layer.cornerRadius = settings.textInputFieldCornerRadius

textColor = settings.textInputFieldTextColor
backgroundColor = settings.textInputFieldBackgroundColor
tintColor = settings.textInputTintColor
layer.cornerRadius = settings.textInputFieldCornerRadius
placeholder = settings.textInputFieldTextPlaceholderText

keyboardType = settings.keyboardType
keyboardAppearance = settings.keyboardAppearance
returnKeyType = settings.returnKeyType
enablesReturnKeyAutomatically = settings.enablesReturnKeyAutomatically
}

}
35 changes: 25 additions & 10 deletions MessagesView/MessagesInputToolbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,34 @@

import UIKit

class MessagesInputToolbar: UIToolbar {
class MessagesInputToolbar: UIView {

let toolbarContentView = MessagesToolbarContentView.fromNib()

/*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
// Drawing code
}
*/
var messageText : String {
return toolbarContentView.messageText
var leftButtonAction: ()->() {
get {
return toolbarContentView.leftButtonAction
}
set {
toolbarContentView.leftButtonAction = newValue
}
}
var rightButtonAction: ()->() {
get {
return toolbarContentView.rightButtonAction
}
set {
toolbarContentView.rightButtonAction = newValue
}
}

var inputText : String {
get {
return toolbarContentView.inputText
}
set {
toolbarContentView.inputText = newValue
}
}

var settings = MessagesViewSettings() {
Expand Down
21 changes: 17 additions & 4 deletions MessagesView/MessagesToolbarContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class MessagesToolbarContentView: UIView {
private var leftButtonEnabled: Bool = true
private var rightButtonEnabled: Bool = true

var leftButtonAction: () -> () = {}
var rightButtonAction: () -> () = {}

private var leftTintColor: UIColor {
return leftButtonEnabled ? settings.leftButtonTextColor : settings.leftButtonDisabledColor
}
Expand All @@ -57,7 +60,7 @@ class MessagesToolbarContentView: UIView {
@IBAction func didPressLeftButton(_ sender: AnyObject) {

if leftButtonEnabled {
settings.leftButtonAction()
leftButtonAction()
}

if settings.leftButtonHidesKeyboard {
Expand All @@ -68,7 +71,7 @@ class MessagesToolbarContentView: UIView {
@IBAction func didPressRightButton(_ sender: AnyObject) {

if rightButtonEnabled {
settings.rightButtonAction()
rightButtonAction()
}

if settings.rightButtonHidesKeyboard {
Expand All @@ -91,8 +94,13 @@ class MessagesToolbarContentView: UIView {
apply(settings: settings)
}
}
var messageText : String {
return messageEditorTextView.text
var inputText : String {
get {
return messageEditorTextView.text ?? ""
}
set {
messageEditorTextView.text = newValue
}
}

func righButton(show: Bool, animated: Bool) {
Expand Down Expand Up @@ -188,6 +196,11 @@ extension MessagesToolbarContentView : UITextFieldDelegate {
}

func textFieldShouldReturn(_ textField: UITextField) -> Bool {

if settings.shouldDoRightActionWithReturnKey {
didPressRightButton(textField)
}

return true
}

Expand Down
13 changes: 7 additions & 6 deletions MessagesView/MessagesToolbarContentView.xib
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="15G1217" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<?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">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -14,7 +15,7 @@
<rect key="frame" x="0.0" y="0.0" width="432" height="78"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="6Ec-dF-1Fn" customClass="UIImageView">
<view contentMode="scaleAspectFit" translatesAutoresizingMaskIntoConstraints="NO" id="6Ec-dF-1Fn" customClass="UIImageView">
<rect key="frame" x="5" y="23" width="32" height="32"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Left" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="amt-9f-7ms">
Expand All @@ -38,7 +39,7 @@
<outletCollection property="gestureRecognizers" destination="xhb-ke-ACy" appends="YES" id="02m-NP-wt6"/>
</connections>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="PQK-3g-SCZ" customClass="UIImageView">
<view contentMode="scaleAspectFit" translatesAutoresizingMaskIntoConstraints="NO" id="PQK-3g-SCZ" customClass="UIImageView">
<rect key="frame" x="395" y="23" width="32" height="32"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Right" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Su6-aD-T5D">
Expand All @@ -59,7 +60,7 @@
<outletCollection property="gestureRecognizers" destination="elv-KC-W68" appends="YES" id="LTt-wu-Dan"/>
</connections>
</view>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" text="HI there!" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="2fz-9A-LKF" customClass="MessageEditorTextView" customModule="MessagesView" customModuleProvider="target">
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="2fz-9A-LKF" customClass="MessageEditorTextView" customModule="MessagesView" customModuleProvider="target">
<rect key="frame" x="45" y="23" width="342" height="32"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
Expand Down
Loading

0 comments on commit 5945df6

Please sign in to comment.