Skip to content

Commit ad3cf5a

Browse files
afohrmanimhappi
authored andcommitted
[Adaptive][Side Sheet] Add detached variant of modal side sheet.
PiperOrigin-RevId: 495709828
1 parent 938105a commit ad3cf5a

File tree

5 files changed

+73
-1
lines changed

5 files changed

+73
-1
lines changed

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import androidx.annotation.NonNull;
3333
import androidx.annotation.Nullable;
3434
import androidx.annotation.StringRes;
35+
import androidx.annotation.StyleRes;
3536
import androidx.core.view.ViewCompat;
3637
import com.google.android.material.sidesheet.SideSheetBehavior;
3738
import com.google.android.material.sidesheet.SideSheetCallback;
@@ -107,7 +108,6 @@ public View onCreateDemoView(
107108
R.id.side_sheet_title_text,
108109
R.string.cat_sidesheet_modal_title);
109110

110-
sideSheetDialog.setDismissWithSheetAnimationEnabled(true);
111111
View showModalSideSheetButton = view.findViewById(R.id.show_modal_side_sheet_button);
112112
showModalSideSheetButton.setOnClickListener(v -> sideSheetDialog.show());
113113

@@ -123,6 +123,34 @@ public View onCreateDemoView(
123123
modalSideSheetCloseIconButton.setOnClickListener(v -> sideSheetDialog.hide());
124124
}
125125

126+
// Set up detached modal side sheet.
127+
SideSheetDialog detachedSideSheetDialog =
128+
new SideSheetDialog(requireContext(), getDetachedModalThemeOverlayResId());
129+
130+
setUpModalSheet(
131+
detachedSideSheetDialog,
132+
R.layout.cat_sidesheet_content,
133+
R.id.m3_side_sheet,
134+
R.id.side_sheet_title_text,
135+
R.string.cat_sidesheet_modal_detached_title);
136+
137+
View showDetachedModalSideSheetButton =
138+
view.findViewById(R.id.show_modal_detached_side_sheet_button);
139+
showDetachedModalSideSheetButton.setOnClickListener(v -> detachedSideSheetDialog.show());
140+
141+
detachedSideSheetDialog
142+
.getBehavior()
143+
.addCallback(
144+
createSideSheetCallback(
145+
detachedSideSheetDialog.findViewById(R.id.side_sheet_state_text),
146+
detachedSideSheetDialog.findViewById(R.id.side_sheet_slide_offset_text)));
147+
148+
View detachedModalSideSheetCloseIconButton =
149+
detachedSideSheetDialog.findViewById(R.id.close_icon_button);
150+
if (detachedModalSideSheetCloseIconButton != null) {
151+
detachedModalSideSheetCloseIconButton.setOnClickListener(v -> detachedSideSheetDialog.hide());
152+
}
153+
126154
// Set up coplanar side sheet.
127155
View coplanarSideSheet =
128156
setUpSideSheet(
@@ -216,6 +244,11 @@ int getDemoContent() {
216244
return R.layout.cat_sidesheet_fragment;
217245
}
218246

247+
@StyleRes
248+
private int getDetachedModalThemeOverlayResId() {
249+
return R.style.ThemeOverlay_Catalog_SideSheet_Modal_Detached;
250+
}
251+
219252
@Override
220253
public boolean shouldShowDefaultDemoActionBar() {
221254
return false;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@
7272
android:layout_height="wrap_content"
7373
android:layout_marginTop="16dp"
7474
android:text="@string/cat_sidesheet_modal_button_show_text" />
75+
<Button
76+
android:id="@+id/show_modal_detached_side_sheet_button"
77+
android:layout_width="wrap_content"
78+
android:layout_height="wrap_content"
79+
android:layout_marginTop="16dp"
80+
android:text="@string/cat_sidesheet_modal_detached_button_show_text" />
7581
<Button
7682
android:id="@+id/show_coplanar_side_sheet_button"
7783
android:layout_width="wrap_content"

catalog/java/io/material/catalog/sidesheet/res/values/strings.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@
6868
Show Modal Side Sheet
6969
</string>
7070

71+
<string name="cat_sidesheet_modal_detached_title" description="Title of the detached modal side sheet. [CHAR_LIMIT=NONE]">
72+
Detached Modal Side Sheet
73+
</string>
74+
<string name="cat_sidesheet_modal_detached_button_show_text" description="Label of button which shows the detached modal side sheet. [CHAR_LIMIT=NONE]">
75+
Show Detached Modal Side Sheet
76+
</string>
77+
7178
<string name="cat_sidesheet_coplanar_title" description="Title of the coplanar side sheet. [CHAR_LIMIT=NONE]">
7279
Coplanar Side Sheet
7380
</string>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--
2+
Copyright 2022 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<resources>
17+
<style name="ThemeOverlay.Catalog.SideSheet.Modal.Detached" parent="ThemeOverlay.Material3.SideSheetDialog">
18+
<item name="sideSheetModalStyle">@style/Widget.Material3.SideSheet.Modal.Detached</item>
19+
</style>
20+
</resources>

lib/java/com/google/android/material/sidesheet/res/values/styles.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
<item name="shapeAppearanceOverlay">@style/ShapeAppearanceOverlay.Material3.Corner.Left</item>
4545
</style>
4646

47+
<!-- Style for the M3 Detached Modal Side Sheet. -->
48+
<style name="Widget.Material3.SideSheet.Modal.Detached">
49+
<item name="android:layout_margin">@dimen/m3_side_sheet_margin_detached</item>
50+
<item name="shapeAppearanceOverlay">@null</item>
51+
</style>
52+
4753
<!-- Animation used for the M3 Modal Side Sheet. -->
4854
<style name="Animation.Material3.SideSheetDialog" parent="Animation.AppCompat.Dialog">
4955
<item name="android:windowEnterAnimation">@anim/m3_side_sheet_slide_in</item>

0 commit comments

Comments
 (0)