Skip to content

refactor(screen-orientation): remove unneeded iOS code - #2589

Open
andredestro wants to merge 1 commit into
nextfrom
chore/RMET-5352/screen-orientation-cleanup
Open

refactor(screen-orientation): remove unneeded iOS code#2589
andredestro wants to merge 1 commit into
nextfrom
chore/RMET-5352/screen-orientation-cleanup

Conversation

@andredestro

Copy link
Copy Markdown
Contributor

The plugin's deployment target is iOS 16.0 (Package.swift and the podspec), so the two #available(iOS 16.0, *) checks in ScreenOrientation.swift always pass and their fallback branches were unreachable.

Removed

  • lockLegacy(_:), which set the orientation through KVC on UIDevice (setValue(_:forKey: "orientation")) and called UINavigationController.attemptRotationToDeviceOrientation(), deprecated in iOS 16
  • the attemptRotationToDeviceOrientation() fallback in unlock
  • both #available(iOS 16.0, *) checks

fromOrientationTypeToInt(_:) is kept: it is still used to set supportedOrientations on the bridge view controller.

Deduplicated

The geometry update was identical in lock and unlock, so it moved to a single requestGeometryUpdate(_:completion:) helper.

Fixed along the way

completion(nil) ran unconditionally right after the request was made, so on failure the completion was invoked twice and the call resolved before it rejected. requestGeometryUpdate's error handler only runs when the request is rejected, so its result is now reported once, after the request. The plugin layer was missing a return after call.reject, which had the same effect one level up.

Verification

  • xcodebuild build -scheme CapacitorScreenOrientation -destination generic/platform=iOS: succeeds with no warnings. Before this change it emitted 'attemptRotationToDeviceOrientation()' was deprecated in iOS 16.0.
  • swiftlint lint --strict screen-orientation/ios: 0 violations.

Android is untouched: getLegacyDisplayRotation() looks similar but is still reachable, since minSdkVersion is 26 and the check guards API 30.

RMET-5352

The plugin's deployment target is iOS 16.0, so the `#available(iOS 16.0, *)`
checks always pass and their fallback branches were unreachable:

- `lockLegacy(_:)`, which set the orientation through KVC on `UIDevice`
  and called `attemptRotationToDeviceOrientation()`, deprecated in iOS 16
- the `attemptRotationToDeviceOrientation()` fallback in `unlock`

Removing them clears the only deprecation warning in the iOS build.

The remaining geometry update was duplicated between `lock` and `unlock`,
so it now lives in a single `requestGeometryUpdate(_:completion:)` helper.
That also fixes the completion being called twice: `completion(nil)` ran
unconditionally right after the request was made, so a failure resolved
the call before rejecting it. The error handler only runs when the request
is rejected, so its result is now reported once, after the request.
@github-actions

Copy link
Copy Markdown

Released dev build of screen-orientation with dev version: 9.0.0-dev-2589-20260820T132634.0

@jcesarmobile jcesarmobile changed the title chore(screen-orientation): remove unneeded iOS code refactor(screen-orientation): remove unneeded iOS code Aug 21, 2026
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.

2 participants