another test
This commit is contained in:
parent
1a4d391a6c
commit
426a459fb1
1 changed files with 27 additions and 7 deletions
|
|
@ -1,19 +1,39 @@
|
||||||
package nexus.federated.nexus
|
package nexus.federated.nexus
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.WindowInsets
|
||||||
|
import android.view.WindowInsetsAnimation
|
||||||
import io.flutter.embedding.android.FlutterActivity
|
import io.flutter.embedding.android.FlutterActivity
|
||||||
|
|
||||||
class MainActivity: FlutterActivity() {
|
class MainActivity: FlutterActivity() {
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) return
|
||||||
|
|
||||||
|
window.decorView.setWindowInsetsAnimationCallback(
|
||||||
|
object : WindowInsetsAnimation.Callback(DISPATCH_MODE_CONTINUE_ON_SUBTREE) {
|
||||||
|
override fun onProgress(
|
||||||
|
insets: WindowInsets,
|
||||||
|
runningAnimations: List<WindowInsetsAnimation>,
|
||||||
|
) = insets
|
||||||
|
|
||||||
|
override fun onEnd(animation: WindowInsetsAnimation) {
|
||||||
|
if ((animation.typeMask and WindowInsets.Type.ime()) != 0) reapplyInsets()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||||
super.onWindowFocusChanged(hasFocus)
|
super.onWindowFocusChanged(hasFocus)
|
||||||
if (!hasFocus) return
|
if (hasFocus && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) reapplyInsets()
|
||||||
|
}
|
||||||
|
|
||||||
// Flutter swallows inset updates while it thinks a keyboard animation is
|
// Posted so it runs after Flutter has applied any insets it deferred.
|
||||||
// running, and only stops when the animation ends. If the app is
|
private fun reapplyInsets() {
|
||||||
// backgrounded mid-animation, it can miss the end and keep the keyboard's
|
|
||||||
// space reserved, so hand the view the real insets directly.
|
|
||||||
val view = findViewById<View>(FLUTTER_VIEW_ID) ?: return
|
val view = findViewById<View>(FLUTTER_VIEW_ID) ?: return
|
||||||
val insets = view.rootWindowInsets ?: return
|
view.post { view.rootWindowInsets?.let(view::onApplyWindowInsets) }
|
||||||
view.onApplyWindowInsets(insets)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue