Answer the question
In order to leave comments, you need to log in
How to make Screen Orientation?
Good afternoon, how to check the screen orientation?
I use: import { ScreenOrientation } from 'expo';
That is, when the device makes a turn, ScreenOrientation is triggered.
Answer the question
In order to leave comments, you need to log in
Decision:
import { Component } from 'react';
import PropTypes from 'prop-types';
import Expo from 'expo';
import { expo } from '../app.json';
const ORIENTATION_DEFAULT = Expo.ScreenOrientation.Orientation.ALL;
const ORIENTATIONS = {
'portrait': Expo.ScreenOrientation.Orientation.PORTRAIT,
'landscape': Expo.ScreenOrientation.Orientation.LANDSCAPE,
'default': ORIENTATION_DEFAULT,
};
export default class ScreenOrientation extends Component {
allow(orientation) {
const key = orientation === 'default' ? expo.orientation : orientation;
Expo.ScreenOrientation.allow(ORIENTATIONS[key] || ORIENTATION_DEFAULT);
}
componentDidMount() {
this.allow(this.props.allow);
}
componentWillUnmount() {
this.allow('default');
}
render() {
return this.props.children;
}
}
ScreenOrientation.propTypes = {
children: PropTypes.node,
allow: PropTypes.oneOf(Object.keys(ORIENTATIONS)),
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question