Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mobile): respect orientation on displaying asset dimensions #13129

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions mobile/lib/entities/asset.entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class Asset {
durationInSeconds = remote.duration.toDuration()?.inSeconds ?? 0,
type = remote.type.toAssetType(),
fileName = remote.originalFileName,
height = remote.exifInfo?.exifImageHeight?.toInt(),
width = remote.exifInfo?.exifImageWidth?.toInt(),
height = isFlipped(remote) ? remote.exifInfo?.exifImageWidth?.toInt() : remote.exifInfo?.exifImageHeight?.toInt(),
width = isFlipped(remote) ? remote.exifInfo?.exifImageHeight?.toInt() : remote.exifInfo?.exifImageWidth?.toInt(),
livePhotoVideoId = remote.livePhotoVideoId,
ownerId = fastHash(remote.ownerId),
exifInfo =
Expand Down Expand Up @@ -507,3 +507,19 @@ extension AssetsHelper on IsarCollection<Asset> {
return where().anyOf(ids, (q, String e) => q.localIdEqualTo(e));
}
}

/// Returns `true` if this [int] is flipped 90° clockwise
bool isRotated90CW(int orientation) {
return [7,8,-90].contains(orientation);
}

/// Returns `true` if this [int] is flipped 270° clockwise
bool isRotated270CW(int orientation) {
return [5,6,90].contains(orientation);
}

/// Returns `true` if this [Asset] is flipped 90° or 270° clockwise
bool isFlipped(AssetResponseDto response) {
final int orientation = response.exifInfo?.orientation?.toInt() ?? 0;
return orientation != 0 && (isRotated90CW(orientation) || isRotated270CW(orientation));
}
Loading