Skip to content

Commit 5945df6

Browse files
authored
Merge pull request #13 from PGSSoft/feature/keyboard_fixes
Feature/keyboard fixes
2 parents 2a17c08 + eab28f3 commit 5945df6

File tree

11 files changed

+454
-239
lines changed

11 files changed

+454
-239
lines changed

Demo/ViewController.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ extension ViewController: MessagesViewDelegate {
4242
}
4343

4444
func didTapRightButton() {
45-
let text = messagesView.inputText
45+
46+
let text = messagesView.inputText.trimmingCharacters(in: .whitespaces)
47+
48+
guard !text.isEmpty else {
49+
return
50+
}
51+
4652
TestData.exampleMessageText.append(text)
4753
messagesView.refresh(scrollToLastMessage: true, animateLastMessage: true)
4854
}

MessagesView.xcodeproj/project.pbxproj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@
290290
isa = PBXProject;
291291
attributes = {
292292
LastSwiftUpdateCheck = 0820;
293-
LastUpgradeCheck = 0820;
293+
LastUpgradeCheck = 0900;
294294
ORGANIZATIONNAME = "pgs-dkanak";
295295
TargetAttributes = {
296296
055DA17B1E9296600091279C = {
@@ -471,15 +471,21 @@
471471
CLANG_CXX_LIBRARY = "libc++";
472472
CLANG_ENABLE_MODULES = YES;
473473
CLANG_ENABLE_OBJC_ARC = YES;
474+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
474475
CLANG_WARN_BOOL_CONVERSION = YES;
476+
CLANG_WARN_COMMA = YES;
475477
CLANG_WARN_CONSTANT_CONVERSION = YES;
476478
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
477479
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
478480
CLANG_WARN_EMPTY_BODY = YES;
479481
CLANG_WARN_ENUM_CONVERSION = YES;
480482
CLANG_WARN_INFINITE_RECURSION = YES;
481483
CLANG_WARN_INT_CONVERSION = YES;
484+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
485+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
482486
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
487+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
488+
CLANG_WARN_STRICT_PROTOTYPES = YES;
483489
CLANG_WARN_SUSPICIOUS_MOVE = YES;
484490
CLANG_WARN_UNREACHABLE_CODE = YES;
485491
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -524,15 +530,21 @@
524530
CLANG_CXX_LIBRARY = "libc++";
525531
CLANG_ENABLE_MODULES = YES;
526532
CLANG_ENABLE_OBJC_ARC = YES;
533+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
527534
CLANG_WARN_BOOL_CONVERSION = YES;
535+
CLANG_WARN_COMMA = YES;
528536
CLANG_WARN_CONSTANT_CONVERSION = YES;
529537
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
530538
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
531539
CLANG_WARN_EMPTY_BODY = YES;
532540
CLANG_WARN_ENUM_CONVERSION = YES;
533541
CLANG_WARN_INFINITE_RECURSION = YES;
534542
CLANG_WARN_INT_CONVERSION = YES;
543+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
544+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
535545
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
546+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
547+
CLANG_WARN_STRICT_PROTOTYPES = YES;
536548
CLANG_WARN_SUSPICIOUS_MOVE = YES;
537549
CLANG_WARN_UNREACHABLE_CODE = YES;
538550
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;

MessagesView.xcodeproj/xcshareddata/xcschemes/MessagesView.xcscheme

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0820"
3+
LastUpgradeVersion = "0900"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,6 +26,7 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
language = ""
2930
shouldUseLaunchSchemeArgsEnv = "YES">
3031
<Testables>
3132
<TestableReference
@@ -55,6 +56,7 @@
5556
buildConfiguration = "Debug"
5657
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
5758
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
59+
language = ""
5860
launchStyle = "0"
5961
useCustomWorkingDirectory = "NO"
6062
ignoresPersistentStateOnLaunch = "NO"

MessagesView/BubbleImage.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class BubbleImage {
2727
public lazy var middle: UIImage? = self.cropAndResize(slice: .middle)
2828
public lazy var bottom: UIImage? = self.cropAndResize(slice: .bottom)
2929

30-
var flipped: BubbleImage {
30+
public var flipped: BubbleImage {
3131

3232
let flippedImage = image.flipped
3333
let flippedResizeInsets = insetsFlippedHorizontally(resizeInsets)
@@ -132,7 +132,7 @@ public class BubbleImage {
132132
return result
133133
}
134134

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

MessagesView/MessageEditorTextView.swift

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,20 @@
88

99
import UIKit
1010

11-
class MessageEditorTextView: UITextView {
11+
class MessageEditorTextView: UITextField {
1212

13-
/*
14-
// Only override draw() if you perform custom drawing.
15-
// An empty implementation adversely affects performance during animation.
16-
override func draw(_ rect: CGRect) {
17-
// Drawing code
18-
}
19-
*/
20-
21-
override func awakeFromNib() {
22-
super.awakeFromNib()
23-
setupTextView()
24-
}
25-
26-
func setupTextView() {
27-
self.backgroundColor = UIColor.yellow
28-
}
29-
3013
func applySettings(settings: MessagesViewSettings) {
31-
self.textColor = settings.textInputFieldTextColor
32-
self.backgroundColor = settings.textInputFieldBackgroundColor
33-
self.layer.cornerRadius = settings.textInputFieldCornerRadius
14+
15+
textColor = settings.textInputFieldTextColor
16+
backgroundColor = settings.textInputFieldBackgroundColor
17+
tintColor = settings.textInputTintColor
18+
layer.cornerRadius = settings.textInputFieldCornerRadius
19+
placeholder = settings.textInputFieldTextPlaceholderText
20+
21+
keyboardType = settings.keyboardType
22+
keyboardAppearance = settings.keyboardAppearance
23+
returnKeyType = settings.returnKeyType
24+
enablesReturnKeyAutomatically = settings.enablesReturnKeyAutomatically
3425
}
3526

3627
}

MessagesView/MessagesInputToolbar.swift

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,34 @@
88

99
import UIKit
1010

11-
class MessagesInputToolbar: UIToolbar {
11+
class MessagesInputToolbar: UIView {
1212

1313
let toolbarContentView = MessagesToolbarContentView.fromNib()
1414

15-
/*
16-
// Only override draw() if you perform custom drawing.
17-
// An empty implementation adversely affects performance during animation.
18-
override func draw(_ rect: CGRect) {
19-
// Drawing code
20-
}
21-
*/
22-
var messageText : String {
23-
return toolbarContentView.messageText
15+
var leftButtonAction: ()->() {
16+
get {
17+
return toolbarContentView.leftButtonAction
18+
}
19+
set {
20+
toolbarContentView.leftButtonAction = newValue
21+
}
22+
}
23+
var rightButtonAction: ()->() {
24+
get {
25+
return toolbarContentView.rightButtonAction
26+
}
27+
set {
28+
toolbarContentView.rightButtonAction = newValue
29+
}
30+
}
31+
32+
var inputText : String {
33+
get {
34+
return toolbarContentView.inputText
35+
}
36+
set {
37+
toolbarContentView.inputText = newValue
38+
}
2439
}
2540

2641
var settings = MessagesViewSettings() {

MessagesView/MessagesToolbarContentView.swift

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ class MessagesToolbarContentView: UIView {
3434
private var leftButtonEnabled: Bool = true
3535
private var rightButtonEnabled: Bool = true
3636

37+
var leftButtonAction: () -> () = {}
38+
var rightButtonAction: () -> () = {}
39+
3740
private var leftTintColor: UIColor {
3841
return leftButtonEnabled ? settings.leftButtonTextColor : settings.leftButtonDisabledColor
3942
}
@@ -57,7 +60,7 @@ class MessagesToolbarContentView: UIView {
5760
@IBAction func didPressLeftButton(_ sender: AnyObject) {
5861

5962
if leftButtonEnabled {
60-
settings.leftButtonAction()
63+
leftButtonAction()
6164
}
6265

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

7073
if rightButtonEnabled {
71-
settings.rightButtonAction()
74+
rightButtonAction()
7275
}
7376

7477
if settings.rightButtonHidesKeyboard {
@@ -91,8 +94,13 @@ class MessagesToolbarContentView: UIView {
9194
apply(settings: settings)
9295
}
9396
}
94-
var messageText : String {
95-
return messageEditorTextView.text
97+
var inputText : String {
98+
get {
99+
return messageEditorTextView.text ?? ""
100+
}
101+
set {
102+
messageEditorTextView.text = newValue
103+
}
96104
}
97105

98106
func righButton(show: Bool, animated: Bool) {
@@ -188,6 +196,11 @@ extension MessagesToolbarContentView : UITextFieldDelegate {
188196
}
189197

190198
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
199+
200+
if settings.shouldDoRightActionWithReturnKey {
201+
didPressRightButton(textField)
202+
}
203+
191204
return true
192205
}
193206

MessagesView/MessagesToolbarContentView.xib

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<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">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
33
<device id="retina4_7" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
66
<dependencies>
7-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
7+
<deployment identifier="iOS"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
89
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
910
</dependencies>
1011
<objects>
@@ -14,7 +15,7 @@
1415
<rect key="frame" x="0.0" y="0.0" width="432" height="78"/>
1516
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1617
<subviews>
17-
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="6Ec-dF-1Fn" customClass="UIImageView">
18+
<view contentMode="scaleAspectFit" translatesAutoresizingMaskIntoConstraints="NO" id="6Ec-dF-1Fn" customClass="UIImageView">
1819
<rect key="frame" x="5" y="23" width="32" height="32"/>
1920
<subviews>
2021
<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">
@@ -38,7 +39,7 @@
3839
<outletCollection property="gestureRecognizers" destination="xhb-ke-ACy" appends="YES" id="02m-NP-wt6"/>
3940
</connections>
4041
</view>
41-
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="PQK-3g-SCZ" customClass="UIImageView">
42+
<view contentMode="scaleAspectFit" translatesAutoresizingMaskIntoConstraints="NO" id="PQK-3g-SCZ" customClass="UIImageView">
4243
<rect key="frame" x="395" y="23" width="32" height="32"/>
4344
<subviews>
4445
<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">
@@ -59,7 +60,7 @@
5960
<outletCollection property="gestureRecognizers" destination="elv-KC-W68" appends="YES" id="LTt-wu-Dan"/>
6061
</connections>
6162
</view>
62-
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" text="HI there!" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="2fz-9A-LKF" customClass="MessageEditorTextView" customModule="MessagesView" customModuleProvider="target">
63+
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="2fz-9A-LKF" customClass="MessageEditorTextView" customModule="MessagesView" customModuleProvider="target">
6364
<rect key="frame" x="45" y="23" width="342" height="32"/>
6465
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
6566
<constraints>

0 commit comments

Comments
 (0)