Skip to content

Commit

Permalink
Merge pull request #19 from KarimEbrahemAbdelaziz/support_rtl_in_swif…
Browse files Browse the repository at this point in the history
…tymenu

Support RTL in swiftymenu
  • Loading branch information
KarimEbrahemAbdelaziz authored Jul 13, 2020
2 parents ad706c7 + 6560452 commit 1c5846b
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 20 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.6.4] - 2020-07-13
### Changed
- Update SnapKit version.

### Fixed
- Support RTL in SwiftyMenu.

## [0.6.3] - 2020-04-06
### Added
- Allow Changing separator color.
Expand Down
12 changes: 6 additions & 6 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PODS:
- SnapKit (4.2.0)
- SwiftyMenu (0.6.2):
- SnapKit (~> 4.2.0)
- SnapKit (5.0.1)
- SwiftyMenu (0.6.4):
- SnapKit (~> 5.0.1)

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

SPEC CHECKSUMS:
SnapKit: fe8a619752f3f27075cc9a90244d75c6c3f27e2a
SwiftyMenu: 039a1fe10f32cf91abb9257c63663721abb0140b
SnapKit: 97b92857e3df3a0c71833cce143274bf6ef8e5eb
SwiftyMenu: 78a70edddb323f6b671ace1bd47853629cf040a9

PODFILE CHECKSUM: e76fbe8ebeca450e6d7f72e5036d5d85d327d6d2

COCOAPODS: 1.8.4
COCOAPODS: 1.9.3
2 changes: 1 addition & 1 deletion Example/SwiftyMenu/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ extension String: SwiftyMenuDisplayable {
return self
}

public var retrivableValue: Any {
public var retrievableValue: Any {
return self
}
}
Expand Down
4 changes: 2 additions & 2 deletions SwiftyMenu.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'SwiftyMenu'
s.version = '0.6.3'
s.version = '0.6.4'
s.summary = 'SwiftyMenu is simple drop down menu for iOS.'

# This description is used to generate tags and improve search results.
Expand All @@ -34,7 +34,7 @@ This drop down is to overcome the loss of usability and user experience due to t
s.source_files = 'SwiftyMenu/Classes/**/*'
s.resources = 'SwiftyMenu/Assets/*'

s.dependency 'SnapKit', '~> 4.2.0'
s.dependency 'SnapKit', '~> 5.0.1'

# s.resource_bundles = {
# 'SwiftyMenu' => ['SwiftyMenu/Assets/*.png']
Expand Down
2 changes: 1 addition & 1 deletion SwiftyMenu/Classes/SwiftMenuDisplayable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ public protocol SwiftyMenuDisplayable {
var displayableValue: String { get }

/// The value that will be returned when select menu item
var retrivableValue: Any { get }
var retrievableValue: Any { get }
}
37 changes: 27 additions & 10 deletions SwiftyMenu/Classes/SwiftyMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,25 +210,34 @@ final public class SwiftyMenu: UIView {
private var state: SwiftyMenuState = .hidden
private var width: CGFloat!
private var height: CGFloat!
private var setuped: Bool = false

// MARK: - Init

public override init(frame: CGRect) {
super.init(frame: frame)
setupUI()

selectButton = UIButton(frame: self.frame)
itemsTableView = UITableView()
}

public required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
setupUI()

selectButton = UIButton(frame: self.frame)
itemsTableView = UITableView()
}

// MARK: - LifeCycle

public override func layoutSubviews() {
super.layoutSubviews()

setupArrowImage()
if !setuped {
setupUI()
setupArrowImage()
setuped = true
}
}

// MARK: - Public Funcitons
Expand Down Expand Up @@ -334,7 +343,11 @@ extension SwiftyMenu {

private func setupArrowImage() {
let spacing = self.selectButton.frame.width - 20 // the amount of spacing to appear between image and title
selectButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: CGFloat(spacing), bottom: 0, right: 0)
var imageEdgeInsets = UIEdgeInsets(top: 0, left: CGFloat(spacing), bottom: 0, right: 0)
if UIView.userInterfaceLayoutDirection(for: selectButton.semanticContentAttribute) == .rightToLeft {
imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: CGFloat(spacing))
}
selectButton.imageEdgeInsets = imageEdgeInsets
}

private func setupView() {
Expand All @@ -345,7 +358,6 @@ extension SwiftyMenu {
}

private func setupSelectButton() {
selectButton = UIButton(frame: self.frame)
self.addSubview(selectButton)

selectButton.snp.makeConstraints { maker in
Expand All @@ -359,10 +371,16 @@ extension SwiftyMenu {
selectButton.setTitle(placeHolderText, for: .normal)
selectButton.layoutIfNeeded()
}
selectButton.titleLabel?.lineBreakMode = .byTruncatingTail
selectButton.titleLabel?.font = UIFont.systemFont(ofSize: 12)
selectButton.imageEdgeInsets.left = width - 16
selectButton.titleEdgeInsets.right = 16
if UIView.userInterfaceLayoutDirection(for: selectButton.semanticContentAttribute) == .rightToLeft {
selectButton.imageEdgeInsets.right = width - 16
selectButton.titleEdgeInsets.left = 32
selectButton.titleLabel?.lineBreakMode = .byTruncatingHead
} else {
selectButton.imageEdgeInsets.left = width - 16
selectButton.titleEdgeInsets.right = 32
selectButton.titleLabel?.lineBreakMode = .byTruncatingTail
}
selectButton.backgroundColor = menuHeaderBackgroundColor

let frameworkBundle = Bundle(for: SwiftyMenu.self)
Expand All @@ -383,12 +401,11 @@ extension SwiftyMenu {
}

private func setupDataTableView() {
itemsTableView = UITableView()
self.addSubview(itemsTableView)

itemsTableView.snp.makeConstraints { maker in
maker.leading.trailing.bottom.equalTo(self)
maker.top.equalTo(selectButton.snp_bottom)
maker.top.equalTo(selectButton.snp.bottom)
}

itemsTableView.delegate = self
Expand Down

0 comments on commit 1c5846b

Please sign in to comment.