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.swiftindex 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, UITextDroprivate var iconImages: [String: UIImage] = [:]private var pendingIconUris = Set<String>()private var tokensNeedRebuild = false+ private var chipsNeedMeasuredWidth = falselet onComposerChange = EventDispatcher()let onComposerSelectionChange = EventDispatcher()@@ -571,6 +572,10 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDropublic 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.lineFragmentPaddinglet placeholderY = textView.textContainerInset.toplet 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 = .byTruncatingMiddleattributedLabel.addAttribute(diff --git a/apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffView.swift b/apps/mobile/modules/t3-review-diff/ios/T3ReviewDiffView.swiftindex 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.displayScaletheme.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.displayScaletheme.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.swiftindex 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.displayScaleterminalViewport.clipsToBounds = trueterminalViewport.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.displayScaleif contentScaleFactor != scale {contentScaleFactor = scale}