feat: support locking screen orientation, closes #860 (#1034)

This commit is contained in:
Huang Xin 2025-05-05 16:55:50 +08:00 committed by GitHub
parent 6299ea09b7
commit 5e04f6ae03
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
37 changed files with 375 additions and 21 deletions

View file

@ -12,6 +12,7 @@ import android.view.WindowManager
import android.view.WindowInsetsController
import android.graphics.Color
import android.webkit.WebView
import android.content.pm.ActivityInfo
import android.graphics.fonts.SystemFonts
import android.graphics.fonts.Font
import androidx.core.view.WindowCompat
@ -56,6 +57,11 @@ class InterceptKeysRequestArgs {
var backKey: Boolean? = null
}
@InvokeArg
class LockScreenOrientationRequestArgs {
var orientation: String? = null
}
interface KeyDownInterceptor {
fun interceptVolumeKeys(enabled: Boolean)
fun interceptBackKey(enabled: Boolean)
@ -326,4 +332,20 @@ class NativeBridgePlugin(private val activity: Activity): Plugin(activity) {
}
invoke.resolve()
}
@Command
fun lock_screen_orientation(invoke: Invoke) {
val args = invoke.parseArgs(LockScreenOrientationRequestArgs::class.java)
val orientation = args.orientation ?: "auto"
when (orientation) {
"portrait" -> activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
"landscape" -> activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
"auto" -> activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR
else -> {
invoke.reject("Invalid orientation mode")
return
}
}
invoke.resolve()
}
}