From c55e9dcd8bf2b0425fecbca4ab86b27243c77adf Mon Sep 17 00:00:00 2001 From: Nora Trapp Date: Tue, 8 Dec 2020 19:26:16 -0800 Subject: [PATCH] Fix measurement in release builds --- SignalMessaging/Views/CVText.swift | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/SignalMessaging/Views/CVText.swift b/SignalMessaging/Views/CVText.swift index fbe38c9cc9..bbd2589dd3 100644 --- a/SignalMessaging/Views/CVText.swift +++ b/SignalMessaging/Views/CVText.swift @@ -370,9 +370,17 @@ public class CVText { textStorage.addLayoutManager(layoutManager) - layoutManager.glyphRange(for: textContainer) let size = layoutManager.usedRect(for: textContainer).size + // For some reason, in production builds, the textStorage + // seems to get optimized out in many circumstances. This + // results in `usedRect` measuring an empty string and a + // size of 0,0. + // TODO: Figure out a better way to fix this. For now, + // by just using the textStorage later it ensures that it + // is properly measured. + _ = textStorage + return size.ceil } @@ -492,9 +500,17 @@ public class CVText { textStorage.addLayoutManager(layoutManager) - layoutManager.glyphRange(for: textContainer) let size = layoutManager.usedRect(for: textContainer).size + // For some reason, in production builds, the textStorage + // seems to get optimized out in many circumstances. This + // results in `usedRect` measuring an empty string and a + // size of 0,0. + // TODO: Figure out a better way to fix this. For now, + // by just using the textStorage later it ensures that it + // is properly measured. + _ = textStorage + return size.ceil }