Skip to content

Fix missing InterfaceOrientation rawValue, remove redundant logic - #583

Merged
Elijah Semyonov (elijah-semyonov) merged 4 commits into
jb-mainfrom
elijah.semyonov/orientation-bug-fix
May 31, 2023
Merged

Fix missing InterfaceOrientation rawValue, remove redundant logic#583
Elijah Semyonov (elijah-semyonov) merged 4 commits into
jb-mainfrom
elijah.semyonov/orientation-bug-fix

Conversation

@elijah-semyonov

@elijah-semyonov Elijah Semyonov (elijah-semyonov) commented May 30, 2023

Copy link
Copy Markdown

Proposed Changes

Remove UIDeviceOrientation change notifications listening, since it's orthogonal to UIInterfaceOrientation
Differentiate between new and deprecated API for orientation retrieval based on iOS version.
Update orientation composition local inside viewWillLayout.
Orientation update will call viewWillTransitionToSize followed by viewSafeAreaInsetsDidChange and viewWillLayout. If orientation change happens when app is in background, viewSafeAreaInsetsDidChange and willViewLayout will still be called after it becomes active, so it's the best place for it.

Testing

Test: run regenerate_xcodeproject.sh, launch the app.

Issues Fixed

Fixes: startup crash on xcodegen generated project. Crashes when creating ComposeWindow on iOS in case statusBarOrientation of UIApplication is invalid (usually before UIWindow becomes key and visible). Trying to proactively obtain current interface orientation before view is ready for layout is a bad idea.

@MatkovIvan Ivan Matkov (MatkovIvan) changed the title Apply a fix Fix missing InterfaceOrientation rawValue May 31, 2023
)

/*
* On newest iOS interfaceOrientation will be deduced from [UIWindowScene] of [UIWindow]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newest

Please specify versions. This comment will be there in a few years with new iOS and possible new API

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

/*
* On newest iOS interfaceOrientation will be deduced from [UIWindowScene] of [UIWindow]
* to which our [ComposeWindow] is attached.
* It's never UIInterfaceOrientationUnknown, if accessed after owning [UIWindow] was made key and visible:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's never UIInterfaceOrientationUnknown

Why it's nullable then? Isn't it adding extra boxing?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same rationale.

You can write a code, that will end up with accessing this property and getting null. And we don't need to do anything about it.

@elijah-semyonov
Elijah Semyonov (elijah-semyonov) deleted the elijah.semyonov/orientation-bug-fix branch May 31, 2023 09:34
@elijah-semyonov Elijah Semyonov (elijah-semyonov) changed the title Fix missing InterfaceOrientation rawValue Fix missing InterfaceOrientation rawValue, remove redundant logic May 31, 2023
// This fixes an interop use case when Compose is embedded in SwiftUi.
layer.layer.needRedraw()
}
super.viewWillTransitionToSize(size, withTransitionCoordinator)

@MatkovIvan Ivan Matkov (MatkovIvan) May 31, 2023

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just remove this now? I mean after deleting everything aside super call in the last commit

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually yes. I'll need it in a branch where I want to make rotation animation not so clunky though. Could remove it altogether until then.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Igor Demin (igordmn) pushed a commit that referenced this pull request Jul 10, 2023
Test: ./gradlew test connectedCheck
Bug: 270612487

This is an imported pull request from androidx#583.

Resolves #583
Github-Pr-Head-Sha: bdbe4b4
GitOrigin-RevId: c027806

Change-Id: Id251580331a2ddd3999abed175e954372c2be416
Zahari Zahariev (harryzz) pushed a commit to harryzz/compose-multiplatform-core that referenced this pull request Jul 28, 2026
Zahari Zahariev (harryzz) pushed a commit to harryzz/compose-multiplatform-core that referenced this pull request Jul 28, 2026
Test: ./gradlew test connectedCheck
Bug: 270612487

This is an imported pull request from androidx#583.

Resolves JetBrains#583
Github-Pr-Head-Sha: bdbe4b4
GitOrigin-RevId: c027806

Change-Id: Id251580331a2ddd3999abed175e954372c2be416
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants