Skip to content

Commit

Permalink
Move UI layout direction to user preference parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeehut committed Dec 1, 2024
1 parent 026208e commit df4a802
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ TelemetryDeck will automatically send base parameters, such as:
- TelemetryDeck.Accessibility.isVoiceOverEnabled
- TelemetryDeck.Accessibility.preferredContentSizeCategory
- TelemetryDeck.Accessibility.shouldDifferentiateWithoutColor
- TelemetryDeck.Accessibility.userInterfaceLayoutDirection

- TelemetryDeck.AppInfo.buildNumber
- TelemetryDeck.AppInfo.version
- TelemetryDeck.Device.architecture
Expand All @@ -106,6 +106,7 @@ TelemetryDeck will automatically send base parameters, such as:
- TelemetryDeck.SDK.version
- TelemetryDeck.UserPreference.colorScheme
- TelemetryDeck.UserPreference.language
- TelemetryDeck.UserPreference.layoutDirection
- TelemetryDeck.UserPreference.region

See our [Grand Renaming article](https://telemetrydeck.com/docs/articles/grand-rename/?source=github) for a full list.
Expand Down
16 changes: 14 additions & 2 deletions Sources/TelemetryDeck/Signals/Signal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ public struct DefaultSignalPayload: Encodable {
"TelemetryDeck.SDK.nameAndVersion": "SwiftSDK \(sdkVersion)",
"TelemetryDeck.SDK.version": sdkVersion,

"TelemetryDeck.UserPreference.colorScheme": Self.colorScheme,
"TelemetryDeck.UserPreference.language": Self.preferredLanguage,
"TelemetryDeck.UserPreference.layoutDirection": Self.layoutDirection,
"TelemetryDeck.UserPreference.region": Self.region,
"TelemetryDeck.UserPreference.colorScheme": Self.colorScheme
]

parameters.merge(self.accessibilityParameters, uniquingKeysWith: { $1 })
Expand Down Expand Up @@ -132,7 +133,6 @@ extension DefaultSignalPayload {
}
a11yParams["TelemetryDeck.Accessibility.preferredContentSizeCategory"] = UIApplication.shared.preferredContentSizeCategory.rawValue
.replacingOccurrences(of: "UICTContentSizeCategory", with: "") // replaces output "UICTContentSizeCategoryL" with "L"
a11yParams["TelemetryDeck.Accessibility.userInterfaceLayoutDirection"] = UIApplication.shared.userInterfaceLayoutDirection == .leftToRight ? "leftToRight" : "rightToLeft"
a11yParams["TelemetryDeck.Accessibility.isSwitchControlEnabled"] = "\(UIAccessibility.isSwitchControlRunning)"
#elseif os(macOS)
a11yParams["TelemetryDeck.Accessibility.isVoiceOverEnabled"] = "\(NSWorkspace.shared.isVoiceOverEnabled)"
Expand Down Expand Up @@ -399,6 +399,18 @@ extension DefaultSignalPayload {
#endif
}

/// The user-preferred layout direction (left-to-right or right-to-left) based on the current language/region settings.
@MainActor
static var layoutDirection: String {
#if os(iOS) || os(tvOS) || os(watchOS)
return UIApplication.shared.userInterfaceLayoutDirection == .leftToRight ? "leftToRight" : "rightToLeft"
#elseif os(macOS)
return NSApp.userInterfaceLayoutDirection == .leftToRight ? "leftToRight" : "rightToLeft"
#else
return "N/A"
#endif
}

/// The current devices screen resolution width in points.
@MainActor
static var screenResolutionWidth: String {
Expand Down

0 comments on commit df4a802

Please sign in to comment.