Skip to content

Commit d754591

Browse files
dsn5ftpaulfthomas
authored andcommitted
[SideSheetDialog] Add support for enabling edge to edge via setFitsSystemWindows()
PiperOrigin-RevId: 767168515
1 parent 1c2beb1 commit d754591

File tree

7 files changed

+350
-274
lines changed

7 files changed

+350
-274
lines changed

catalog/java/io/material/catalog/sidesheet/SideSheetMainDemoFragment.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import static android.view.View.NO_ID;
2222

23+
import android.content.Context;
24+
import android.graphics.Color;
2325
import android.os.Bundle;
2426
import androidx.appcompat.app.AppCompatActivity;
2527
import androidx.appcompat.widget.Toolbar;
@@ -28,6 +30,7 @@
2830
import android.view.LayoutInflater;
2931
import android.view.View;
3032
import android.view.ViewGroup;
33+
import android.view.Window;
3134
import android.widget.Button;
3235
import android.widget.TextView;
3336
import androidx.activity.BackEventCompat;
@@ -41,7 +44,9 @@
4144
import androidx.annotation.StyleRes;
4245
import androidx.coordinatorlayout.widget.CoordinatorLayout.LayoutParams;
4346
import androidx.core.view.ViewCompat;
47+
import androidx.core.view.WindowCompat;
4448
import com.google.android.material.button.MaterialButtonToggleGroup;
49+
import com.google.android.material.resources.MaterialAttributes;
4550
import com.google.android.material.sidesheet.SideSheetBehavior;
4651
import com.google.android.material.sidesheet.SideSheetCallback;
4752
import com.google.android.material.sidesheet.SideSheetDialog;
@@ -288,6 +293,7 @@ private void setUpModalSheet(
288293
closeIconButtonIdRes);
289294
}
290295

