Skip to content
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

[Android SDK] Revisit activities to see if landscape 3 button navigation handled well #13464

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import android.view.animation.Transformation
import android.widget.LinearLayout.LayoutParams
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.Group
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.children
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
Expand Down Expand Up @@ -182,3 +184,19 @@ fun View.scrollStartEvents(): Flow<Unit> {
.filter { it == MotionEvent.ACTION_MOVE }
.map { }
}

fun View.edgeToEdgeHandlingForNavigationBar() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

ViewCompat.setOnApplyWindowInsetsListener(this) { v, insets ->
val systemInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemInsets.left, 0, systemInsets.right, systemInsets.bottom)
insets
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using this extension function on the root views. I wonder if we should return WindowInsetsCompat.CONSUMED so that insets don't keep passing
down to descendant views.

From the docs:
// Return CONSUMED if you don't want the window insets to keep passing
// down to descendant views.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, we can not do that because then the components that automatically support the edge-to-edge won't apply insets, e.g. in HelpActivity:
Screenshot 2025-02-07 at 11 17 23

It's all quite hacky and we should just slowly migrate to Material 3 components and/or compose (also with material 3 components) then it'll be working out of the box

}
}

fun View.edgeToEdgeHandlingForNavigationAndStatusBar() {
ViewCompat.setOnApplyWindowInsetsListener(this) { v, insets ->
val systemInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemInsets.left, systemInsets.top, systemInsets.right, systemInsets.bottom)
insets
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.woocommerce.android.analytics.AnalyticsTracker.Companion.KEY_HELP_CON
import com.woocommerce.android.analytics.AnalyticsTracker.Companion.KEY_SOURCE_FLOW
import com.woocommerce.android.analytics.AnalyticsTracker.Companion.KEY_SOURCE_STEP
import com.woocommerce.android.databinding.ActivityHelpBinding
import com.woocommerce.android.extensions.edgeToEdgeHandlingForNavigationBar
import com.woocommerce.android.extensions.isNotNullOrEmpty
import com.woocommerce.android.extensions.serializable
import com.woocommerce.android.extensions.show
Expand Down Expand Up @@ -68,6 +69,7 @@ class HelpActivity : AppCompatActivity() {

binding = ActivityHelpBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.root.edgeToEdgeHandlingForNavigationBar()

setSupportActionBar(binding.toolbar.toolbar as Toolbar)
supportActionBar?.setHomeButtonEnabled(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.woocommerce.android.R
import com.woocommerce.android.analytics.AnalyticsEvent
import com.woocommerce.android.analytics.AnalyticsTracker
import com.woocommerce.android.databinding.ActivitySupportRequestFormBinding
import com.woocommerce.android.extensions.edgeToEdgeHandlingForNavigationBar
import com.woocommerce.android.extensions.serializable
import com.woocommerce.android.support.SupportHelper
import com.woocommerce.android.support.help.HelpOrigin
Expand Down Expand Up @@ -51,6 +52,7 @@ class SupportRequestFormActivity : AppCompatActivity() {
zendeskSettings.setup(context = this)

ActivitySupportRequestFormBinding.inflate(layoutInflater).apply {
this.root.edgeToEdgeHandlingForNavigationBar()
setContentView(root)
setupActionBar()
observeViewEvents(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,26 @@ package com.woocommerce.android.ui.prefs

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import androidx.fragment.app.FragmentContainerView
import com.automattic.about.model.AboutConfigProvider
import com.woocommerce.android.R
import com.woocommerce.android.extensions.edgeToEdgeHandlingForNavigationAndStatusBar
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class UnifiedAboutScreenActivity : AppCompatActivity(), AboutConfigProvider {
@Inject lateinit var configBuilder: AboutConfigBuilder
@Inject
lateinit var configBuilder: AboutConfigBuilder

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.unified_about_screen_activity)

applyTopInset()
}

private fun applyTopInset() {
val fragmentContainer = findViewById<FragmentContainerView>(
R.id.about_fragment_container
)
ViewCompat.setOnApplyWindowInsetsListener(fragmentContainer) { view, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
view.updatePadding(top = insets.top)
WindowInsetsCompat.CONSUMED
}
fragmentContainer.edgeToEdgeHandlingForNavigationAndStatusBar()
}

override fun getAboutConfig() = configBuilder.createAboutConfig(this)
Expand Down
1 change: 1 addition & 0 deletions WooCommerce/src/main/res/layout/activity_help.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar_layout"
android:background="@color/color_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar_layout"
android:background="@color/color_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">

Expand Down
Loading