Skip to content

Commit 82092c6

Browse files
authored
fix: Obscured GutenbergKit block toolbar (#22304)
Custom IME handling is necessary to ensure the virtual keyboard does not obscure the block toolbar. The previous `BaseAppCompatActivity` approach worked for some devices, but not all. Namely, it did not work for the Pixel 6 Pro.
1 parent 1bd2a8f commit 82092c6

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

WordPress/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@
307307
<activity
308308
android:name=".ui.posts.GutenbergKitActivity"
309309
android:configChanges="locale|screenLayout|orientation|screenSize|keyboard|keyboardHidden|smallestScreenSize|uiMode"
310-
android:theme="@style/WordPress.NoActionBar.NoEdgeToEdge"
310+
android:theme="@style/WordPress.NoActionBar"
311311
android:windowSoftInputMode="stateHidden|adjustResize"
312312
android:exported="false">
313313
<meta-data

WordPress/src/main/java/org/wordpress/android/ui/main/BaseAppCompatActivity.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import org.wordpress.android.ui.mysite.menu.MenuActivity
2828
import org.wordpress.android.ui.mysite.personalization.PersonalizationActivity
2929
import org.wordpress.android.ui.notifications.NotificationsDetailActivity
3030
import org.wordpress.android.ui.posts.EditPostActivity
31+
import org.wordpress.android.ui.posts.GutenbergKitActivity
3132
import org.wordpress.android.ui.posts.sharemessage.EditJetpackSocialShareMessageActivity
3233
import org.wordpress.android.ui.prefs.experimentalfeatures.ExperimentalFeaturesActivity
3334
import org.wordpress.android.ui.reader.ReaderCommentListActivity
@@ -114,4 +115,8 @@ private val excludedActivities = listOf(
114115
NotificationsDetailActivity::class.java.name,
115116
ReaderCommentListActivity::class.java.name,
116117
ReaderSubsActivity::class.java.name,
118+
119+
// these are excluded because they implement custom IME inset handling for proper
120+
// keyboard management with edge-to-edge support
121+
GutenbergKitActivity::class.java.name,
117122
)

WordPress/src/main/java/org/wordpress/android/ui/posts/GutenbergKitActivity.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import androidx.appcompat.widget.Toolbar
3333
import androidx.core.app.ActivityCompat
3434
import androidx.core.content.ContextCompat
3535
import androidx.core.util.Consumer
36+
import androidx.core.view.ViewCompat
37+
import androidx.core.view.WindowInsetsCompat
3638
import androidx.fragment.app.Fragment
3739
import androidx.fragment.app.FragmentManager
3840
import androidx.fragment.app.FragmentPagerAdapter
@@ -490,6 +492,10 @@ class GutenbergKitActivity : BaseAppCompatActivity(), EditorImageSettingsListene
490492
}
491493

492494
setContentView(R.layout.new_edit_post_activity)
495+
496+
// Handle edge-to-edge with IME insets for keyboard management
497+
setupEdgeToEdgeWithImeInsets()
498+
493499
backPressedCallback = object : OnBackPressedCallback(true) {
494500
override fun handleOnBackPressed() {
495501
if (isModalDialogOpen) {
@@ -615,6 +621,30 @@ class GutenbergKitActivity : BaseAppCompatActivity(), EditorImageSettingsListene
615621
}
616622
}
617623

624+
/**
625+
* Enables edge-to-edge display with proper IME (keyboard) inset handling.
626+
* This ensures the editor toolbar remains visible above the keyboard on all devices.
627+
*/
628+
private fun setupEdgeToEdgeWithImeInsets() {
629+
val rootView = findViewById<View>(R.id.editor_activity)
630+
631+
ViewCompat.setOnApplyWindowInsetsListener(rootView) { view, insets ->
632+
val systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
633+
val imeInsets = insets.getInsets(WindowInsetsCompat.Type.ime())
634+
635+
// Apply system bar insets to keep content within safe areas
636+
view.setPadding(
637+
systemBarsInsets.left,
638+
systemBarsInsets.top,
639+
systemBarsInsets.right,
640+
// Use IME insets for bottom padding when keyboard is visible, otherwise system bars
641+
maxOf(systemBarsInsets.bottom, imeInsets.bottom)
642+
)
643+
644+
WindowInsetsCompat.CONSUMED
645+
}
646+
}
647+
618648
private fun initializeViewModels() {
619649
editPostNavigationViewModel = ViewModelProvider(this, viewModelFactory)[EditPostNavigationViewModel::class.java]
620650
editPostSettingsViewModel = ViewModelProvider(this, viewModelFactory)[EditPostSettingsViewModel::class.java]

0 commit comments

Comments
 (0)