Skip to content

Commit 331f8a0

Browse files
committed
Chore: Improve WindowInsets
Signed-off-by: imknown <imknown@qq.com>
1 parent 9738cf1 commit 331f8a0

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

app/src/main/java/net/imknown/android/forefrontinfo/ui/MainActivity.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,30 @@ class MainActivity : AppCompatActivity() {
6161
// enableEdgeToEdge()
6262
WindowCompat.setDecorFitsSystemWindows(window, false)
6363

64-
ViewCompat.setOnApplyWindowInsetsListener(binding.appBar) { appBar, windowInsets ->
65-
val insets = windowInsets.getInsets(windowInsetsCompatTypes)
64+
// https://developer.android.com/develop/ui/views/layout/edge-to-edge#material-components
65+
// https://developer.android.com/develop/ui/compose/layouts/insets#material3-components
66+
ViewCompat.setOnApplyWindowInsetsListener(binding.appBar) { appBar, windowInsetsCompat ->
67+
val insets = windowInsetsCompat.getInsets(windowInsetsCompatTypes)
6668
appBar.updatePadding(
6769
left = insets.left,
6870
right = insets.right,
6971
top = insets.top
7072
)
7173

72-
windowInsets
74+
windowInsetsCompat
7375
}
7476

75-
ViewCompat.setOnApplyWindowInsetsListener(binding.bottomNavigationView) { bnView, windowInsets ->
76-
val insets = windowInsets.getInsets(windowInsetsCompatTypes)
77+
// https://developer.android.com/develop/ui/views/layout/edge-to-edge#material-components
78+
// https://developer.android.com/develop/ui/compose/layouts/insets#material3-components
79+
ViewCompat.setOnApplyWindowInsetsListener(binding.bottomNavigationView) { bnView, windowInsetsCompat ->
80+
val insets = windowInsetsCompat.getInsets(windowInsetsCompatTypes)
7781
bnView.updatePadding(
7882
left = insets.left,
7983
right = insets.right,
8084
bottom = insets.bottom
8185
)
8286

83-
windowInsets
87+
windowInsetsCompat
8488
}
8589
}
8690

app/src/main/java/net/imknown/android/forefrontinfo/ui/base/list/BaseListFragment.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ abstract class BaseListFragment : BaseFragment<FragmentListBinding>() {
7272
}
7373

7474
private fun initWindowInsets() {
75-
ViewCompat.setOnApplyWindowInsetsListener(binding.recyclerView) { rv, windowInsets ->
76-
val insets = windowInsets.getInsets(windowInsetsCompatTypes)
75+
ViewCompat.setOnApplyWindowInsetsListener(binding.recyclerView) { rv, windowInsetsCompat ->
76+
val insets = windowInsetsCompat.getInsets(windowInsetsCompatTypes)
7777
(activity as? MainActivity)?.binding?.bottomNavigationView?.doOnLayout { bnv ->
7878
rv.updatePadding(
7979
left = insets.left,
@@ -82,7 +82,7 @@ abstract class BaseListFragment : BaseFragment<FragmentListBinding>() {
8282
)
8383
}
8484

85-
windowInsets
85+
windowInsetsCompat
8686
}
8787
}
8888

app/src/main/java/net/imknown/android/forefrontinfo/ui/settings/SettingsFragment.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class SettingsFragment : PreferenceFragmentCompat(), FragmentMixin {
4343
private fun initWindowInsets() {
4444
listView.clipToPadding = false
4545

46-
ViewCompat.setOnApplyWindowInsetsListener(listView) { rv, windowInsets ->
47-
val insets = windowInsets.getInsets(windowInsetsCompatTypes)
46+
ViewCompat.setOnApplyWindowInsetsListener(listView) { rv, windowInsetsCompat ->
47+
val insets = windowInsetsCompat.getInsets(windowInsetsCompatTypes)
4848
(activity as? MainActivity)?.binding?.bottomNavigationView?.doOnLayout { bnv ->
4949
rv.updatePadding(
5050
left = insets.left,
@@ -53,7 +53,7 @@ class SettingsFragment : PreferenceFragmentCompat(), FragmentMixin {
5353
)
5454
}
5555

56-
windowInsets
56+
windowInsetsCompat
5757
}
5858
}
5959

0 commit comments

Comments
 (0)