Skip to content

Commit 22484fd

Browse files
committed
#214 format information tooltip for dark mode and iPad w/minor corrections
1 parent cdd91e8 commit 22484fd

9 files changed

+39
-64
lines changed

Keyboards/KeyboardsBase/KeyboardViewController.swift

+20-18
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,17 @@ class KeyboardViewController: UIInputViewController {
219219
}
220220

221221

222-
// Logic to create tooltip
223-
func createInformationStateDatasource(text: String, backgroundColor: UIColor) -> ToolTipViewDatasource {
224-
let theme = ToolTipViewTheme(backgroundColor: backgroundColor, textFont: nil, textColor: UIColor.black, textAlignment: .center, cornerRadius: 10, masksToBounds: true)
225-
let content = getENTooltipContent(content: text, fontSize: 10)
222+
// Logic to create notification tooltip.
223+
func createInformationStateDatasource(text: NSMutableAttributedString, backgroundColor: UIColor) -> ToolTipViewDatasource {
224+
let theme = ToolTipViewTheme(backgroundColor: backgroundColor, textFont: nil, textColor: keyCharColor, textAlignment: .center, cornerRadius: 10, masksToBounds: true)
226225

227-
return ToolTipViewDatasource(content: content, theme: theme)
226+
return ToolTipViewDatasource(content: text, theme: theme)
228227
}
229228

230229
func setInformationState() {
231-
let contentData: [String] = InformationToolTipData.getContent()
232-
let backgroundColors: [UIColor] = [#colorLiteral(red: 0.6392156863, green: 0.7764705882, blue: 0.1921568627, alpha: 1), #colorLiteral(red: 0.6274509804, green: 0.7333333333, blue: 0.9098039216, alpha: 1), #colorLiteral(red: 0.9725490196, green: 0.8666666667, blue: 0.3960784314, alpha: 1)]
230+
let contentData: [NSMutableAttributedString] = InformationToolTipData.getContent()
233231
let datasources = contentData.enumerated().compactMap({ index, text in
234-
createInformationStateDatasource(text: text, backgroundColor: backgroundColors[index])
232+
createInformationStateDatasource(text: text, backgroundColor: keyColor)
235233
})
236234
tipView = ToolTipView(datasources: datasources)
237235

@@ -240,11 +238,15 @@ class KeyboardViewController: UIInputViewController {
240238
guard let tipView = tipView else { return }
241239
tipView.translatesAutoresizingMaskIntoConstraints = false
242240
formKeySingle.addSubview(tipView)
243-
tipView.leadingAnchor.constraint(equalTo: formKeySingle.leadingAnchor, constant: 5).isActive = true
244-
tipView.trailingAnchor.constraint(equalTo: formKeySingle.trailingAnchor, constant: -5).isActive = true
245-
tipView.topAnchor.constraint(equalTo: formKeySingle.topAnchor, constant: 5).isActive = true
241+
tipView.leadingAnchor.constraint(
242+
equalTo: formKeySingle.leadingAnchor, constant: DeviceType.isPhone ? 15: 40
243+
).isActive = true
244+
tipView.trailingAnchor.constraint(
245+
equalTo: formKeySingle.trailingAnchor, constant: DeviceType.isPhone ? -15: -40
246+
).isActive = true
247+
tipView.topAnchor.constraint(equalTo: formKeySingle.topAnchor, constant: 8).isActive = true
246248
tipView.bottomAnchor.constraint(equalTo: formKeySingle.bottomAnchor, constant: -5).isActive = true
247-
249+
styleBtn(btn: formKeySingle, title: "", radius: keyCornerRadius)
248250
}
249251

250252
private func bindTooltipview() {
@@ -268,7 +270,8 @@ class KeyboardViewController: UIInputViewController {
268270
weakSelf.styleShiftButtons()
269271
}
270272
}
271-
273+
274+
/// Styles the shift buttons for the displayInformation states.
272275
private func styleShiftButtons() {
273276
styleBtn(btn: shiftFormsDisplayLeft, title: "", radius: keyCornerRadius)
274277
styleIconBtn(btn: shiftFormsDisplayLeft,
@@ -809,7 +812,7 @@ class KeyboardViewController: UIInputViewController {
809812
&& deCaseVariantDeclensionState != .disabled {
810813
switch deCaseVariantDeclensionState {
811814
case .disabled:
812-
break // placeholder
815+
break
813816
case .accusativePersonalSPS, .dativePersonalSPS, .genitivePersonalSPS,
814817
.accusativePossesiveSPS, .dativePossesiveSPS, .genitivePossesiveSPS:
815818
formsDisplayDimensions = .view1x2
@@ -832,7 +835,7 @@ class KeyboardViewController: UIInputViewController {
832835
&& controllerLanguage == "German"
833836
&& [.accusative, .dative, .genitive].contains(deCaseDeclensionState) {
834837
formsDisplayDimensions = .view2x2
835-
}else if
838+
} else if
836839
commandState == .displayInformation {
837840
formsDisplayDimensions = .view1x1
838841
} else {
@@ -851,7 +854,6 @@ class KeyboardViewController: UIInputViewController {
851854
setFormDisplay1x2View()
852855
case .view1x1:
853856
setFormDisplay1x1View()
854-
//break // placeholder
855857
}
856858

857859
// Setup the view shift buttons.
@@ -945,7 +947,7 @@ class KeyboardViewController: UIInputViewController {
945947
deactivateBtn(btn: btn)
946948
}
947949
case .view1x1:
948-
break // placeholder
950+
break
949951
}
950952
}
951953

@@ -1134,7 +1136,7 @@ class KeyboardViewController: UIInputViewController {
11341136
allConjugations = [formLeft, formRight]
11351137
allConjugationBtns = get1x2FormDisplayButtons()
11361138
case .view1x1:
1137-
break // placeholder
1139+
break
11381140
}
11391141

11401142
// Populate conjugation view buttons.

Keyboards/KeyboardsBase/ToolTip/Model/InformationToolTipData.swift

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
//
22
// InformationToolTipData.swift
3-
// Scribe
4-
//
5-
// Created by Gabriel Moraes on 03/12/22.
63
//
74

85
import Foundation
6+
import UIKit
97

108
enum InformationToolTipData {
9+
10+
static let wikiDataExplanation = NSMutableAttributedString(
11+
string: "Wikidata is a collaboratively edited knowledge graph that's maintained by the Wikimedia Foundation. It serves as a source of open data for projects like Wikipedia.",
12+
attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: DeviceType.isPhone ? letterKeyWidth / 2 : letterKeyWidth / 2.75)]
13+
)
1114

12-
static let wikiDataExplanation = "Wikidata is a collaboratively edited knowledge graph that's maintained by the Wikimedia Foundation. It serves as a source of open data for projects like Wikipedia."
13-
14-
static let wikiDataContationOrigin = "Scribe uses Wikidata's language data for many of its core features. We get information like noun genders, verb conjugations and much more!"
15+
static let wikiDataContationOrigin = NSMutableAttributedString(
16+
string: "Scribe uses Wikidata's language data for many of its core features. We get information like noun genders, verb conjugations and much more!",
17+
attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: DeviceType.isPhone ? letterKeyWidth / 2 : letterKeyWidth / 2.75)]
18+
)
1519

16-
static let howToContribute = "You can make an account at wikidata.org to join the community that's supporting Scribe and so many other projects. Help us bring free information to the world!"
20+
static let howToContribute = NSMutableAttributedString(
21+
string: "You can make an account at wikidata.org to join the community that's supporting Scribe and so many other projects. Help us bring free information to the world!",
22+
attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: DeviceType.isPhone ? letterKeyWidth / 2 : letterKeyWidth / 2.75)]
23+
)
1724

18-
static func getContent() -> [String] {
25+
static func getContent() -> [NSMutableAttributedString] {
1926
[
2027
InformationToolTipData.wikiDataExplanation,
2128
InformationToolTipData.wikiDataContationOrigin,

Keyboards/KeyboardsBase/ToolTip/Model/ToolTipViewDatasource.swift

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
//
22
// ToolTipViewDatasource.swift
3-
// Scribe
4-
//
5-
// Created by Gabriel Moraes on 03/12/22.
63
//
74

85
import Foundation

Keyboards/KeyboardsBase/ToolTip/Model/ToolTipViewTheme.swift

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
//
22
// ToolTipViewTheme.swift
3-
// Scribe
4-
//
5-
// Created by Gabriel Moraes on 03/12/22.
63
//
74

85
import UIKit

Keyboards/KeyboardsBase/ToolTip/Protocol/ToolTipViewDatasourceable.swift

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
//
22
// ToolTipViewDatasourceable.swift
3-
// Scribe
4-
//
5-
// Created by Gabriel Moraes on 03/12/22.
63
//
74

85
import Foundation

Keyboards/KeyboardsBase/ToolTip/Protocol/ToolTipViewUpdatable.swift

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
//
22
// ToolTipViewUpdatable.swift
3-
// Scribe
4-
//
5-
// Created by Gabriel Moraes on 03/12/22.
63
//
74

85
import Foundation

Keyboards/KeyboardsBase/ToolTip/Protocol/ViewThemeable.swift

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
//
22
// ViewThemeable.swift
3-
// Scribe
4-
//
5-
// Created by Gabriel Moraes on 03/12/22.
63
//
74

85
import UIKit

Keyboards/KeyboardsBase/ToolTip/ToolTipView.swift

+4-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
//
22
// ToolTipView.swift
3-
// Scribe
4-
//
5-
// Created by Gabriel Moraes on 26/11/22.
63
//
74

85
import UIKit
@@ -45,7 +42,6 @@ final class ToolTipView: UIView, ToolTipViewUpdatable {
4542
}
4643

4744
tempLabel.attributedText = datasource.getCurrentText()
48-
4945
tempLabel.numberOfLines = 0
5046

5147
return tempLabel
@@ -61,6 +57,10 @@ final class ToolTipView: UIView, ToolTipViewUpdatable {
6157
pageControl.currentPage = 0
6258
pageControl.numberOfPages = datasources.count
6359
super.init(frame: CGRect.zero)
60+
61+
let datasource = getCurrentDatasource()
62+
pageControl.pageIndicatorTintColor = datasource.theme.textColor?.withAlphaComponent(0.3)
63+
pageControl.currentPageIndicatorTintColor = datasource.theme.textColor
6464
buildHierarchy()
6565
setupConstraints()
6666
configureViews()
@@ -94,22 +94,12 @@ final class ToolTipView: UIView, ToolTipViewUpdatable {
9494
let tempCurrentIndex = currentIndex + 1
9595
updateText(index: tempCurrentIndex)
9696
pageControl.currentPage += 1
97-
98-
// if pageControl.currentPage == datasources.count - 1 {
99-
// didUpdatePage?(.rightInactive)
100-
// }
101-
10297
}
10398

10499
func updatePrevious() {
105100
let tempCurrentIndex = max(0, currentIndex - 1)
106101
updateText(index: tempCurrentIndex)
107102
pageControl.currentPage -= 1
108-
109-
// if pageControl.currentPage == 0 {
110-
// didUpdatePage?(.leftInactive)
111-
// }
112-
113103
}
114104

115105
func updateText(index: Int) {
@@ -137,8 +127,6 @@ final class ToolTipView: UIView, ToolTipViewUpdatable {
137127
self?.backgroundColor = newDatasource.theme.backgroundColor
138128
}, completion: nil)
139129
}
140-
141-
142130
}
143131

144132
extension ToolTipView {
@@ -165,7 +153,5 @@ extension ToolTipView {
165153
func configureViews() {
166154
let datasource = getCurrentDatasource()
167155
backgroundColor = datasource.theme.backgroundColor
168-
169156
}
170-
171157
}

Scribe/AppTexts/English/ENAppText.swift

-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66

77
import UIKit
88

9-
/// Formats and returns the title of the installation guidelines.
10-
func getENTooltipContent(content: String, fontSize: CGFloat) -> NSMutableAttributedString {
11-
NSMutableAttributedString(string: content, attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: fontSize * 1.5)])
12-
}
13-
149
/// Formats and returns the title of the installation guidelines.
1510
func getENInstallationTitle(fontSize: CGFloat) -> NSMutableAttributedString {
1611
return NSMutableAttributedString(string: """

0 commit comments

Comments
 (0)