Skip to content

Instantly share code, notes, and snippets.

@dennda
Created December 18, 2018 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dennda/e6a801599de868ee80bfba92494989e9 to your computer and use it in GitHub Desktop.
Save dennda/e6a801599de868ee80bfba92494989e9 to your computer and use it in GitHub Desktop.
diff --git a/DuolingoMobile/Sources/Library/UI/Views/SpeakableLabel.swift b/DuolingoMobile/Sources/Library/UI/Views/SpeakableLabel.swift
index 0e968a1a4b..90f125c75a 100644
--- a/DuolingoMobile/Sources/Library/UI/Views/SpeakableLabel.swift
+++ b/DuolingoMobile/Sources/Library/UI/Views/SpeakableLabel.swift
@@ -183,7 +183,8 @@ class SpeakableLabel: UIView {
super.init(frame: .zero)
- for subview in [sentenceView, speakerView] as [UIView] {
+// for subview in [sentenceView, speakerView] as [UIView] {
+ for subview in [sentenceView] as [UIView] {
addSubview(subview)
}
@@ -219,6 +220,7 @@ class SpeakableLabel: UIView {
override func layoutSubviews() {
super.layoutSubviews()
if sentenceView.frame.width != sentenceView.preferredMaxLayoutWidth {
+ speakerView.frame = CGRect(origin: .zero, size: speakerSize)
sentenceView.preferredMaxLayoutWidth = sentenceView.frame.width
setNeedsLayout()
}
@@ -251,20 +253,20 @@ class SpeakableLabel: UIView {
make.edges.equalTo(self)
}
- speakerView.snp.remakeConstraints { make in
- let scriptDirection = textLanguage.scriptDirection
- switch scriptDirection {
- case .LTR:
- make.left.equalTo(self)
- case .RTL:
- make.right.equalTo(self)
- }
-
- // The sentence view should be accounting for the size of the speaker, so top aligning
- // the speaker with the sentence should center it vertically with the first line of text.
- make.top.equalTo(sentenceView)
- make.size.equalTo(speakerSize)
- }
+// speakerView.snp.remakeConstraints { make in
+// let scriptDirection = textLanguage.scriptDirection
+// switch scriptDirection {
+// case .LTR:
+// make.left.equalTo(self)
+// case .RTL:
+// make.right.equalTo(self)
+// }
+//
+// // The sentence view should be accounting for the size of the speaker, so top aligning
+// // the speaker with the sentence should center it vertically with the first line of text.
+// make.top.equalTo(sentenceView)
+// make.size.equalTo(speakerSize)
+// }
// super is supposed to be called last.
super.updateConstraints()
diff --git a/DuolingoMobile/Sources/Sessions/Controllers/Challenges/JuicyTranslateChallengeVC.swift b/DuolingoMobile/Sources/Sessions/Controllers/Challenges/JuicyTranslateChallengeVC.swift
index 3d6129fd9d..c7bec99b0a 100644
--- a/DuolingoMobile/Sources/Sessions/Controllers/Challenges/JuicyTranslateChallengeVC.swift
+++ b/DuolingoMobile/Sources/Sessions/Controllers/Challenges/JuicyTranslateChallengeVC.swift
@@ -95,9 +95,13 @@ final class JuicyTranslateChallengeVC: UIViewController, DUOChallengeContentView
wordBankView = DUOWordBankView(frame: CGRect.zero)
prompt = SpeakableLabel(textLanguage: element.sourceLanguage)
- prompt.model = DUOHintableString(tokens: element.tokens)
+// prompt.model = DUOHintableString(tokens: element.tokens)
+
+ prompt.model = DUOHintableString(string: "Este pueblo tiene dos supermercados.", language: "es")
+ prompt.hasSpeaker = true
+
prompt.sentenceAccessibilityLabel = element.sentence
- prompt.hasSpeaker = element.sourceLanguage != element.courseFromLanguage && (element.ttsURL != nil)
+// prompt.hasSpeaker = element.sourceLanguage != element.courseFromLanguage && (element.ttsURL != nil)
super.init(nibName: nil, bundle: nil)
diff --git a/DuolingoMobile/Sources/Sessions/Views/DUOHintableTextView.m b/DuolingoMobile/Sources/Sessions/Views/DUOHintableTextView.m
index a59d1a54cf..ed88cb7a5d 100644
--- a/DuolingoMobile/Sources/Sessions/Views/DUOHintableTextView.m
+++ b/DuolingoMobile/Sources/Sessions/Views/DUOHintableTextView.m
@@ -279,7 +279,11 @@ - (NSIndexSet *)indexesForCharactersOfTokenToHighlight:(NSString *)tokenToHighli
- (void)setWrapView:(UIView *)wrapView
{
+ UIView *oldView = _wrapView;
+ [oldView removeFromSuperview];
+
_wrapView = wrapView;
+ [self addSubview:wrapView];
[self setNeedsLayout];
[self invalidateIntrinsicContentSize];
}
@@ -327,25 +331,26 @@ - (CGSize)sizeThatFits:(CGSize)size
- (CGSize)intrinsicContentSize
{
- CGFloat desiredMaxWidth;
- if (self.preferredMaxLayoutWidth > 0) {
- // In an AL context we need to subtract the wrapView's width here.
- // In theory I'm not sure we should be relying on its frame/bounds here (as opposed to its
- // intrinsicContentSize), but that might not get us much since the owner is also responsible for setting the
- // frame, which might cause the size to be different from the intrinsicContentSize.
- //
- // A better solution might be to indicate a preferred size and layout for the wrap view and have this class
- // be responsible for its layout.
- //
- // Or, better still, we rewrite this class and just use `NSTextContainer.exclusionPaths`, and then query that
- // for the correct size.
- //
- // Alas, we need a quick fix, and this seems like it does the trick for now.
- desiredMaxWidth = self.preferredMaxLayoutWidth - self.wrapView.bounds.size.width - [self wrapViewPadding];
- } else {
- desiredMaxWidth = CGFLOAT_MAX;
- }
-
+// CGFloat desiredMaxWidth;
+// if (self.preferredMaxLayoutWidth > 0) {
+// // In an AL context we need to subtract the wrapView's width here.
+// // In theory I'm not sure we should be relying on its frame/bounds here (as opposed to its
+// // intrinsicContentSize), but that might not get us much since the owner is also responsible for setting the
+// // frame, which might cause the size to be different from the intrinsicContentSize.
+// //
+// // A better solution might be to indicate a preferred size and layout for the wrap view and have this class
+// // be responsible for its layout.
+// //
+// // Or, better still, we rewrite this class and just use `NSTextContainer.exclusionPaths`, and then query that
+// // for the correct size.
+// //
+// // Alas, we need a quick fix, and this seems like it does the trick for now.
+// desiredMaxWidth = self.preferredMaxLayoutWidth - self.wrapView.bounds.size.width - [self wrapViewPadding];
+// } else {
+// desiredMaxWidth = CGFLOAT_MAX;
+// }
+
+ CGFloat desiredMaxWidth = self.preferredMaxLayoutWidth > 0 ? self.preferredMaxLayoutWidth : CGFLOAT_MAX;
return [self sizeThatFits:CGSizeMake(desiredMaxWidth, CGFLOAT_MAX)];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment