Skip to content

Commit 6494a34

Browse files
Merge branch 'develop' into refactor-emoji-data
2 parents e03f946 + b19895c commit 6494a34

6 files changed

Lines changed: 70 additions & 25 deletions

File tree

.github/workflows/swift.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717

1818
steps:
1919
- uses: actions/checkout@v3
20-
- name: Build on iOS 16.0
21-
run: xcodebuild -workspace Example\ App/EmojiPicker.xcworkspace -scheme EmojiPicker -sdk iphonesimulator -destination 'platform=iOS Simulator,OS=16.0,name=iPhone 14'
22-
- name: Test on iOS 16.0
23-
run: xcodebuild -workspace Example\ App/EmojiPicker.xcworkspace -scheme EmojiPicker-Example -sdk iphonesimulator -destination 'platform=iOS Simulator,OS=16.0,name=iPhone 14' test
20+
- name: Build on iOS 16.2
21+
run: xcodebuild -workspace Example\ App/EmojiPicker.xcworkspace -scheme EmojiPicker -sdk iphonesimulator -destination 'platform=iOS Simulator,OS=16.2,name=iPhone 14'
22+
- name: Test on iOS 16.2
23+
run: xcodebuild -workspace Example\ App/EmojiPicker.xcworkspace -scheme EmojiPicker-Example -sdk iphonesimulator -destination 'platform=iOS Simulator,OS=16.2,name=iPhone 14' test

Example App/EmojiPicker.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,12 @@
359359
MODULE_NAME = ExampleApp;
360360
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
361361
PRODUCT_NAME = "$(TARGET_NAME)";
362+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
363+
SUPPORTS_MACCATALYST = NO;
364+
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES;
362365
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
363366
SWIFT_VERSION = 4.0;
367+
TARGETED_DEVICE_FAMILY = "1,2";
364368
};
365369
name = Debug;
366370
};
@@ -374,8 +378,12 @@
374378
MODULE_NAME = ExampleApp;
375379
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
376380
PRODUCT_NAME = "$(TARGET_NAME)";
381+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
382+
SUPPORTS_MACCATALYST = NO;
383+
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES;
377384
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
378385
SWIFT_VERSION = 4.0;
386+
TARGETED_DEVICE_FAMILY = "1,2";
379387
};
380388
name = Release;
381389
};

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,5 @@ To play around with the project, contribute to it, see how it works or adapt it
178178
1. Clone or fork this repository to yourself
179179
2. Open `Example App/EmojiPicker.xcworkspace` file
180180
3. Expand `Pods` target
181-
4. Expand `Development Pods` and `EmojiPicker` directories
182-
Here you can make your changes.
181+
4. Expand `Development Pods` and `EmojiPicker` directories. Here you can make your changes
183182
5. Build & Run project to see an immediate result on an example application. Have fun!

Sources/EmojiPicker/Views/EmojiCategoryView/TouchableEmojiCategoryView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ final class TouchableEmojiCategoryView: UIView {
6868
super.init(frame: .zero)
6969
}
7070

71+
@available(*, unavailable, message: "init(coder:) has not been implemented")
7172
required init?(coder: NSCoder) {
7273
fatalError("init(coder:) has not been implemented")
7374
}

Sources/EmojiPicker/Views/EmojiPickerView.swift

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,15 @@ final class EmojiPickerView: UIView {
4545
collectionView.contentInset = UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 16)
4646
collectionView.backgroundColor = .clear
4747
collectionView.translatesAutoresizingMaskIntoConstraints = false
48-
collectionView.register(EmojiCollectionViewCell.self, forCellWithReuseIdentifier: EmojiCollectionViewCell.identifier)
49-
collectionView.register(EmojiCollectionViewHeader.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: EmojiCollectionViewHeader.identifier)
48+
collectionView.register(
49+
EmojiCollectionViewCell.self,
50+
forCellWithReuseIdentifier: EmojiCollectionViewCell.identifier
51+
)
52+
collectionView.register(
53+
EmojiCollectionViewHeader.self,
54+
forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader,
55+
withReuseIdentifier: EmojiCollectionViewHeader.identifier
56+
)
5057
return collectionView
5158
}()
5259

@@ -68,12 +75,23 @@ final class EmojiPickerView: UIView {
6875
}()
6976

7077
private var categoryViews = [TouchableEmojiCategoryView]()
78+
private var selectedCategoryIndex: Int = .zero
7179

