Skip to content

Commit ade1437

Browse files
kendrickumstattdafohrman
authored andcommitted
[Bottom Sheet] [Catalog] Add new non-expandable demo for debugging.
PiperOrigin-RevId: 679169657
1 parent 1106890 commit ade1437

File tree

6 files changed

+154
-1
lines changed

6 files changed

+154
-1
lines changed

catalog/java/io/material/catalog/bottomsheet/BottomSheetFragment.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ public Fragment createFragment() {
6464
return new BottomSheetScrollableContentDemoFragment();
6565
}
6666
});
67+
additionalDemos.add(
68+
new Demo(R.string.cat_bottomsheet_unscrollable_content_demo_title) {
69+
@Override
70+
public Fragment createFragment() {
71+
return new BottomSheetUnscrollableContentDemoFragment();
72+
}
73+
});
6774
return additionalDemos;
6875
}
6976

catalog/java/io/material/catalog/bottomsheet/BottomSheetScrollableContentDemoFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public View onCreateDemoView(
5050

5151
@LayoutRes
5252
protected int getDemoContent() {
53-
return R.layout.cat_bottomsheet_scrollable_content_fragment;
53+
return R.layout.cat_bottomsheet_additional_demo_fragment;
5454
}
5555

5656
/** A custom bottom sheet dialog fragment. */
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright 2024 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+
17+
package io.material.catalog.bottomsheet;
18+
19+
import io.material.catalog.R;
20+
21+
import android.app.Dialog;
22+
import android.os.Bundle;
23+
import android.view.LayoutInflater;
24+
import android.view.View;
25+
import android.view.ViewGroup;
26+
import androidx.annotation.LayoutRes;
27+
import androidx.annotation.NonNull;
28+
import androidx.annotation.Nullable;
29+
import androidx.core.view.WindowInsetsCompat;
30+
import com.google.android.material.bottomsheet.BottomSheetBehavior;
31+
import com.google.android.material.bottomsheet.BottomSheetDialog;
32+
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
33+
import com.google.android.material.internal.ViewUtils;
34+
import io.material.catalog.feature.DemoFragment;
35+
import io.material.catalog.windowpreferences.WindowPreferencesManager;
36+
37+
/**
38+
* A fragment that displays the a BottomSheet demo with unscrollable content and text input for the
39+
* Catalog app.
40+
*/
41+
public class BottomSheetUnscrollableContentDemoFragment extends DemoFragment {
42+
@NonNull
43+
@Override
44+
public View onCreateDemoView(
45+
@NonNull LayoutInflater layoutInflater,
46+
@Nullable ViewGroup viewGroup,
47+
@Nullable Bundle bundle) {
48+
View view = layoutInflater.inflate(getDemoContent(), viewGroup, false /* attachToRoot */);
49+
View button = view.findViewById(R.id.bottomsheet_button);
50+
button.setOnClickListener(v -> new BottomSheet().show(getParentFragmentManager(), ""));
51+
return view;
52+
}
53+
54+
@LayoutRes
55+
protected int getDemoContent() {
56+
return R.layout.cat_bottomsheet_additional_demo_fragment;
57+
}
58+
59+
/** A custom bottom sheet dialog fragment. */
60+
@SuppressWarnings("RestrictTo")
61+
public static class BottomSheet extends BottomSheetDialogFragment {
62+
@NonNull
63+
@Override
64+
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
65+
// Set up BottomSheetDialog
66+
BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(getContext());
67+
new WindowPreferencesManager(requireContext()).applyEdgeToEdgePreference(bottomSheetDialog.getWindow());
68+
bottomSheetDialog.setContentView(R.layout.cat_bottomsheet_unscrollable_content);
69+
View bottomSheetInternal = bottomSheetDialog.findViewById(R.id.design_bottom_sheet);
70+
BottomSheetBehavior.from(bottomSheetInternal).setPeekHeight(400);
71+
72+
View bottomSheetContent = bottomSheetInternal.findViewById(R.id.bottom_drawer_3);
73+
ViewUtils.doOnApplyWindowInsets(bottomSheetContent, (v, insets, initialPadding) -> {
74+
// Add the inset in the inner NestedScrollView instead to make the edge-to-edge behavior
75+
// consistent - i.e., the extra padding will only show at the bottom of all content, i.e.,
76+
// only when you can no longer scroll down to show more content.
77+
bottomSheetContent.setPaddingRelative(
78+
initialPadding.start,
79+
initialPadding.top,
80+
initialPadding.end,
81+
initialPadding.bottom + insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom);
82+
return insets;
83+
});
84+
return bottomSheetDialog;
85+
}
86+
}
87+
}

catalog/java/io/material/catalog/bottomsheet/res/layout/cat_bottomsheet_scrollable_content_fragment.xml renamed to catalog/java/io/material/catalog/bottomsheet/res/layout/cat_bottomsheet_additional_demo_fragment.xml

File renamed without changes.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2024 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:app="http://schemas.android.com/apk/res-auto"
19+
android:orientation="vertical"
20+
android:layout_width="match_parent"
21+
android:layout_height="match_parent">
22+
23+
<com.google.android.material.bottomsheet.BottomSheetDragHandleView
24+
android:layout_width="match_parent"
25+
android:layout_height="wrap_content"/>
26+
27+
<androidx.core.widget.NestedScrollView
28+
android:layout_width="match_parent"
29+
android:layout_height="wrap_content">
30+
31+
<LinearLayout
32+
android:id="@+id/bottom_drawer_3"
33+
android:layout_width="match_parent"
34+
android:layout_height="wrap_content"
35+
android:orientation="vertical"
36+
android:gravity="center_horizontal"
37+
android:paddingHorizontal="16dp"
38+
android:paddingVertical="8dp">
39+
40+
<TextView
41+
android:layout_width="wrap_content"
42+
android:layout_height="wrap_content"/>
43+
44+
<com.google.android.material.textfield.TextInputLayout
45+
android:layout_width="match_parent"
46+
android:layout_height="wrap_content"
47+
style="?attr/textInputOutlinedStyle">
48+
<com.google.android.material.textfield.TextInputEditText
49+
android:layout_width="match_parent"
50+
android:layout_height="wrap_content"
51+
android:hint="@string/cat_bottomsheet_textfield_label"/>
52+
</com.google.android.material.textfield.TextInputLayout>
53+
54+
</LinearLayout>
55+
</androidx.core.widget.NestedScrollView>
56+
</LinearLayout>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
<string name="cat_bottomsheet_scrollable_content_demo_title">
5656
Vertically scrollable content demo
5757
</string>
58+
<string name="cat_bottomsheet_unscrollable_content_demo_title" translatable="false">
59+
Non-scrollable text input content demo
60+
</string>
5861
<string name="cat_bottomsheet_label_add_people">Add People</string>
5962
<string name="cat_bottomsheet_label_copy_link">Copy link</string>
6063
<string name="cat_bottomsheet_label_open_in">Open In</string>

0 commit comments

Comments
 (0)