Languages: English | Português (BR) | Español
Complete Guide to Orientation-Aware Dimension Scaling
Author: Jean Bodenberg
Date: February 2025
Version: 2.0.0
🆕 Version 2.0: Base Orientation now works with all 13 scaling strategies, including BALANCED, DEFAULT, LOGARITHMIC, POWER, and others.
- Overview
- The Problem
- The Solution
- How It Works
- API Reference
- Examples by Strategy
- Best Practices
- Platform-Specific Notes
Base Orientation allows you to specify the orientation for which your design was originally created. When the device rotates, AppDimens automatically inverts the LOWEST/HIGHEST screen types to maintain visual proportions.
PORTRAIT Design + LANDSCAPE Current = Auto-invert LOWEST↔HIGHEST
LANDSCAPE Design + PORTRAIT Current = Auto-invert LOWEST↔HIGHEST
AUTO (default) = No inversion
Works with ALL strategies: BALANCED, DEFAULT, PERCENTAGE, LOGARITHMIC, POWER, etc.
Design a card for portrait using LOWEST (width):
// Card designed for portrait (360x800)
val cardWidth = 300.balanced().type(ScreenType.LOWEST).dp
// Portrait (360x800): Uses LOWEST = 360 → Card ~336dp ✅ (93% of width)
// Landscape (800x360): Uses LOWEST = 360 → Card ~336dp ❌ (42% of width - too small!)Problem: Card looks small in landscape.
// Tell AppDimens this design was made for portrait
val cardWidth = 300.balanced().portraitLowest().dp
// Portrait (360x800): Uses LOWEST (width) = 360 → ~336dp ✅
// Landscape (800x360): AUTO-INVERTS to HIGHEST (width) = 800 → ~896dp ✅Benefits:
- ✅ Automatic adaptation
- ✅ Cleaner code
- ✅ Maintains visual proportion
- ✅ Works with all 13 strategies
if (height > width) → Current = PORTRAIT
if (width > height) → Current = LANDSCAPE
| Design | Current | Invert? | LOWEST→ | HIGHEST→ |
|---|---|---|---|---|
| PORTRAIT | PORTRAIT | NO | LOWEST | HIGHEST |
| PORTRAIT | LANDSCAPE | YES | HIGHEST | LOWEST |
| LANDSCAPE | LANDSCAPE | NO | LOWEST | HIGHEST |
| LANDSCAPE | PORTRAIT | YES | HIGHEST | LOWEST |
| AUTO | any | NO | LOWEST | HIGHEST |
PORTRAIT - Design created for portrait
LANDSCAPE - Design created for landscape
AUTO - No specific orientation (default)
Explicit:
.baseOrientation(BaseOrientation.PORTRAIT)
.type(ScreenType.LOWEST)Shorthands:
.portraitLowest()- Portrait design, width → auto-inverts to height in landscape.portraitHighest()- Portrait design, height → auto-inverts to width in landscape.landscapeLowest()- Landscape design, height → auto-inverts to width in portrait.landscapeHighest()- Landscape design, width → auto-inverts to height in portrait
// Android
@Composable
fun ResponsiveCard() {
Card(
modifier = Modifier
.width(300.balanced().portraitLowest().dp) // ⭐ BALANCED + portrait
.padding(16.balanced().dp)
) {
Text("Auto-adapting Card")
}
}// iOS
struct ResponsiveCard: View {
var body: some View {
VStack {
Text("Auto-adapting Card")
}
.padding(AppDimens.shared.balanced(16).toPoints())
.frame(width: AppDimens.shared.balanced(300).portraitLowest().toPoints())
}
}// Flutter
Container(
width: AppDimens.balanced(300).portraitLowest().calculate(context),
padding: EdgeInsets.all(AppDimens.balanced(16).calculate(context)),
child: Text('Auto-adapting Card'),
)// Android - Phone-focused with orientation
Icon(
imageVector = Icons.Default.Favorite,
modifier = Modifier.size(24.defaultDp.portraitLowest())
)// Large container with orientation
Container(
modifier = Modifier.width(400.percentageDp.portraitLowest().dp)
)✅ Do:
- Use
portraitLowest()for portrait-first designs - Use
landscapeHighest()for landscape-first designs - Test in both orientations
- Use with BALANCED for best results
❌ Don't:
- Mix different base orientations randomly
- Use without testing rotation
- Forget AUTO is the default (no inversion)
- Works with Compose and Views
- Automatic configuration change detection
- Cache invalidation on rotation
- Works with SwiftUI and UIKit
- Trait collection observation
- Automatic updates
- Works with MediaQuery
- Rebuild on orientation change
- Context-aware
- Works with Dimensions API
- Event listeners for resize
- Responsive hooks
Document created by: Jean Bodenberg
Last updated: February 2025
Version: 2.0.0
Repository: https://github.com/bodenberg/appdimens