From abc51191c823c86b6cdf09317f14746e728b3e9d Mon Sep 17 00:00:00 2001 From: Andrew McKnight Date: Wed, 16 Oct 2024 10:55:31 -0400 Subject: [PATCH] wip on right to left support: megaphone location/direction --- Samples/iOS-Swift/iOS-Swift/AppDelegate.swift | 27 +++++++++++++++++-- Sources/Sentry/NSLocale+Sentry.m | 6 +++++ Sources/Sentry/include/NSLocale+Sentry.h | 1 + Sources/Sentry/include/SentryPrivate.h | 1 + ...eedbackWidgetButtonMegaphoneIconView.swift | 9 ++++++- .../SentryUserFeedbackWidgetButtonView.swift | 2 +- 6 files changed, 42 insertions(+), 4 deletions(-) diff --git a/Samples/iOS-Swift/iOS-Swift/AppDelegate.swift b/Samples/iOS-Swift/iOS-Swift/AppDelegate.swift index 7845dce66bb..916fa22ad80 100644 --- a/Samples/iOS-Swift/iOS-Swift/AppDelegate.swift +++ b/Samples/iOS-Swift/iOS-Swift/AppDelegate.swift @@ -174,7 +174,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate { config.showFormForScreenshots = true config.configureWidget = { widget in if args.contains("--io.sentry.iOS-Swift.auto-inject-user-feedback-widget") { - widget.labelText = "Report Jank" + if Locale.current.languageCode == "ar" { // arabic + widget.labelText = "﷽" + } else if Locale.current.languageCode == "ur" { // urdu + widget.labelText = "نستعلیق" + } else if Locale.current.languageCode == "he" { // hebrew + widget.labelText = "עִבְרִית‎" + } else if Locale.current.languageCode == "hi" { // Hindi + widget.labelText = "नागरि" + } else { + widget.labelText = "Report Jank" + } widget.widgetAccessibilityLabel = "io.sentry.iOS-Swift.button.report-jank" widget.layoutUIOffset = layoutOffset } else { @@ -195,7 +205,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } config.configureTheme = { theme in let fontSize: CGFloat = 40 - theme.font = UIFont(name: "HelveticaNeue", size: fontSize) ?? UIFont.systemFont(ofSize: fontSize) + + let fontFamily: String + if Locale.current.languageCode == "ar" { // arabic; ar_EG + fontFamily = "Damascus" + } else if Locale.current.languageCode == "ur" { // urdu; ur_PK + fontFamily = "NotoNastaliq" + } else if Locale.current.languageCode == "he" { // hebrew; he_IL + fontFamily = "Arial Hebrew" + } else if Locale.current.languageCode == "hi" { // Hindi; hi_IN + fontFamily = "DevanagariSangamMN" + } else { + fontFamily = "ChalkboardSE-Regular" + } + theme.font = UIFont(name: fontFamily, size: fontSize) ?? UIFont.systemFont(ofSize: fontSize) theme.outlineColor = .purple theme.foreground = .purple theme.background = .purple.withAlphaComponent(0.1) diff --git a/Sources/Sentry/NSLocale+Sentry.m b/Sources/Sentry/NSLocale+Sentry.m index 19eaaed98b1..42740905ef1 100644 --- a/Sources/Sentry/NSLocale+Sentry.m +++ b/Sources/Sentry/NSLocale+Sentry.m @@ -14,4 +14,10 @@ + (BOOL)timeIs24HourFormat return is24Hour; } ++ (BOOL)isRightToLeftLanguage +{ + return [NSLocale characterDirectionForLanguage:NSLocale.currentLocale.languageCode] + == NSLocaleLanguageDirectionRightToLeft; +} + @end diff --git a/Sources/Sentry/include/NSLocale+Sentry.h b/Sources/Sentry/include/NSLocale+Sentry.h index 5c8278f8383..7d2098ad763 100644 --- a/Sources/Sentry/include/NSLocale+Sentry.h +++ b/Sources/Sentry/include/NSLocale+Sentry.h @@ -3,5 +3,6 @@ @interface SentryLocale : NSObject + (BOOL)timeIs24HourFormat; ++ (BOOL)isRightToLeftLanguage; @end diff --git a/Sources/Sentry/include/SentryPrivate.h b/Sources/Sentry/include/SentryPrivate.h index 5cbf613c036..28d51908195 100644 --- a/Sources/Sentry/include/SentryPrivate.h +++ b/Sources/Sentry/include/SentryPrivate.h @@ -1,4 +1,5 @@ // Sentry internal headers that are needed for swift code +#import "NSLocale+Sentry.h" #import "SentryDispatchQueueWrapper.h" #import "SentryNSDataUtils.h" #import "SentryRandom.h" diff --git a/Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackWidgetButtonMegaphoneIconView.swift b/Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackWidgetButtonMegaphoneIconView.swift index 5a63732b9bd..29bb4bf9acc 100644 --- a/Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackWidgetButtonMegaphoneIconView.swift +++ b/Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackWidgetButtonMegaphoneIconView.swift @@ -25,9 +25,16 @@ class SentryUserFeedbackWidgetButtonMegaphoneIconView: UIView { layer.addSublayer(svgLayer) translatesAutoresizingMaskIntoConstraints = false + var transform = CATransform3DIdentity if config.scaleFactor != 1 { - layer.transform = CATransform3DMakeScale(config.scaleFactor, config.scaleFactor, 0) + transform = CATransform3DConcat(transform, CATransform3DMakeScale(config.scaleFactor, config.scaleFactor, 0)) } + + if SentryLocale.isRightToLeftLanguage() { + transform = CATransform3DConcat(transform, CATransform3DMakeScale(-1, 1, 1)) + } + + layer.transform = transform } required init?(coder: NSCoder) { diff --git a/Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackWidgetButtonView.swift b/Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackWidgetButtonView.swift index 31d63df5e27..ecbd49c8ab5 100644 --- a/Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackWidgetButtonView.swift +++ b/Sources/Swift/Integrations/UserFeedback/SentryUserFeedbackWidgetButtonView.swift @@ -173,7 +173,7 @@ class SentryUserFeedbackWidgetButtonView: UIView { if hasText { let paddingDifference = (scaledLeftPadding - padding) / 2 let spacingDifference = scaledSpacing - spacing - let increasedIconLeftPadAmountDueToScaling = config.widgetConfig.showIcon ? paddingDifference + iconSizeDifference + spacingDifference : 0 + let increasedIconLeftPadAmountDueToScaling: CGFloat = config.widgetConfig.showIcon ? SentryLocale.isRightToLeftLanguage() ? paddingDifference : paddingDifference + iconSizeDifference + spacingDifference : 0 lozengeLayer.transform = CATransform3DTranslate(lozengeLayer.transform, -increasedIconLeftPadAmountDueToScaling, -padding * config.paddingScaleFactor, 0) } else { lozengeLayer.transform = CATransform3DTranslate(lozengeLayer.transform, -iconSizeDifference, -iconSizeDifference, 0)