hmos-multidevice-natural-orientation

Diagnose and implement HarmonyOS screen orientation and rotation adaptation across multi-device form factors.

2|Updated Jun 21, 2026
One-click install
npx skills add https://github.com/IsKenKenYa/skills --skill hmos-multidevice-natural-orientation-iskenkenya
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hmos-multidevice-natural-orientation
Source: https://github.com/IsKenKenYa/skills/tree/main/skills/harmonyos/solutions/HMOS-technologies/multi-device/hmos-multidevice-natural-orientation
Command: npx skills add https://github.com/IsKenKenYa/skills --skill hmos-multidevice-natural-orientation-iskenkenya

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? HarmonyOS apps behave inconsistently across phones, foldables, tablets, and PCs because each device form factor has a different natural orientation and rotation capability. This Skill guides requirement analysis, implementation, bug fixing, and verification for screen orientation and rotation, covering setPreferredOrientation, module.json5 orientation config, foldable G-state, and video landscape switching. ## Core Features & Use Cases - Scenario Routing: Four decision-tree scenes (ORIENT-01 to ORIENT-04) covering rotation detection, multi-device adaptation strategy, video landscape switching, and orientation bug fixing. - Bug Fix Case Library: Nine real-world cases including foldable forced-portrait from deviceType misjudgment, Tabs/Swiper lifecycle traps, split-screen rotation failure, and XComponent camera preview black screens. - Reference Guides: Concept quick-reference for the 18 rotation strategies, multi-device adaptation with breakpoint APIs, sensor-based rotation detection, and video rotation with the adaptive_video library. - Use Case: When a foldable device in expanded landscape mode gets forced to portrait on entering a page, the Skill routes to the bug-fix scene, identifies the deviceInfo.deviceType === 'phone' misjudgment, and provides the display.isFoldable() based fix. ## Quick Start Ask the assistant to diagnose why my HarmonyOS app is forced to portrait on a foldable device in expanded landscape mode and provide a fix.

Frequently Asked Questions about hmos-multidevice-natural-orientation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set screen orientation in HarmonyOS with setPreferredOrientation?

Call setPreferredOrientation on the main window instance obtained via windowStage.getMainWindowSync(), passing a window.Orientation enum such as PORTRAIT or AUTO_ROTATION_RESTRICTED. Always save the previous orientation on page entry and restore it on exit, since the setting is window-level global state.

How to handle foldable screen orientation in HarmonyOS apps?

Do not use deviceInfo.deviceType to detect foldables, because foldables return 'phone' just like bar phones. Use display.isFoldable() and display.getFoldStatus() instead, and skip forced portrait when the device is in expanded or half-folded state.

Why does setPreferredOrientation not work in split-screen mode?

HarmonyOS ignores rotation strategies in split-screen, floating window, and free-window modes by system design; the call fails silently without errors. Adapt layouts responsively using windowSizeChange listeners and breakpoint APIs instead of trying to control orientation.

What is the difference between display rotation and window orientation in HarmonyOS?

Display rotation is the physical screen's clockwise angle (0-3) read from the display module, while window orientation is the rotation strategy developers set via setPreferredOrientation. The mapping between them depends on each device's natural orientation, so they cannot be used interchangeably.

Why does my HarmonyOS app get forced to portrait after increasing display size scaling?

The px2vp conversion depends on DPI, so raising display size scaling lowers computed vp values and can drop the minimum dimension below the 348vp rotation threshold. Use physical pixels or system breakpoint APIs for the threshold check instead, since px values are unaffected by DPI scaling.

How do I implement video landscape fullscreen switching in HarmonyOS?

Set USER_ROTATION_LANDSCAPE when entering fullscreen and restore the saved orientation on exit, pairing every setPreferredOrientation call. For short-video adaptive rotation, the adaptive_video third-party library handles device breakpoints and video aspect ratios automatically.