296+
@SuppressWarnings("RestrictTo")
291297
private void setUpModalSheet(
292298
@StyleRes int sheetThemeOverlayRes,
293299
@LayoutRes int sheetContentLayoutRes,
@@ -298,19 +304,29 @@ private void setUpModalSheet(
298304
@IdRes int closeIconButtonIdRes) {
299305
showSheetButton.setOnClickListener(
300306
v1 -> {
307+
Context context = requireContext();
301308
SideSheetDialog sheetDialog =
302309
sheetThemeOverlayRes == NO_ID
303-
? new SideSheetDialog(requireContext())
304-
: new SideSheetDialog(requireContext(), sheetThemeOverlayRes);
310+
? new SideSheetDialog(context)
311+
: new SideSheetDialog(context, sheetThemeOverlayRes);
305312

306313
sheetDialog.setContentView(sheetContentLayoutRes);
314+
307315
View modalSheetContent = sheetDialog.findViewById(sheetContentRootIdRes);
308316
if (modalSheetContent != null) {
309317
TextView modalSideSheetTitle = modalSheetContent.findViewById(sheetTitleIdRes);
310318
modalSideSheetTitle.setText(sheetTitleStringRes);
311319
}
312-
new WindowPreferencesManager(requireContext())
313-
.applyEdgeToEdgePreference(sheetDialog.getWindow());
320+
321+
boolean edgeToEdgeEnabled = new WindowPreferencesManager(context).isEdgeToEdgeEnabled();
322+
boolean isLightTheme =
323+
MaterialAttributes.resolveBoolean(
324+
context, androidx.appcompat.R.attr.isLightTheme, true);
325+
Window window = sheetDialog.getWindow();
326+
sheetDialog.setFitsSystemWindows(!edgeToEdgeEnabled);
327+
window.setNavigationBarColor(Color.TRANSPARENT);
328+
WindowCompat.getInsetsController(window, window.getDecorView())
329+
.setAppearanceLightStatusBars(edgeToEdgeEnabled && isLightTheme);
314330

315331
sheetDialog
316332
.getBehavior()

catalog/java/io/material/catalog/sidesheet/res/layout/cat_sidesheet_content.xml

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,63 +13,69 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
-->
16-
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
16+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
1717
xmlns:app="http://schemas.android.com/apk/res-auto"
1818
xmlns:tools="http://schemas.android.com/tools"
1919
android:layout_width="match_parent"
2020
android:layout_height="match_parent"
21-
android:padding="24dp"
22-
android:clickable="true"
23-
android:focusable="true"
24-
android:gravity="center_horizontal"
25-
android:orientation="vertical">
21+
android:fitsSystemWindows="true">
2622

27-
<Button
28-
android:id="@+id/close_icon_button"
29-
style="?attr/materialIconButtonStyle"
30-
android:layout_width="wrap_content"
31-
android:layout_height="wrap_content"
32-
android:contentDescription="@string/cat_sidesheet_close_button_content_desc"
33-
app:icon="@drawable/ic_close_vd_theme_24px"
34-
app:iconTint="?attr/colorOnSurfaceVariant"
35-
app:layout_constraintEnd_toEndOf="parent"
36-
app:layout_constraintBaseline_toBaselineOf="@id/side_sheet_title_text"
37-
tools:ignore="ContentDescription" />
23+
<androidx.constraintlayout.widget.ConstraintLayout
24+
android:layout_width="match_parent"
25+
android:layout_height="match_parent"
26+
android:padding="16dp"
27+
android:clickable="true"
28+
android:focusable="true"
29+
android:gravity="center_horizontal"
30+
android:orientation="vertical">
3831

39-
<TextView
40-
android:id="@+id/side_sheet_title_text"
41-
android:layout_width="0dp"
42-
android:layout_height="wrap_content"
43-
android:paddingBottom="24dp"
44-
android:text="@string/cat_sidesheet_standard_title"
45-
android:textAppearance="?attr/textAppearanceTitleLarge"
46-
app:layout_constraintEnd_toStartOf="@id/close_icon_button"
47-
app:layout_constraintStart_toStartOf="parent"
48-
app:layout_constraintTop_toTopOf="parent" />
32+
<Button
33+
android:id="@+id/close_icon_button"
34+
style="?attr/materialIconButtonStyle"
35+
android:layout_width="wrap_content"
36+
android:layout_height="wrap_content"
37+
android:contentDescription="@string/cat_sidesheet_close_button_content_desc"
38+
app:icon="@drawable/ic_close_vd_theme_24px"
39+
app:iconTint="?attr/colorOnSurfaceVariant"
40+
app:layout_constraintEnd_toEndOf="parent"
41+
app:layout_constraintBaseline_toBaselineOf="@id/side_sheet_title_text"
42+
tools:ignore="ContentDescription" />
4943

50-
<TextView
51-
android:id="@+id/side_sheet_state_text"
52-
android:layout_width="wrap_content"
53-
android:layout_height="wrap_content"
54-
android:layout_gravity="center"
55-
android:paddingBottom="4dp"
56-
android:text="@string/cat_sidesheet_state_settling"
57-
android:textAppearance="?attr/textAppearanceBodyLarge"
58-
android:visibility="gone"
59-
app:layout_constraintEnd_toEndOf="parent"
60-
app:layout_constraintStart_toStartOf="parent"
61-
app:layout_constraintTop_toBottomOf="@id/side_sheet_title_text" />
44+
<TextView
45+
android:id="@+id/side_sheet_title_text"
46+
android:layout_width="0dp"
47+
android:layout_height="wrap_content"
48+
android:paddingBottom="24dp"
49+
android:text="@string/cat_sidesheet_standard_title"
50+
android:textAppearance="?attr/textAppearanceTitleLarge"
51+
app:layout_constraintEnd_toStartOf="@id/close_icon_button"
52+
app:layout_constraintStart_toStartOf="parent"
53+
app:layout_constraintTop_toTopOf="parent" />
6254

63-
<TextView
64-
android:id="@+id/side_sheet_slide_offset_text"
65-
android:layout_width="wrap_content"
66-
android:layout_height="wrap_content"
67-
android:layout_gravity="center"
68-
android:text="@string/cat_sidesheet_slide_offset_text"
69-
android:textAppearance="?attr/textAppearanceBodyLarge"
70-
android:visibility="gone"
71-
app:layout_constraintEnd_toEndOf="parent"
72-
app:layout_constraintStart_toStartOf="parent"
73-
app:layout_constraintTop_toBottomOf="@id/side_sheet_state_text" />
55+
<TextView
56+
android:id="@+id/side_sheet_state_text"
57+
android:layout_width="wrap_content"
58+
android:layout_height="wrap_content"
59+
android:layout_gravity="center"
60+
android:paddingBottom="4dp"
61+
android:text="@string/cat_sidesheet_state_settling"
62+
android:textAppearance="?attr/textAppearanceBodyLarge"
63+
android:visibility="gone"
64+
app:layout_constraintEnd_toEndOf="parent"
65+
app:layout_constraintStart_toStartOf="parent"
66+
app:layout_constraintTop_toBottomOf="@id/side_sheet_title_text" />
7467

75-
</androidx.constraintlayout.widget.ConstraintLayout>
68+
<TextView
69+
android:id="@+id/side_sheet_slide_offset_text"
70+
android:layout_width="wrap_content"
71+
android:layout_height="wrap_content"
72+
android:layout_gravity="center"
73+
android:text="@string/cat_sidesheet_slide_offset_text"
74+
android:textAppearance="?attr/textAppearanceBodyLarge"
75+
android:visibility="gone"
76+
app:layout_constraintEnd_toEndOf="parent"
77+
app:layout_constraintStart_toStartOf="parent"
78+
app:layout_constraintTop_toBottomOf="@id/side_sheet_state_text" />
79+
80+
</androidx.constraintlayout.widget.ConstraintLayout>
81+
</FrameLayout>

catalog/java/io/material/catalog/sidesheet/res/layout/cat_sidesheet_content_coplanar.xml

Lines changed: 62 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,72 +13,78 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
-->
16-
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
16+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
1717
xmlns:app="http://schemas.android.com/apk/res-auto"
1818
xmlns:tools="http://schemas.android.com/tools"
1919
android:layout_width="match_parent"
2020
android:layout_height="match_parent"
21-
android:padding="24dp"
22-
android:gravity="center_horizontal"
23-
android:orientation="vertical">
21+
android:fitsSystemWindows="true">
2422

25-
<Button
26-
android:id="@+id/coplanar_side_sheet_close_icon_button"
27-
style="?attr/materialIconButtonStyle"
28-
android:layout_width="wrap_content"
29-
android:layout_height="wrap_content"
30-
android:contentDescription="@string/cat_sidesheet_close_button_content_desc"
31-
app:icon="@drawable/ic_close_vd_theme_24px"
32-
app:iconTint="?attr/colorOnSurfaceVariant"
33-
app:layout_constraintEnd_toEndOf="parent"
34-
app:layout_constraintBaseline_toBaselineOf="@id/coplanar_side_sheet_title_text"
35-
tools:ignore="ContentDescription" />
23+
<androidx.constraintlayout.widget.ConstraintLayout
24+
android:layout_width="match_parent"
25+
android:layout_height="match_parent"
26+
android:padding="16dp"
27+
android:gravity="center_horizontal"
28+
android:orientation="vertical">
3629

37-
<TextView
38-
android:id="@+id/coplanar_side_sheet_title_text"
39-
android:layout_width="0dp"
40-
android:layout_height="wrap_content"
41-
android:paddingBottom="24dp"
42-
android:text="@string/cat_sidesheet_coplanar_title"
43-
android:textAppearance="?attr/textAppearanceTitleLarge"
44-
app:layout_constraintEnd_toStartOf="@id/coplanar_side_sheet_close_icon_button"
45-
app:layout_constraintStart_toStartOf="parent"
46-
app:layout_constraintTop_toTopOf="parent" />
30+
<Button
31+
android:id="@+id/coplanar_side_sheet_close_icon_button"
32+
style="?attr/materialIconButtonStyle"
33+
android:layout_width="wrap_content"
34+
android:layout_height="wrap_content"
35+
android:contentDescription="@string/cat_sidesheet_close_button_content_desc"
36+
app:icon="@drawable/ic_close_vd_theme_24px"
37+
app:iconTint="?attr/colorOnSurfaceVariant"
38+
app:layout_constraintEnd_toEndOf="parent"
39+
app:layout_constraintBaseline_toBaselineOf="@id/coplanar_side_sheet_title_text"
40+
tools:ignore="ContentDescription" />
4741

48-
<androidx.core.widget.NestedScrollView
49-
android:layout_width="0dp"
50-
android:layout_height="wrap_content"
51-
app:layout_constraintEnd_toEndOf="parent"
52-
app:layout_constraintStart_toStartOf="parent"
53-
app:layout_constraintTop_toBottomOf="@id/coplanar_side_sheet_title_text">
42+
<TextView
43+
android:id="@+id/coplanar_side_sheet_title_text"
44+
android:layout_width="0dp"
45+
android:layout_height="wrap_content"
46+
android:paddingBottom="24dp"
47+
android:text="@string/cat_sidesheet_coplanar_title"
48+
android:textAppearance="?attr/textAppearanceTitleLarge"
49+
app:layout_constraintEnd_toStartOf="@id/coplanar_side_sheet_close_icon_button"
50+
app:layout_constraintStart_toStartOf="parent"
51+
app:layout_constraintTop_toTopOf="parent" />
5452

55-
<LinearLayout
56-
android:layout_width="match_parent"
53+
<androidx.core.widget.NestedScrollView
54+
android:layout_width="0dp"
5755
android:layout_height="wrap_content"
58-
android:orientation="vertical">
56+
app:layout_constraintEnd_toEndOf="parent"
57+
app:layout_constraintStart_toStartOf="parent"
58+
app:layout_constraintTop_toBottomOf="@id/coplanar_side_sheet_title_text">
5959

60-
<TextView
61-
android:id="@+id/coplanar_side_sheet_state_text"
62-
android:layout_width="wrap_content"
60+
<LinearLayout
61+
android:layout_width="match_parent"
6362
android:layout_height="wrap_content"
64-
android:layout_gravity="center"
65-
android:paddingBottom="4dp"
66-
android:text="@string/cat_sidesheet_state_settling"
67-
android:textAppearance="?attr/textAppearanceBodyLarge" />
63+
android:orientation="vertical">
6864

69-
<TextView
70-
android:id="@+id/coplanar_side_sheet_slide_offset_text"
71-
android:layout_width="wrap_content"
72-
android:layout_height="wrap_content"
73-
android:layout_gravity="center"
74-
android:text="@string/cat_sidesheet_slide_offset_text"
75-
android:textAppearance="?attr/textAppearanceBodyLarge" />
65+
<TextView
66+
android:id="@+id/coplanar_side_sheet_state_text"
67+
android:layout_width="wrap_content"
68+
android:layout_height="wrap_content"
69+
android:layout_gravity="center"
70+
android:paddingBottom="4dp"
71+
android:text="@string/cat_sidesheet_state_settling"
72+
android:textAppearance="?attr/textAppearanceBodyLarge" />
7673

77-
<TextView
78-
android:layout_width="wrap_content"
79-
android:layout_height="wrap_content"
80-
android:paddingTop="24dp"
81-
android:text="@string/cat_sidesheet_filler_text" />
82-
</LinearLayout>
83-
</androidx.core.widget.NestedScrollView>
84-
</androidx.constraintlayout.widget.ConstraintLayout>
74+
<TextView
75+
android:id="@+id/coplanar_side_sheet_slide_offset_text"
76+
android:layout_width="wrap_content"
77+
android:layout_height="wrap_content"
78+
android:layout_gravity="center"
79+
android:text="@string/cat_sidesheet_slide_offset_text"
80+
android:textAppearance="?attr/textAppearanceBodyLarge" />
81+
82+
<TextView
83+
android:layout_width="wrap_content"
84+
android:layout_height="wrap_content"
85+
android:paddingTop="24dp"
86+
android:text="@string/cat_sidesheet_filler_text" />
87+
</LinearLayout>
88+
</androidx.core.widget.NestedScrollView>
89+
</androidx.constraintlayout.widget.ConstraintLayout>
90+
</FrameLayout>

0 commit comments

Comments
 (0)