forked from yamill/react-native-orientation
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3.1.3 discord 1 #1
Open
mrkcsc
wants to merge
16
commits into
master
Choose a base branch
from
3.1.3-discord-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
58896c8
[Android] Update gradle file to latest config.
mrkcsc e3ff091
Upgrade Android side of library and fix bugs.
mrkcsc cab3152
Re-work flow to not OOM.
mrkcsc 3f42241
Update the updateOrientation flow for state machine.
mrkcsc f8416a6
Defer to root client gradle version.
mrkcsc fe464f0
Reset orientation to unspecified when auto rotation is disabled.
mrkcsc 6f5a1f2
Fix warnings.
mrkcsc a5a315a
switch react native ios mappings (#2)
nealmanaktola bf1a3f7
supporting orientation locking on iOS 16 (#3)
donaldchen e170a02
expose ignoreAutoRotate (#4)
nealmanaktola 6531db3
[android] Send orientation change event on resume (#5)
huderlem 02916e4
[android] emit orientation degrees changes to JS (#6)
donaldchen 22a8900
fix applying orientation lock with system lock on (#7)
donaldchen 1f85c94
[Android] Use RECEIVER_NOT_EXPORTED with OrientationConfigListener
DDRBoxman e463b16
AGP 8 compat - add namespace to build.gradle
yayvery 54970bc
Fix orientation not being processed on Android 14+
tpcstld File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 0 additions & 172 deletions
172
android/src/main/java/com/github/yamill/orientation/OrientationModule.java
This file was deleted.
Oops, something went wrong.
120 changes: 120 additions & 0 deletions
120
android/src/main/java/com/github/yamill/orientation/OrientationModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package com.github.yamill.orientation | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.pm.ActivityInfo | ||
import android.content.res.Configuration | ||
import com.facebook.react.bridge.Callback | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule | ||
import com.facebook.react.bridge.ReactMethod | ||
import com.github.yamill.orientation.listeners.OrientationAutoRotateListener | ||
import com.github.yamill.orientation.listeners.OrientationConfigListener | ||
|
||
|
||
class OrientationModule(reactContext: ReactApplicationContext) : | ||
ReactContextBaseJavaModule(reactContext) { | ||
|
||
private var autoRotateEnabled = false | ||
private var autoRotateIgnored = false | ||
|
||
override fun getName() = "Orientation" | ||
|
||
override fun getConstants(): Map<String, Any?> { | ||
val orientationInt = reactApplicationContext.resources.configuration.orientation | ||
val orientation = getOrientationString(orientationInt) | ||
|
||
return mapOf("initialOrientation" to orientation) | ||
} | ||
|
||
init { | ||
reactContext.addLifecycleEventListener( | ||
OrientationAutoRotateListener(reactContext) { autoRotateEnabled -> | ||
this.autoRotateEnabled = autoRotateEnabled | ||
this.maybeLockToPortrait() | ||
} | ||
) | ||
reactContext.addLifecycleEventListener( | ||
OrientationConfigListener(reactContext) { | ||
currentActivity | ||
} | ||
) | ||
} | ||
|
||
@Suppress("unused") | ||
@ReactMethod | ||
fun getOrientation(callback: Callback) { | ||
val orientationInt = reactApplicationContext.resources.configuration.orientation | ||
val orientation = getOrientationString(orientationInt) | ||
if (orientation === "null") { | ||
callback.invoke(orientationInt, null) | ||
} else { | ||
callback.invoke(null, orientation) | ||
} | ||
} | ||
|
||
@Suppress("unused") | ||
@ReactMethod | ||
fun ignoreAutoRotate(ignoreAutoRotate: Boolean) { | ||
this.autoRotateIgnored = ignoreAutoRotate | ||
this.maybeLockToPortrait() | ||
} | ||
|
||
@SuppressLint("SourceLockedOrientationActivity") | ||
@Suppress("unused") | ||
@ReactMethod | ||
fun lockToPortrait() { | ||
currentActivity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT | ||
} | ||
|
||
@Suppress("unused") | ||
@ReactMethod | ||
fun lockToLandscape() { | ||
if (autoRotateEnabled || autoRotateIgnored) { | ||
currentActivity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE | ||
} | ||
} | ||
|
||
@Suppress("unused") | ||
@ReactMethod | ||
fun lockToLandscapeLeft() { | ||
if (autoRotateEnabled || autoRotateIgnored) { | ||
currentActivity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE | ||
} | ||
} | ||
|
||
@Suppress("unused") | ||
@ReactMethod | ||
fun lockToLandscapeRight() { | ||
if (autoRotateEnabled || autoRotateIgnored) { | ||
currentActivity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE | ||
} | ||
} | ||
|
||
@Suppress("unused") | ||
@ReactMethod | ||
fun unlockAllOrientations() { | ||
if (autoRotateEnabled || autoRotateIgnored) { | ||
currentActivity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR | ||
} | ||
} | ||
|
||
private fun maybeLockToPortrait() { | ||
if (autoRotateEnabled || autoRotateIgnored) { | ||
return | ||
} | ||
|
||
lockToPortrait() | ||
} | ||
|
||
private fun getOrientationString(orientation: Int) = | ||
when (orientation) { | ||
Configuration.ORIENTATION_LANDSCAPE -> | ||
"LANDSCAPE" | ||
Configuration.ORIENTATION_PORTRAIT -> | ||
"PORTRAIT" | ||
Configuration.ORIENTATION_UNDEFINED -> | ||
"UNKNOWN" | ||
else -> | ||
null | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New API surface to disable the default behavior of respecting the auto-rotate setting.