mirror of
https://github.com/material-components/material-components-android.git
synced 2026-02-20 08:39:55 +08:00
Bottom sheet demo with nested scrollable content. Hide the demo from the catalog for now, until a nested scrolling bug is fixed.
PiperOrigin-RevId: 255455292
This commit is contained in:
parent
fb47d9d48f
commit
0e4142effc
@ -28,6 +28,8 @@ import io.material.catalog.application.scope.FragmentScope;
|
||||
import io.material.catalog.feature.Demo;
|
||||
import io.material.catalog.feature.DemoLandingFragment;
|
||||
import io.material.catalog.feature.FeatureDemo;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** A landing fragment that links to BottomSheet demos for the Catalog app. */
|
||||
public class BottomSheetFragment extends DemoLandingFragment {
|
||||
@ -52,6 +54,22 @@ public class BottomSheetFragment extends DemoLandingFragment {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Demo> getAdditionalDemos() {
|
||||
List<Demo> additionalDemos = new ArrayList<>();
|
||||
// TODO: Enable below once this bug is fixed.
|
||||
if (false) {
|
||||
additionalDemos.add(
|
||||
new Demo(R.string.cat_bottomsheet_scrollable_content_demo_title) {
|
||||
@Override
|
||||
public Fragment createFragment() {
|
||||
return new BottomSheetScrollableContentDemoFragment();
|
||||
}
|
||||
});
|
||||
}
|
||||
return additionalDemos;
|
||||
}
|
||||
|
||||
/** The Dagger module for {@link BottomSheetMainDemoFragment} dependencies. */
|
||||
@dagger.Module
|
||||
public abstract static class Module {
|
||||
|
||||
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.material.catalog.bottomsheet;
|
||||
|
||||
import io.material.catalog.R;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import io.material.catalog.feature.DemoFragment;
|
||||
|
||||
/**
|
||||
* A fragment that displays the a BottomSheet demo with vertical scrollable content for the Catalog
|
||||
* app.
|
||||
*/
|
||||
public class BottomSheetScrollableContentDemoFragment extends DemoFragment {
|
||||
|
||||
@Override
|
||||
public View onCreateDemoView(
|
||||
LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
|
||||
View view = layoutInflater.inflate(getDemoContent(), viewGroup, false /* attachToRoot */);
|
||||
|
||||
// Set up BottomSheetDialog
|
||||
BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(getContext());
|
||||
bottomSheetDialog.setContentView(R.layout.cat_bottomsheet_scrollable_content);
|
||||
View bottomSheetInternal = bottomSheetDialog.findViewById(R.id.design_bottom_sheet);
|
||||
BottomSheetBehavior.from(bottomSheetInternal).setPeekHeight(400);
|
||||
View button = view.findViewById(R.id.bottomsheet_button);
|
||||
button.setOnClickListener(v -> bottomSheetDialog.show());
|
||||
return view;
|
||||
}
|
||||
|
||||
@LayoutRes
|
||||
protected int getDemoContent() {
|
||||
return R.layout.cat_bottomsheet_scrollable_content_fragment;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
<!--
|
||||
Copyright 2019 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<vector android:height="24dp"
|
||||
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/darker_gray" android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/>
|
||||
</vector>
|
||||
@ -0,0 +1,21 @@
|
||||
<!--
|
||||
Copyright 2019 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<vector android:height="24dp"
|
||||
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/darker_gray" android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
|
||||
</vector>
|
||||
@ -0,0 +1,21 @@
|
||||
<!--
|
||||
Copyright 2019 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<vector android:height="24dp"
|
||||
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/darker_gray" android:pathData="M10,4H4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V8c0,-1.1 -0.9,-2 -2,-2h-8l-2,-2z"/>
|
||||
</vector>
|
||||
@ -0,0 +1,25 @@
|
||||
<!--
|
||||
Copyright 2019 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="@android:color/darker_gray"
|
||||
android:pathData="M3.9,12c0,-1.71 1.39,-3.1 3.1,-3.1h4L11,7L7,7c-2.76,0 -5,2.24 -5,5s2.24,5 5,5h4v-1.9L7,15.1c-1.71,0 -3.1,-1.39 -3.1,-3.1zM8,13h8v-2L8,11v2zM17,7h-4v1.9h4c1.71,0 3.1,1.39 3.1,3.1s-1.39,3.1 -3.1,3.1h-4L13,17h4c2.76,0 5,-2.24 5,-5s-2.24,-5 -5,-5z"/>
|
||||
</vector>
|
||||
@ -0,0 +1,21 @@
|
||||
<!--
|
||||
Copyright 2019 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<vector android:height="24dp"
|
||||
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/darker_gray" android:pathData="M12,2C6.5,2 2,6.5 2,12s4.5,10 10,10 10,-4.5 10,-10S17.5,2 12,2zM17,18L7,18v-2h10v2zM10.3,14L7,10.7l1.4,-1.4 1.9,1.9 5.3,-5.3L17,7.3 10.3,14z"/>
|
||||
</vector>
|
||||
@ -0,0 +1,21 @@
|
||||
<!--
|
||||
Copyright 2019 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<vector android:height="24dp"
|
||||
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/darker_gray" android:pathData="M19,4L5,4c-1.11,0 -2,0.9 -2,2v12c0,1.1 0.89,2 2,2h4v-2L5,18L5,8h14v10h-4v2h4c1.1,0 2,-0.9 2,-2L21,6c0,-1.1 -0.89,-2 -2,-2zM12,10l-4,4h3v6h2v-6h3l-4,-4z"/>
|
||||
</vector>
|
||||
@ -0,0 +1,21 @@
|
||||
<!--
|
||||
Copyright 2019 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<vector android:height="24dp"
|
||||
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/darker_gray" android:pathData="M15,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM6,10L6,7L4,7v3L1,10v2h3v3h2v-3h3v-2L6,10zM15,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/>
|
||||
</vector>
|
||||
@ -0,0 +1,21 @@
|
||||
<!--
|
||||
Copyright 2019 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<vector android:height="24dp"
|
||||
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/darker_gray" android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z"/>
|
||||
</vector>
|
||||
@ -0,0 +1,92 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2019 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<LinearLayout
|
||||
android:id="@+id/bottom_drawer_2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="600dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
style="@style/selectableTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:drawableLeft="@drawable/ic_person_add_24dp"
|
||||
android:drawableStart="@drawable/ic_person_add_24dp"
|
||||
android:text="@string/cat_bottomsheet_label_add_people"/>
|
||||
|
||||
<TextView
|
||||
style="@style/selectableTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:drawableLeft="@drawable/ic_link_24dp"
|
||||
android:drawableStart="@drawable/ic_link_24dp"
|
||||
android:text="@string/cat_bottomsheet_label_copy_link"/>
|
||||
|
||||
<TextView
|
||||
style="@style/selectableTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:drawableLeft="@drawable/ic_open_in_browser_24dp"
|
||||
android:drawableStart="@drawable/ic_open_in_browser_24dp"
|
||||
android:text="@string/cat_bottomsheet_label_open_in"/>
|
||||
|
||||
<TextView
|
||||
style="@style/selectableTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:drawableLeft="@drawable/ic_folder_24dp"
|
||||
android:drawableStart="@drawable/ic_folder_24dp"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@string/cat_bottomsheet_label_move"/>
|
||||
|
||||
<TextView
|
||||
style="@style/selectableTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:drawableLeft="@drawable/ic_offline_pin_24dp"
|
||||
android:drawableStart="@drawable/ic_offline_pin_24dp"
|
||||
android:text="@string/cat_bottomsheet_label_available_offline"/>
|
||||
|
||||
<TextView
|
||||
style="@style/selectableTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:drawableLeft="@drawable/ic_star_24dp"
|
||||
android:drawableStart="@drawable/ic_star_24dp"
|
||||
android:text="@string/cat_bottomsheet_label_star"/>
|
||||
|
||||
<TextView
|
||||
style="@style/selectableTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:drawableLeft="@drawable/ic_edit_24dp"
|
||||
android:drawableStart="@drawable/ic_edit_24dp"
|
||||
android:text="@string/cat_bottomsheet_label_rename"/>
|
||||
|
||||
<TextView
|
||||
style="@style/selectableTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:drawableLeft="@drawable/ic_delete_24dp"
|
||||
android:drawableStart="@drawable/ic_delete_24dp"
|
||||
android:text="@string/cat_bottomsheet_label_remove"/>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2019 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
<Button
|
||||
android:id="@+id/bottomsheet_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:text="@string/cat_bottomsheet_button_text"/>
|
||||
|
||||
</RelativeLayout>
|
||||
@ -47,5 +47,15 @@
|
||||
<string name="cat_bottomsheet_button_label_enabled">Enabled</string>
|
||||
<string name="cat_bottomsheet_button_label_disabled">Disabled</string>
|
||||
<string name="cat_bottomsheet_button_clicked">Button clicked</string>
|
||||
|
||||
<string name="cat_bottomsheet_scrollable_content_demo_title">
|
||||
Vertically scrollable content demo
|
||||
</string>
|
||||
<string name="cat_bottomsheet_label_add_people">Add People</string>
|
||||
<string name="cat_bottomsheet_label_copy_link">Copy link</string>
|
||||
<string name="cat_bottomsheet_label_open_in">Open In</string>
|
||||
<string name="cat_bottomsheet_label_move">Move</string>
|
||||
<string name="cat_bottomsheet_label_available_offline">Available offline</string>
|
||||
<string name="cat_bottomsheet_label_star">Star</string>
|
||||
<string name="cat_bottomsheet_label_remove">Remove</string>
|
||||
<string name="cat_bottomsheet_label_rename">Rename</string>
|
||||
</resources>
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2019 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<resources>
|
||||
<style name="selectableTextView" parent="@android:style/Widget.TextView">
|
||||
<item name="android:textSize">20sp</item>
|
||||
<item name="android:gravity">center_vertical</item>
|
||||
<item name="android:clickable">true</item>
|
||||
<item name="android:paddingLeft">8dp</item>
|
||||
<item name="android:drawablePadding">8dp</item>
|
||||
<item name="android:background">?attr/selectableItemBackground</item>
|
||||
</style>
|
||||
</resources>
|
||||
Loading…
x
Reference in New Issue
Block a user