Skip to content

Commit

Permalink
Merge pull request #13 from jeffreality/doneButton
Browse files Browse the repository at this point in the history
Added a done button and moved the delete to the left-hand side
  • Loading branch information
isaced authored Jul 9, 2018
2 parents 4e9479c + d24b678 commit b2987b5
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 40 deletions.
24 changes: 7 additions & 17 deletions Example/ISEmojiViewExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
0DEA0E531DD20B3B00B1B151 /* Frameworks */,
0DEA0E541DD20B3B00B1B151 /* Resources */,
374B14ED04AC84B4D6A8BAB1 /* [CP] Embed Pods Frameworks */,
2235FE1A5907F3DAE6F94BE0 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -164,28 +163,16 @@
files = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-ISEmojiViewExample-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
2235FE1A5907F3DAE6F94BE0 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-ISEmojiViewExample/Pods-ISEmojiViewExample-resources.sh\"\n";
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
374B14ED04AC84B4D6A8BAB1 /* [CP] Embed Pods Frameworks */ = {
Expand All @@ -194,9 +181,12 @@
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-ISEmojiViewExample/Pods-ISEmojiViewExample-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/ISEmojiView/ISEmojiView.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ISEmojiView.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down
4 changes: 4 additions & 0 deletions Example/ISEmojiViewExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,9 @@ class ViewController: UIViewController, ISEmojiViewDelegate {
func emojiViewDidPressDeleteButton(emojiView: ISEmojiView) {
textView.deleteBackward()
}

func emojiViewDidPressDoneButton(emojiView: ISEmojiView) {
textView.resignFirstResponder()
}
}

6 changes: 3 additions & 3 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- ISEmojiView (0.0.4)
- ISEmojiView (0.0.6)

DEPENDENCIES:
- ISEmojiView (from `../`)
Expand All @@ -9,8 +9,8 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
ISEmojiView: 0771acaccd1897c91b77810a3ca831db8614957b
ISEmojiView: 41417cd289acdbcaf69bce2e65ca8f1f3fe058c4

PODFILE CHECKSUM: 87a1004beddffa4d5c3892af0de2a7eb26a2e5d3

COCOAPODS: 1.2.1
COCOAPODS: 1.5.3
64 changes: 44 additions & 20 deletions Source/Classes/ISEmojiView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public protocol ISEmojiViewDelegate: class {
///
/// - Parameter emojiView: the emoji view
func emojiViewDidPressDeleteButton(emojiView: ISEmojiView)


/// is finished typing
///
/// - Parameter emojiView: the emoji view
func emojiViewDidPressDoneButton(emojiView: ISEmojiView)
}

fileprivate let EmojiSize = CGSize(width: 45, height: 35)
Expand All @@ -34,7 +40,7 @@ fileprivate let ISMainBackgroundColor = UIColor(red: 249/255.0, green: 249/255.0

/// A emoji keyboard view
public class ISEmojiView: UIView, UICollectionViewDataSource, UICollectionViewDelegate {

/// the delegate for callback
public weak var delegate: ISEmojiViewDelegate?

Expand Down Expand Up @@ -84,6 +90,12 @@ public class ISEmojiView: UIView, UICollectionViewDataSource, UICollectionViewDe
button.tintColor = .lightGray
return button
}()
public var doneButton: UIButton = {
let button = UIButton(type: .system)
button.setTitle("", for: .normal)
button.tintColor = .lightGray
return button
}()

public var emojis: [[String]]!

Expand All @@ -103,29 +115,29 @@ public class ISEmojiView: UIView, UICollectionViewDataSource, UICollectionViewDe
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}

@available(iOS 11.0, *)
public override func safeAreaInsetsDidChange() {
super.safeAreaInsetsDidChange()

if let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {

var sectionInset = collectionInset
sectionInset.bottom += safeAreaInsets.bottom

layout.sectionInset = sectionInset
layout.invalidateLayout()
}

setNeedsLayout()

invalidateIntrinsicContentSize()
}

public override func layoutSubviews() {
updateControlLayout()
}

private func setupUI() {
frame = defaultFrame

Expand All @@ -141,16 +153,20 @@ public class ISEmojiView: UIView, UICollectionViewDataSource, UICollectionViewDe
addSubview(collectionView)
collectionView.reloadData()

// DeleteButton
deleteButton.addTarget(self, action: #selector(deleteButtonPressed), for: .touchUpInside)
addSubview(deleteButton)

// PageControl
pageControl.addTarget(self, action: #selector(pageControlTouched), for: .touchUpInside)
pageControl.pageIndicatorTintColor = UIColor(red: 229/255.0, green: 229/255.0, blue: 229/255.0, alpha: 1)
pageControl.currentPageIndicatorTintColor = UIColor(red: 153/255.0, green: 153/255.0, blue: 153/255.0, alpha: 1)
pageControl.autoresizingMask = [.flexibleTopMargin, .flexibleLeftMargin, .flexibleRightMargin]
addSubview(pageControl)

// DeleteButton
deleteButton.addTarget(self, action: #selector(deleteButtonPressed), for: .touchUpInside)
addSubview(deleteButton)
// DoneButton
doneButton.addTarget(self, action: #selector(doneButtonPressed), for: .touchUpInside)
addSubview(doneButton)

// Long press to pop preview
let emojiLongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(emojiLongPressHandle))
Expand All @@ -159,27 +175,30 @@ public class ISEmojiView: UIView, UICollectionViewDataSource, UICollectionViewDe
}

private func updateControlLayout() {

frame.origin.x = defaultFrame.origin.x
frame.size = defaultFrame.size


// update delete button
deleteButton.frame = CGRect(x: 12, y: frame.height - 40 - safeAreaBottomInset, width: 40, height: 40)

// update page control
let pageCount = collectionView.numberOfSections
let pageControlSizes = pageControl.size(forNumberOfPages: pageCount)

var pageControlFrame = CGRect(x: frame.midX - pageControlSizes.width / 2.0,
y: frame.height - pageControlSizes.height,
width: pageControlSizes.width,
height: pageControlSizes.height)

pageControlFrame.origin.y -= safeAreaBottomInset

pageControl.frame = pageControlFrame

pageControl.numberOfPages = pageCount

// update delete button
deleteButton.frame = CGRect(x: frame.width - 48, y: frame.height - 40 - safeAreaBottomInset, width: 40, height: 40)
// update done button
doneButton.frame = CGRect(x: frame.width - 48, y: frame.height - 40 - safeAreaBottomInset, width: 40, height: 40)
}

//MARK: LongPress
Expand Down Expand Up @@ -254,6 +273,10 @@ public class ISEmojiView: UIView, UICollectionViewDataSource, UICollectionViewDe
self.delegate?.emojiViewDidPressDeleteButton(emojiView: self)
}

@objc private func doneButtonPressed(sender: UIButton) {
self.delegate?.emojiViewDidPressDoneButton(emojiView: self)
}

@objc private func pageControlTouched(sender: UIPageControl) {
var bounds = collectionView.bounds
bounds.origin.x = bounds.width * CGFloat(sender.currentPage)
Expand Down Expand Up @@ -411,3 +434,4 @@ fileprivate class ISEmojiPopView: UIView {
self.emojiLabel.text = emoji
}
}

0 comments on commit b2987b5

Please sign in to comment.