Skip to content
TypeScript

fix(mobile): read display scale and width from the view's scene, not UIScreen.main (#12050)

Julius Marminge9962e6986db6
diff --git a/apps/mobile/modules/t3-composer-editor/ios/T3ComposerEditorView.swift b/apps/mobile/modules/t3-composer-editor/ios/T3ComposerEditorView.swift
index 50ac2afbcb4..bff803f69c0 100644
--- a/apps/mobile/modules/t3-composer-editor/ios/T3ComposerEditorView.swift
+++ b/apps/mobile/modules/t3-composer-editor/ios/T3ComposerEditorView.swift
@@ -436,6 +436,7 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
private var iconImages: [String: UIImage] = [:]
private var pendingIconUris = Set<String>()
private var tokensNeedRebuild = false
+ private var chipsNeedMeasuredWidth = false
let onComposerChange = EventDispatcher()
let onComposerSelectionChange = EventDispatcher()
@@ -571,6 +572,10 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
public override func layoutSubviews() {
super.layoutSubviews()
textView.frame = bounds
+ if chipsNeedMeasuredWidth, bounds.width > 0 {
+ chipsNeedMeasuredWidth = false
+ applyControlledDocument(force: true)
+ }
let placeholderX = textView.textContainerInset.left + textView.textContainer.lineFragmentPadding
let placeholderY = textView.textContainerInset.top
let placeholderWidth = max(
@@ -970,7 +975,10 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
// `maximumWidth` does, so the chip always fits the line it sits on.
let availableWidth = textView.textContainer.size.width > 0
? textView.textContainer.size.width - textView.textContainer.lineFragmentPadding * 2
- : UIScreen.main.bounds.width
+ : (textView.window?.bounds.width ?? bounds.width)
+ if availableWidth <= 0 {
+ chipsNeedMeasuredWidth = true
+ }
let maximumLabelWidth = max(chipFontSize * 3, availableWidth - padding * 2 - iconWidth - iconGap)
paragraph.lineBreakMode = .byTruncatingMiddle
attributedLabel.addAttribute(
diff --git a/apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffView.swift b/apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffView.swift
index e2400e0a939..928e3b5669d 100644
--- a/apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffView.swift
+++ b/apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffView.swift
@@ -1923,7 +1923,7 @@ private final class ReviewDiffContentView: UIView, UIGestureRecognizerDelegate {
theme.headerBackground.setFill()
context.fill(cardRect)
- let hairline = 1 / UIScreen.main.scale
+ let hairline = 1 / traitCollection.displayScale
theme.border.setFill()
context.fill(CGRect(x: cardRect.minX, y: cardRect.maxY - hairline, width: cardRect.width, height: hairline))
@@ -1982,7 +1982,7 @@ private final class ReviewDiffContentView: UIView, UIGestureRecognizerDelegate {
theme.background.setFill()
context.fill(rect)
- let hairline = 1 / UIScreen.main.scale
+ let hairline = 1 / traitCollection.displayScale
theme.border.withAlphaComponent(0.65).setFill()
context.fill(CGRect(x: 0, y: rect.maxY - hairline, width: rect.width, height: hairline))
diff --git a/apps/mobile/modules/t3-terminal/ios/T3TerminalView.swift b/apps/mobile/modules/t3-terminal/ios/T3TerminalView.swift
index 69f8a6d4af1..9e382bfcd7e 100644
--- a/apps/mobile/modules/t3-terminal/ios/T3TerminalView.swift
+++ b/apps/mobile/modules/t3-terminal/ios/T3TerminalView.swift
@@ -315,7 +315,8 @@ public final class T3TerminalView: ExpoView, UITextFieldDelegate {
applyTheme()
clipsToBounds = true
- contentScaleFactor = UIScreen.main.scale
+ // The real scale arrives with the window; layoutSubviews corrects it.
+ contentScaleFactor = traitCollection.displayScale
terminalViewport.clipsToBounds = true
terminalViewport.contentScaleFactor = contentScaleFactor
@@ -677,7 +678,9 @@ public final class T3TerminalView: ExpoView, UITextFieldDelegate {
}
private func updateContentScale() {
- let scale = window?.screen.scale ?? UIScreen.main.scale
+ // The trait collection follows the scene the view is in, which matters once
+ // iPhone apps run resizable and on external displays; UIScreen.main does not.
+ let scale = traitCollection.displayScale
if contentScaleFactor != scale {
contentScaleFactor = scale
}