File tree Expand file tree Collapse file tree
main/java/com/orientationdirector Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -40,7 +40,12 @@ class OrientationDirectorModule internal constructor(context: ReactApplicationCo
4040
4141 @ReactMethod(isBlockingSynchronousMethod = true )
4242 override fun isLocked (): Boolean {
43- return orientationDirectorImpl.isLocked
43+ return orientationDirectorImpl.getIsLocked()
44+ }
45+
46+ @ReactMethod(isBlockingSynchronousMethod = true )
47+ override fun isAutoRotationEnabled (): Boolean {
48+ return orientationDirectorImpl.getIsAutoRotationEnabled()
4449 }
4550
4651 @ReactMethod()
Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ package com.orientationdirector.implementation
33import android.content.pm.ActivityInfo
44import android.os.Handler
55import android.os.Looper
6- import android.util.Log
76import com.facebook.react.bridge.ReactApplicationContext
87
98class OrientationDirectorImpl internal constructor(private val context : ReactApplicationContext ) {
@@ -21,8 +20,7 @@ class OrientationDirectorImpl internal constructor(private val context: ReactApp
2120 private var lastInterfaceOrientation = Orientation .UNKNOWN
2221 private var lastDeviceOrientation = Orientation .UNKNOWN
2322 private var initialized = false
24-
25- var isLocked: Boolean = false
23+ private var isLocked: Boolean = false
2624
2725 init {
2826 mSensorListener.setOnOrientationChangedCallback { orientation ->
@@ -73,6 +71,14 @@ class OrientationDirectorImpl internal constructor(private val context: ReactApp
7371 return lastDeviceOrientation
7472 }
7573
74+ fun getIsLocked (): Boolean {
75+ return isLocked
76+ }
77+
78+ fun getIsAutoRotationEnabled (): Boolean {
79+ return mAutoRotationObserver.getLastAutoRotationStatus()
80+ }
81+
7682 fun lockTo (jsOrientation : Int ) {
7783 val interfaceOrientation = mUtils.getOrientationFromJsOrientation(jsOrientation)
7884 val screenOrientation =
Original file line number Diff line number Diff line change @@ -10,8 +10,8 @@ abstract class OrientationDirectorSpec internal constructor(context: ReactApplic
1010 abstract fun getDeviceOrientation (promise : Promise )
1111 abstract fun lockTo (orientation : Double )
1212 abstract fun unlock ()
13-
1413 abstract fun isLocked (): Boolean
14+ abstract fun isAutoRotationEnabled (): Boolean
1515 abstract fun addListener (eventName : String )
1616 abstract fun removeListeners (count : Double )
1717}
Original file line number Diff line number Diff line change @@ -58,6 +58,16 @@ export default function App() {
5858 } }
5959 />
6060 < View style = { styles . marginBottom } />
61+ < Button
62+ title = { 'Log is Auto Rotation Enabled' }
63+ onPress = { ( ) => {
64+ console . log (
65+ 'isAutoRotationEnabled: ' ,
66+ RNOrientationDirector . isAutoRotationEnabled ( )
67+ ) ;
68+ } }
69+ />
70+ < View style = { styles . marginBottom } />
6171 < Button
6272 title = { 'Lock To Portrait' }
6373 onPress = { ( ) => {
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ export interface Spec extends TurboModule {
77 lockTo ( orientation : number ) : void ;
88 unlock ( ) : void ;
99 isLocked ( ) : boolean ;
10+ isAutoRotationEnabled ( ) : boolean ;
1011
1112 addListener : ( eventType : string ) => void ;
1213 removeListeners : ( count : number ) => void ;
Original file line number Diff line number Diff line change 1+ import { Platform } from 'react-native' ;
12import Module , { EventEmitter } from './module' ;
23import Event from './types/Event.enum' ;
34import type { InterfaceOrientationToLocalizedStringProvider } from './types/InterfaceOrientationToLocalizedStringProvider.type' ;
45import { Orientation } from './types/Orientation.enum' ;
6+ import { AutoRotation } from './types/AutoRotation.enum' ;
57import type { OrientationEvent } from './types/OrientationEvent.interface' ;
68import type { LockableOrientation } from './types/LockableOrientation.type' ;
79import type { LockedEvent } from './types/LockedEvent.interface' ;
@@ -44,6 +46,15 @@ class RNOrientationDirector {
4446 return Module . isLocked ( ) ;
4547 }
4648
49+ static isAutoRotationEnabled ( ) : AutoRotation {
50+ if ( Platform . OS !== 'android' ) {
51+ return AutoRotation . unknown ;
52+ }
53+ return Module . isAutoRotationEnabled ( )
54+ ? AutoRotation . enabled
55+ : AutoRotation . disabled ;
56+ }
57+
4758 static listenForDeviceOrientationChanges (
4859 callback : ( orientation : OrientationEvent ) => void
4960 ) {
Original file line number Diff line number Diff line change 11export { Orientation } from './types/Orientation.enum' ;
2+ export { AutoRotation } from './types/AutoRotation.enum' ;
23
34import useDeviceOrientation from './hooks/useDeviceOrientation.hook' ;
45export { useDeviceOrientation } ;
Original file line number Diff line number Diff line change 1+ export enum AutoRotation {
2+ unknown = 0 ,
3+ enabled = 1 ,
4+ disabled = 2 ,
5+ }
You can’t perform that action at this time.
0 commit comments