7280
/// Describes height for `categoriesStackView`.
7381
///
74-
/// - Note: The number `0.13` was taken based on the proportion of this element to the width of the EmojiPicker on MacOS.
75-
private var categoriesStackViewHeight: CGFloat {
76-
return bounds.width * 0.13
82+
/// - Note: The number `0.13` was taken based on the proportion of this element to the width of the EmojiPicker on macOS.
83+
private var categoriesStackViewHeight: CGFloat { bounds.width * 0.13 }
84+
private var categoriesStackHeightConstraint: NSLayoutConstraint?
85+
86+
// MARK: - Init
87+
override init(frame: CGRect) {
88+
super.init(frame: .zero)
89+
setupView()
90+
}
91+
92+
@available(*, unavailable, message: "init(coder:) has not been implemented")
93+
required init?(coder: NSCoder) {
94+
fatalError("init(coder:) has not been implemented")
7795
}
7896

7997
// MARK: - Override
@@ -82,27 +100,31 @@ final class EmojiPickerView: UIView {
82100
super.draw(rect)
83101

84102
setupCategoryViews()
85-
setupView()
86103
}
87104

88105
/// Passes the index of the selected category to all categoryViews to update the state.
89106
///
90107
/// - Parameter categoryIndex: Selected category index.
91108
func updateSelectedCategoryIcon(with categoryIndex: Int) {
109+
selectedCategoryIndex = categoryIndex
92110
categoryViews.forEach {
93111
$0.updateCategoryViewState(selectedCategoryIndex: categoryIndex)
94112
}
95113
}
96114

97115
// MARK: - Private Methods
98-
99116
private func setupView() {
100117
backgroundColor = .popoverBackgroundColor
101-
118+
102119
addSubview(collectionView)
103120
addSubview(categoriesStackView)
104121
addSubview(separatorView)
105122

123+
let categoriesStackHeightConstraint = categoriesStackView.heightAnchor.constraint(
124+
equalToConstant: categoriesStackViewHeight
125+
)
126+
self.categoriesStackHeightConstraint = categoriesStackHeightConstraint
127+
106128
NSLayoutConstraint.activate([
107129
collectionView.leadingAnchor.constraint(equalTo: leadingAnchor),
108130
collectionView.trailingAnchor.constraint(equalTo: trailingAnchor),
@@ -112,7 +134,7 @@ final class EmojiPickerView: UIView {
112134
categoriesStackView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 16),
113135
categoriesStackView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -16),
114136
categoriesStackView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -safeAreaInsets.bottom),
115-
categoriesStackView.heightAnchor.constraint(equalToConstant: categoriesStackViewHeight),
137+
categoriesStackHeightConstraint,
116138

117139
separatorView.leadingAnchor.constraint(equalTo: leadingAnchor),
118140
separatorView.trailingAnchor.constraint(equalTo: trailingAnchor),
@@ -122,6 +144,10 @@ final class EmojiPickerView: UIView {
122144
}
123145

124146
private func setupCategoryViews() {
147+
categoriesStackHeightConstraint?.constant = categoriesStackViewHeight
148+
categoryViews = []
149+
categoriesStackView.subviews.forEach { $0.removeFromSuperview() }
150+
125151
var index = 0
126152
for type in CategoryType.allCases {
127153
let categoryView = TouchableEmojiCategoryView(
@@ -132,7 +158,7 @@ final class EmojiPickerView: UIView {
132158
)
133159

134160
/// We need to set _selected_ state for the first category (default at the start).
135-
categoryView.updateCategoryViewState(selectedCategoryIndex: 0)
161+
categoryView.updateCategoryViewState(selectedCategoryIndex: selectedCategoryIndex)
136162
categoryViews.append(categoryView)
137163
categoriesStackView.addArrangedSubview(categoryView)
138164
index += 1

Sources/EmojiPicker/Views/EmojiPickerViewController.swift

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,27 @@ public final class EmojiPickerViewController: UIViewController {
170170

171171
/// Sets up preferred content size.
172172
///
173-
/// - Note: The number `0.16` was taken based on the proportion of height to the width of the EmojiPicker on MacOS.
173+
/// - Note: The number `0.16` was taken based on the proportion of height to the width of the EmojiPicker on macOS.
174174
private func setupPreferredContentSize() {
175-
let sideInset: CGFloat = 20
176-
let screenWidth: CGFloat = UIScreen.main.nativeBounds.width / UIScreen.main.nativeScale
177-
let popoverWidth: CGFloat = screenWidth - (sideInset * 2)
178-
let heightProportionToWidth: CGFloat = 1.16
179-
180-
preferredContentSize = CGSize(width: popoverWidth,
181-
height: customHeight ?? popoverWidth * heightProportionToWidth
182-
)
175+
let size: CGSize = {
176+
switch UIDevice.current.userInterfaceIdiom {
177+
case .phone:
178+
let sideInset: CGFloat = 20
179+
let screenWidth: CGFloat = UIScreen.main.nativeBounds.width / UIScreen.main.nativeScale
180+
let popoverWidth: CGFloat = screenWidth - (sideInset * 2)
181+
// The number 0.16 was taken based on the proportion of height to the width of the EmojiPicker on macOS.
182+
let heightProportionToWidth: CGFloat = 1.16
183+
return CGSize(
184+
width: popoverWidth,
185+
height: popoverWidth * heightProportionToWidth
186+
)
187+
default:
188+
// macOS size
189+
return CGSize(width: 410, height: 460)
190+
}
191+
}()
192+
193+
preferredContentSize = size
183194
}
184195

185196
private func setupArrowDirections() {

0 commit comments

Comments
 (0)