Skip to content

Commit 9962e69

Browse files
fix(mobile): read display scale and width from the view's scene, not UIScreen.main (pingdotgg#12050)
Co-authored-by: Claude Fable 5 <[email protected]>
1 parent ce920f2 commit 9962e69

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

‎apps/mobile/modules/t3-composer-editor/ios/T3ComposerEditorView.swift‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
436436
private var iconImages: [String: UIImage] = [:]
437437
private var pendingIconUris = Set<String>()
438438
private var tokensNeedRebuild = false
439+
private var chipsNeedMeasuredWidth = false
439440

440441
let onComposerChange = EventDispatcher()
441442
let onComposerSelectionChange = EventDispatcher()
@@ -571,6 +572,10 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
571572
public override func layoutSubviews() {
572573
super.layoutSubviews()
573574
textView.frame = bounds
575+
if chipsNeedMeasuredWidth, bounds.width > 0 {
576+
chipsNeedMeasuredWidth = false
577+
applyControlledDocument(force: true)
578+
}
574579
let placeholderX = textView.textContainerInset.left + textView.textContainer.lineFragmentPadding
575580
let placeholderY = textView.textContainerInset.top
576581
let placeholderWidth = max(
@@ -970,7 +975,10 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
970975
// `maximumWidth` does, so the chip always fits the line it sits on.
971976
let availableWidth = textView.textContainer.size.width > 0
972977
? textView.textContainer.size.width - textView.textContainer.lineFragmentPadding * 2
973-
: UIScreen.main.bounds.width
978+
: (textView.window?.bounds.width ?? bounds.width)
979+
if availableWidth <= 0 {
980+
chipsNeedMeasuredWidth = true
981+
}
974982
let maximumLabelWidth = max(chipFontSize * 3, availableWidth - padding * 2 - iconWidth - iconGap)
975983
paragraph.lineBreakMode = .byTruncatingMiddle
976984
attributedLabel.addAttribute(

‎apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffView.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,7 +1923,7 @@ private final class ReviewDiffContentView: UIView, UIGestureRecognizerDelegate {
19231923
theme.headerBackground.setFill()
19241924
context.fill(cardRect)
19251925

1926-
let hairline = 1 / UIScreen.main.scale
1926+
let hairline = 1 / traitCollection.displayScale
19271927
theme.border.setFill()
19281928
context.fill(CGRect(x: cardRect.minX, y: cardRect.maxY - hairline, width: cardRect.width, height: hairline))
19291929

@@ -1982,7 +1982,7 @@ private final class ReviewDiffContentView: UIView, UIGestureRecognizerDelegate {
19821982
theme.background.setFill()
19831983
context.fill(rect)
19841984

1985-
let hairline = 1 / UIScreen.main.scale
1985+
let hairline = 1 / traitCollection.displayScale
19861986
theme.border.withAlphaComponent(0.65).setFill()
19871987
context.fill(CGRect(x: 0, y: rect.maxY - hairline, width: rect.width, height: hairline))
19881988

‎apps/mobile/modules/t3-terminal/ios/T3TerminalView.swift‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ public final class T3TerminalView: ExpoView, UITextFieldDelegate {
315315

316316
applyTheme()
317317
clipsToBounds = true
318-
contentScaleFactor = UIScreen.main.scale
318+
// The real scale arrives with the window; layoutSubviews corrects it.
319+
contentScaleFactor = traitCollection.displayScale
319320

320321
terminalViewport.clipsToBounds = true
321322
terminalViewport.contentScaleFactor = contentScaleFactor
@@ -677,7 +678,9 @@ public final class T3TerminalView: ExpoView, UITextFieldDelegate {
677678
}
678679

679680
private func updateContentScale() {
680-
let scale = window?.screen.scale ?? UIScreen.main.scale
681+
// The trait collection follows the scene the view is in, which matters once
682+
// iPhone apps run resizable and on external displays; UIScreen.main does not.
683+
let scale = traitCollection.displayScale
681684
if contentScaleFactor != scale {
682685
contentScaleFactor = scale
683686
}

0 commit comments

Comments
 (0)