Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 7418ca581c2e0f390ac3d8da4bb8888c4bc25faa

COCOAPODS: 1.8.4
COCOAPODS: 1.9.3
2 changes: 1 addition & 1 deletion Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

204 changes: 103 additions & 101 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

40 changes: 37 additions & 3 deletions Example/ReactionButton/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,20 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="wds-l2-yp1">
<rect key="frame" x="161" y="456" width="53" height="30"/>
<state key="normal" title="Present"/>
<connections>
<action selector="presentButtonTappedWithSender:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="Nsj-FG-pP3"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" systemColor="tertiarySystemBackgroundColor"/>
<constraints>
<constraint firstItem="Xat-mh-mMx" firstAttribute="centerY" secondItem="kh9-bI-dsS" secondAttribute="centerY" multiplier="1.3" id="Awu-hO-FVu"/>
<constraint firstItem="MKJ-na-Ra4" firstAttribute="width" secondItem="kh9-bI-dsS" secondAttribute="width" multiplier="0.8" id="JCM-b1-ezb"/>
<constraint firstItem="wds-l2-yp1" firstAttribute="centerX" secondItem="kh9-bI-dsS" secondAttribute="centerX" id="Zb2-Hq-DZc"/>
<constraint firstItem="wds-l2-yp1" firstAttribute="top" secondItem="Xat-mh-mMx" secondAttribute="bottom" constant="7.5" id="eVh-vt-bKn"/>
<constraint firstItem="Xat-mh-mMx" firstAttribute="firstBaseline" secondItem="MKJ-na-Ra4" secondAttribute="baseline" constant="100" id="liC-Dc-vGU"/>
<constraint firstItem="MKJ-na-Ra4" firstAttribute="centerX" secondItem="kh9-bI-dsS" secondAttribute="centerX" id="ui3-xQ-YC9"/>
<constraint firstItem="Xat-mh-mMx" firstAttribute="centerX" secondItem="kh9-bI-dsS" secondAttribute="centerX" id="vpJ-gs-Yt7"/>
Expand Down Expand Up @@ -77,15 +86,15 @@
<color key="selectedImageTintColor" systemColor="systemYellowColor"/>
</tabBar>
<connections>
<segue destination="fX9-1j-LLq" kind="relationship" relationship="viewControllers" id="pa3-Hd-ZD9"/>
<segue destination="OuN-q0-GPo" kind="relationship" relationship="viewControllers" id="pa3-Hd-ZD9"/>
<segue destination="vXZ-lx-hvc" kind="relationship" relationship="viewControllers" id="UYY-ij-xub"/>
</connections>
</tabBarController>
<placeholder placeholderIdentifier="IBFirstResponder" id="bqo-Zn-L6X" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-910" y="-266"/>
</scene>
<!--Table-->
<!--Sample Table View Controller-->
<scene sceneID="uHY-zy-B7R">
<objects>
<tableViewController id="fX9-1j-LLq" customClass="SampleTableViewController" customModule="ReactionButton_Example" customModuleProvider="target" sceneMemberID="viewController">
Expand Down Expand Up @@ -144,10 +153,35 @@
<outlet property="delegate" destination="fX9-1j-LLq" id="T3b-jW-0Ia"/>
</connections>
</tableView>
<tabBarItem key="tabBarItem" title="Table" image="tablecells.fill" catalog="system" selectedImage="tablecells.fill" id="r65-4y-N1l"/>
<navigationItem key="navigationItem" id="Ezy-Yi-6TW">
<barButtonItem key="leftBarButtonItem" title="Cancel" id="Apz-bg-7Zn">
<connections>
<action selector="cancelButtonTappedWithSender:" destination="fX9-1j-LLq" id="guo-Ya-CEU"/>
</connections>
</barButtonItem>
</navigationItem>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="nOi-7z-pzg" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1076" y="-593.25337331334333"/>
</scene>
<!--Table-->
<scene sceneID="kzA-P0-qaa">
<objects>
<navigationController storyboardIdentifier="TableNavigation" automaticallyAdjustsScrollViewInsets="NO" id="OuN-q0-GPo" sceneMemberID="viewController">
<tabBarItem key="tabBarItem" title="Table" image="tablecells.fill" catalog="system" selectedImage="tablecells.fill" id="r65-4y-N1l"/>
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="i6T-d9-9Mg">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="fX9-1j-LLq" kind="relationship" relationship="rootViewController" id="QD2-zg-Vof"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="lwp-3Y-rLh" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="136.80000000000001" y="-593.25337331334333"/>
</scene>
</scenes>
Expand Down
15 changes: 15 additions & 0 deletions Example/ReactionButton/SampleTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ import ReactionButton

final class SampleTableViewController: UITableViewController {

var canShowCancelButton: Bool = false

override func viewDidLoad() {
super.viewDidLoad()

if !canShowCancelButton {
self.navigationItem.leftBarButtonItem = nil
}
}

override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
Expand All @@ -23,6 +33,11 @@ final class SampleTableViewController: UITableViewController {
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
return tableView.dequeueReusableCell(withIdentifier: "SampleCell", for: indexPath)
}

//MARK: IBActions
@IBAction func cancelButtonTapped(sender: UIBarButtonItem) {
self.dismiss(animated: true, completion: nil)
}

}

Expand Down
7 changes: 7 additions & 0 deletions Example/ReactionButton/SampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ final class SampleViewController: UIViewController {
selectorView.dataSource = self
}

//MARK: IBActions
@IBAction func presentButtonTapped(sender: UIButton) {
let navController = (self.storyboard!.instantiateViewController(identifier: "TableNavigation") as! UINavigationController)
let simpleTableController = (navController.viewControllers.first as! SampleTableViewController)
simpleTableController.canShowCancelButton = true
self.present(navController, animated: true, completion: nil)
}
}

// MARK: ReactionButtonDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ import UIKit
extension ReactionButton.Config {

func rect(items: Int, originalPos: CGPoint, trait: UITraitCollection) -> CGRect {
var originalPos = CGPoint(x: originalPos.x, y: originalPos.y - heightForSize - 10)
let originalPos = CGPoint(x: originalPos.x, y: originalPos.y - heightForSize - 10)
let option = CGFloat(items)
let width = (option + 1) * spacing + self.size * option

if trait.horizontalSizeClass == .compact && trait.verticalSizeClass == .regular {
originalPos.x = (UIScreen.main.bounds.width - width) / 2
}

return CGRect(origin: originalPos, size: CGSize(width: width, height: heightForSize))
}

Expand Down
12 changes: 11 additions & 1 deletion Sources/ReactionButton/ReactionButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,17 @@ open class ReactionButton: UIButton {
}

private var rootView: UIView? {
UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController?.view
var currentVc = UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController
while let presentedVc = currentVc?.presentedViewController {
if let navVc = (presentedVc as? UINavigationController)?.viewControllers.last {
currentVc = navVc
} else if let tabVc = (presentedVc as? UITabBarController)?.selectedViewController {
currentVc = tabVc
} else {
currentVc = presentedVc
}
}
return currentVc?.view
}

// MARK: - View lifecycle
Expand Down