Skip to main content

orientationHelpers

Content

Sets and gets orientation of device. Made possible by react-native-orientation-locker and react-native-device-detection.

getCurrentOrientation

Gets initial orientation of device. For smartphones (with forceOnPhone equals true) it will always return PORTRAIT

Params

NameTypeRequiredDefault valueDescription
forceOnPhoneBooleanFalseUndefinedReturns initial device orientation for smartphones too

Usage example

const [orientation, setOrientation] = useState<OrientationType>(() => getCurrentOrientation());

useOrientationChange((changedOrientation) => {
if (isTablet) {
setOrientation(changedOrientation);
}
});

setDefaultOrientation

Locks orientation on smartphones to PORTRAIT and unlocks it for other devices.

Usage example

export function initializeApp() {
setDefaultOrientation();
}