Skip to content

Commit f05f8e9

Browse files
refactor: add comments and made minor updates
1 parent 31e8f3a commit f05f8e9

11 files changed

Lines changed: 48 additions & 31 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Emoji picker for iOS like on macOS
77
<img src="https://user-images.githubusercontent.com/50948518/171909950-ebf388f3-83a1-4b63-ad54-f58ba947e3bb.png" width="230">
88
</p>
99

10-
## Navigate
10+
## Navigation
1111

1212
- [Installation](#installation)
1313
- [Swift Package Manager](#swift-package-manager)
@@ -130,10 +130,10 @@ configuration.customHeight = 300
130130
Feedback generator style. To turn off, set `nil` to this parameter. The default value of this property is `.light`.
131131

132132
```swift
133-
configuration.feedBackGeneratorStyle = .soft
133+
configuration.feedbackGeneratorStyle = .soft
134134
```
135135

136-
## To do
136+
## To Do
137137

138138
- [x] The main functionality for choosing emojis
139139
- [x] Dark mode
@@ -143,7 +143,7 @@ configuration.feedBackGeneratorStyle = .soft
143143
- [ ] Seach bar and search results
144144
- [ ] Recently used
145145

146-
## Localizations
146+
## Localization
147147

148148
* English 🇬🇧
149149
* Russian 🇷🇺

Sources/EmojiPicker/Bindings/Observable.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import Foundation
2323

24+
/// A type of object that publishes a message after the object has changed.
2425
final class Observable<T> {
2526
typealias Listener = (T) -> Void
2627

Sources/EmojiPicker/Extensions/Foundation/Array.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121

2222
import Foundation
2323

24+
/**
25+
Emojis are being represented as hex values. This code converts provided emojis (ints) to a one line string.
26+
27+
- Experiment: `[0x1F600, 0x1F601, 0x1F602, 0x1F923, 0x1F603]` -> "😀😁😂🤣😃".
28+
*/
2429
extension Array where Element == Int {
2530
func emoji() -> String {
2631
var emoji = ""

Sources/EmojiPicker/Extensions/Foundation/Bundle.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77

88
import Foundation
99

10+
/// We don't want `Bundle.module` that is being generated automatically for Swift Package to be overriden by our property.
1011
#if !SWIFT_PACKAGE
1112
extension Bundle {
12-
/// Resources bundle.
13-
///
14-
/// - Note: It was named same as for Swift Package to simplify usage.
13+
/**
14+
Resources bundle.
15+
16+
Since CocoaPods resources bundle is something other than SPM's `Bundle.module`, we need to create it.
17+
18+
- Note: It was named same as for Swift Package to simplify usage.
19+
*/
1520
static var module: Bundle {
1621
let path = Bundle(for: UnicodeManager.self).path(forResource: "EmojiPicker", ofType: "bundle") ?? ""
1722
return Bundle(path: path) ?? Bundle.main

Sources/EmojiPicker/Models/Configuration.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import UIKit
2323

24-
/// Configuration for an EmojiPicker.
24+
/// Configuration for an EmojiPicker. Represents list of requirements.
2525
public struct Configuration {
2626
/// A view controller on which EmojiPicker is being presented.
2727
public var delegate: EmojiPickerDelegate
@@ -34,28 +34,29 @@ public struct Configuration {
3434
/// Inset from the sourceView border.
3535
public var horizontalInset: CGFloat
3636
/// Defines whether to dismiss emoji picker or not after choosing.
37-
public var isDismissAfterChoosing: Bool
37+
public var isDismissedAfterChoosing: Bool
3838
/// Custom height for EmojiPicker.
3939
public var customHeight: CGFloat?
4040
/// Feedback generator style. To turn off, set `nil` to this parameter.
41-
public var feedBackGeneratorStyle: UIImpactFeedbackGenerator.FeedbackStyle?
41+
public var feedbackGeneratorStyle: UIImpactFeedbackGenerator.FeedbackStyle?
4242

43+
/// Creates configuration with optional values (memberwise).
4344
public init(delegate: EmojiPickerDelegate,
4445
sender: UIView,
4546
selectedEmojiCategoryTintColor: UIColor? = nil,
4647
arrowDirection: PickerArrowDirectionMode = .up,
4748
horizontalInset: CGFloat = 0,
48-
isDismissAfterChoosing: Bool = true,
49+
isDismissedAfterChoosing: Bool = true,
4950
customHeight: CGFloat? = nil,
50-
feedBackGeneratorStyle: UIImpactFeedbackGenerator.FeedbackStyle = .light
51+
feedbackGeneratorStyle: UIImpactFeedbackGenerator.FeedbackStyle = .light
5152
) {
5253
self.delegate = delegate
5354
self.sender = sender
5455
self.selectedEmojiCategoryTintColor = selectedEmojiCategoryTintColor
5556
self.arrowDirection = arrowDirection
5657
self.horizontalInset = horizontalInset
57-
self.isDismissAfterChoosing = isDismissAfterChoosing
58+
self.isDismissedAfterChoosing = isDismissedAfterChoosing
5859
self.customHeight = customHeight
59-
self.feedBackGeneratorStyle = feedBackGeneratorStyle
60+
self.feedbackGeneratorStyle = feedbackGeneratorStyle
6061
}
6162
}

Sources/EmojiPicker/Services/UnicodeManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
// SOFTWARE.
2121

22-
import UIKit
22+
import UIKit.UIDevice
2323

2424
/// The protocol is necessary to hide unnecessary methods with Unicode categories in UnicodeManager.
2525
protocol UnicodeManagerProtocol {

Sources/EmojiPicker/Views/EmojiPickerView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import UIKit
2525
protocol EmojiPickerViewDelegate: AnyObject {
2626
/// Processes an event by category selection.
2727
///
28-
/// - Parameter index: index of the selected category.
28+
/// - Parameter index: Index of the selected category.
2929
func didChoiceEmojiCategory(at index: Int)
3030
}
3131

Sources/EmojiPicker/Views/EmojiPickerViewController.swift

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public final class EmojiPickerViewController: UIViewController {
7474

7575
- Note: The default value of this property is `true`.
7676
*/
77-
let isDismissAfterChoosing: Bool
77+
let isDismissedAfterChoosing: Bool
7878

7979
/**
8080
Color for the selected emoji category.
@@ -93,20 +93,23 @@ public final class EmojiPickerViewController: UIViewController {
9393

9494
- Note: The default value of this property is `.light`.
9595
*/
96-
var feedBackGeneratorStyle: UIImpactFeedbackGenerator.FeedbackStyle? {
96+
var feedbackGeneratorStyle: UIImpactFeedbackGenerator.FeedbackStyle? {
9797
didSet {
98-
guard let feedBackGeneratorStyle = feedBackGeneratorStyle else {
99-
generator = nil
98+
guard let feedBackGeneratorStyle = feedbackGeneratorStyle else {
99+
feedbackGenerator = nil
100100
return
101101
}
102-
generator = UIImpactFeedbackGenerator(style: feedBackGeneratorStyle)
102+
feedbackGenerator = UIImpactFeedbackGenerator(style: feedBackGeneratorStyle)
103103
}
104104
}
105105

106106
// MARK: - Private Properties
107107

108+
/// View of this controller.
108109
private let emojiPickerView = EmojiPickerView()
109-
private var generator: UIImpactFeedbackGenerator?
110+
/// An obect that creates haptics to simulate physical impacts.
111+
private var feedbackGenerator: UIImpactFeedbackGenerator?
112+
/// View model of this module.
110113
private var viewModel: EmojiPickerViewModelProtocol
111114

112115
// MARK: - Init
@@ -116,8 +119,9 @@ public final class EmojiPickerViewController: UIViewController {
116119
arrowDirection = configuration.arrowDirection
117120
selectedEmojiCategoryTintColor = configuration.selectedEmojiCategoryTintColor
118121
horizontalInset = configuration.horizontalInset
119-
isDismissAfterChoosing = configuration.isDismissAfterChoosing
122+
isDismissedAfterChoosing = configuration.isDismissAfterChoosing
120123
customHeight = configuration.customHeight
124+
feedbackGeneratorStyle = configuration.feedbackGeneratorStyle
121125

122126
let unicodeManager = UnicodeManager()
123127
viewModel = EmojiPickerViewModel(unicodeManager: unicodeManager)
@@ -155,12 +159,14 @@ public final class EmojiPickerViewController: UIViewController {
155159

156160
private func bindViewModel() {
157161
viewModel.selectedEmoji.bind { [unowned self] emoji in
158-
generator?.impactOccurred()
162+
feedbackGenerator?.impactOccurred()
159163
delegate?.didGetEmoji(emoji: emoji)
160-
if isDismissAfterChoosing {
164+
165+
if isDismissedAfterChoosing {
161166
dismiss(animated: true, completion: nil)
162167
}
163168
}
169+
164170
viewModel.selectedEmojiCategoryIndex.bind { [unowned self] categoryIndex in
165171
self.emojiPickerView.updateSelectedCategoryIcon(with: categoryIndex)
166172
}
@@ -288,7 +294,7 @@ extension EmojiPickerViewController: UICollectionViewDelegateFlowLayout {
288294
extension EmojiPickerViewController: EmojiPickerViewDelegate {
289295

290296
func didChoiceEmojiCategory(at index: Int) {
291-
generator?.impactOccurred()
297+
feedbackGenerator?.impactOccurred()
292298
viewModel.selectedEmojiCategoryIndex.value = index
293299
}
294300
}

Tests/ConfigurationTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ConfigurationTests: XCTestCase {
2727
XCTAssertEqual(configuration.horizontalInset, 0)
2828
XCTAssertEqual(configuration.isDismissAfterChoosing, true)
2929
XCTAssertEqual(configuration.customHeight, nil)
30-
XCTAssertEqual(configuration.feedBackGeneratorStyle, .light)
30+
XCTAssertEqual(configuration.feedbackGeneratorStyle, .light)
3131
}
3232

3333
func testFullDataProvided() throws {
@@ -36,7 +36,7 @@ class ConfigurationTests: XCTestCase {
3636
let horizontalInset: CGFloat = 100
3737
let isDismissAfterChoosing = false
3838
let customHeight: CGFloat = 100
39-
let feedBackGeneratorStyle = UIImpactFeedbackGenerator.FeedbackStyle.medium
39+
let feedbackGeneratorStyle = UIImpactFeedbackGenerator.FeedbackStyle.medium
4040

4141
configuration = Configuration(delegate: delegate,
4242
sender: sender,
@@ -45,13 +45,13 @@ class ConfigurationTests: XCTestCase {
4545
horizontalInset: horizontalInset,
4646
isDismissAfterChoosing: isDismissAfterChoosing,
4747
customHeight: customHeight,
48-
feedBackGeneratorStyle: feedBackGeneratorStyle)
48+
feedbackGeneratorStyle: feedbackGeneratorStyle)
4949

5050
XCTAssertEqual(configuration.selectedEmojiCategoryTintColor, selectedEmojiCategoryTintColor)
5151
XCTAssertEqual(configuration.arrowDirection, arrowDirection)
5252
XCTAssertEqual(configuration.horizontalInset, horizontalInset)
5353
XCTAssertEqual(configuration.isDismissAfterChoosing, isDismissAfterChoosing)
5454
XCTAssertEqual(configuration.customHeight, customHeight)
55-
XCTAssertEqual(configuration.feedBackGeneratorStyle, feedBackGeneratorStyle)
55+
XCTAssertEqual(configuration.feedbackGeneratorStyle, feedbackGeneratorStyle)
5656
}
5757
}

0 commit comments

Comments
 (0)