159 Commits

Author SHA1 Message Date
pekingme
921868d31b [BottomSheet] Migrated shape appearance to new shape system.
PiperOrigin-RevId: 443484334
2022-04-25 09:27:33 -04:00
conradchen
431e291b01 [Translation] Update string translations
PiperOrigin-RevId: 443191056
2022-04-20 17:19:02 -04:00
pubiqq
3ca41be8f0 [General] Fix typos
Resolves https://github.com/material-components/material-components-android/pull/2654

GIT_ORIGIN_REV_ID=b8f6728979875629f2c813ef90d2f671cf56b4eb
PiperOrigin-RevId: 442852630
2022-04-19 14:48:55 -04:00
conradchen
e644a72aa7 Automated g4 rollback of changelist 435127325
PiperOrigin-RevId: 435152125
2022-03-17 11:40:14 -04:00
conradchen
493243ea1e [BottomSheet] Fix bottom sheets in EXPANDED state when the expanded height is the same as the collapsed height
Resolves https://github.com/material-components/material-components-android/issues/2335

PiperOrigin-RevId: 435127325
2022-03-17 11:39:42 -04:00
conradchen
04c483cf34 [CleanUp][BottomSheet] Simplify state transition logic
Reduces and restructures the calling chain when a state is set to improve readability and robustness.

This CL also introduces the following fixes:

1. Limit the possible input values of setState() and throws IllegalArgumentException if invalid values are provided.
2. Block the state to be set as HIDDEN when hideable is false.
3. Fix the bug that SettleRunnable could be posted multiple times due to isPosted flag being incorrectly set to false when the settling is still going on.
4. Fix the bug that dragging the bottom sheet when settling would result the bottom sheet in an incorrect state (the target state of settling instead of DRAGGING).

PiperOrigin-RevId: 432963533
2022-03-09 21:08:53 +00:00
conradchen
43114c4f7c [BottomSheet] Fix activity leak when setting states on destroying activities
The activity leak can happen in a corner case: setting bottom sheet state when the bottom sheet is dismissed and the host activity is closed. In this situation SettleRunnable will be posted to ViewRootImpl since the bottom sheet is not attached, which leaves references of the dismissed bottom sheet (and thus the destroyed activity) in ViewRootImpl and causes activity leak.

Fixes this by using weak reference in SettleRunnable instead of the strong reference, which is the standard practice of the BottomSheetBehavior class.

Resolves https://github.com/material-components/material-components-android/issues/1417

PiperOrigin-RevId: 430709002
2022-02-25 03:53:30 -08:00
conradchen
19af0ac9d9 [BottomSheet] Update edge-to-edge paddings when bottom sheet is laid out
Since adding bottom sheet behavior callbacks won't trigger any callbacks to be called, the bottom sheet paddings won't be updated right away. This causes the issue that top paddings are not correctly applied when the bottom sheet is initially expanded. Besides that, due to some unknown reason, bottom sheet's getTop() method will only return a non-zero value that is the offset to the container top when calling from bottom sheet behavior callbacks. It seems related to how ViewCompat.offsetTopAndBottom() is working. Not 100% sure.

Therefore this CL add a internal callback to BottomSheetCallback class so when bottom sheet is being laid out (and getting offset), we can update paddings right away.

Resolves https://github.com/material-components/material-components-android/issues/2165

PiperOrigin-RevId: 429071367
2022-02-18 15:41:23 +00:00
pekingme
1304522beb [BottomSheet] Fixed IME bottom padding is ignored in edge-to-edge case. Reverted to use deprecated getSystemWindowInsetBottom() for bottom inset to align with behaviors in 1.5.0.
Resolves: https://github.com/material-components/material-components-android/issues/2543
PiperOrigin-RevId: 428856163
2022-02-15 21:28:33 +00:00
conradchen
13dbc9f906 [BottomSheet] Support background tint without shape appearance set
Resolves https://github.com/material-components/material-components-android/issues/2200

PiperOrigin-RevId: 428781539
2022-02-15 19:26:40 +00:00
pekingme
6bf92e1c07 Automated g4 rollback of changelist 426304311
PiperOrigin-RevId: 428054428
2022-02-11 20:27:52 -08:00
pekingme
6454b8709a [BottomSheet] Fixed IME bottom padding is ignored in edge-to-edge case.
The regression on BottomSheet was introduced in 1.6.0-alpha01. Before this version, the bottom padding in edge-to-edge mode is calculated by getSystemWindowInsetBottom().

https://developer.android.com/reference/android/view/WindowInsets#getSystemWindowInsetBottom()

This is deprecated in newer APIs. According to deprecation message, the replacement is to use getInsets(int) with Type#systemBars(). But this is not completely true, because it doesn't contain IME insets.

https://developer.android.com/reference/android/view/WindowInsets.Type#systemBars()

Resolves: https://github.com/material-components/material-components-android/issues/2543
PiperOrigin-RevId: 426304311
2022-02-03 21:52:22 -08:00
Material Design Team
cfc00aa5a3 Update android core class definitions across material
PiperOrigin-RevId: 414839941
2021-12-08 14:56:25 +00:00
serniebanders
2e73d1a1cf [BottomSheetBehavior] Remove paddingTopSystemWindowInsets from flags checked to apply windowInsetListener
PiperOrigin-RevId: 413474393
2021-12-01 19:08:17 -05:00
Dan Nizri
e59fa50343
Revert "[BottomSheetDialogFragment] Added constructor that takes a layout ID" 2021-12-01 18:40:58 -05:00
Jose Figueroa
8c50ee2c12
Merge pull request #2237 from 4brunu/feature/bottomsheetdialogfragment-layoutid-in-constructor
[BottomSheetDialogFragment] Added constructor that takes a layout ID
2021-12-01 16:55:15 -05:00
Material Design Team
a487c89185 Internal change
PiperOrigin-RevId: 412135443
2021-11-29 17:35:39 +00:00
serniebanders
185a0f9c92 [BottomSheetBehavior] Add margin flags to BottomSheetBehavior for system inset bars.
Updates bottom sheet styles to default to left and right margins, top and bottom padding.

Resolves: https://github.com/material-components/material-components-android/issues/2221
PiperOrigin-RevId: 410580245
2021-11-29 16:46:09 +00:00
Bruno Coelho
0b63bb76e8 Update AppCompat to 1.4.0 stable 2021-11-17 21:35:14 +00:00
serniebanders
d5729d5935 Automated g4 rollback of changelist 409212345
PiperOrigin-RevId: 409279906
2021-11-16 12:34:36 -05:00
serniebanders
022a05f526 [BottomSheetBehavior] Add margin flags to BottomSheetBehavior for system inset bars.
Updates bottom sheet styles to default to left and right margins, top and bottom padding.

Resolves: https://github.com/material-components/material-components-android/issues/2221
PiperOrigin-RevId: 409212345
2021-11-16 12:29:43 -05:00
Bruno Coelho
8fb12fd2f6 Merge branch 'master' into feature/bottomsheetdialogfragment-layoutid-in-constructor
# Conflicts:
#	build.gradle
2021-11-11 20:26:33 +00:00
pfthomas
dbd37d2791 [BottomSheetBehavior] Remove IllegalArgumentException in settleToState
PiperOrigin-RevId: 405497835
2021-10-27 18:53:26 +00:00
dsn5ft
9ae56ceedd [Javadocs] Remove all broken attr links from Javadocs
PiperOrigin-RevId: 404246710
2021-10-20 19:06:18 +00:00
pekingme
9de9319b1e [Resources] Added styles in res-public.
PiperOrigin-RevId: 403451624
2021-10-18 15:31:13 -04:00
serniebanders
10284bcf74 [M3][Docs] Update bottomsheet documentation to describe M3 themes/styles.
Additionally exposes M3 bottomsheet styles in res-public

PiperOrigin-RevId: 397125281
2021-09-20 11:49:12 -07:00
conradchen
cdafe752e3 [M3][Bottomsheet] Create bottom sheet styles
PiperOrigin-RevId: 394258956
2021-09-01 17:07:04 -04:00
conradchen
27757d026a [M3] Create M3 skeleton themes
PiperOrigin-RevId: 390228317
2021-08-16 13:36:10 -07:00
Material Design Team
9fb73b50ff [BottomSheetBehavior] Apply the max width/height during measure instead of modifying layout params
Previously the BottomSheetBehavior was checking the measured size during onLayout and if it exceeded the max width or height configured it would "adjust" them by directly modifying the width and height on the layout params and then posting a setLayoutParams. This has many problems and is fundamentally the wrong way to do it. First off, a view should never modify the layout params that are configured on it for two reasons, one, they are properties of the parent view group, not the view itself, and two, they are almost always intended for users of the view group to configure, not the view group itself. Modifying the layout params directly is clobbering any previously configured parameter and permanently changing the layout (for example consider the case where the max width is set to 100dp and then later set to 200dp, the view would not be allowed to grow to 200dp because its layout params would already have been clobbered). Secondly the post is a very bad way to apply this max, not only does it trigger an entire layout pass a second time but it does so after having completed the first layout pass so it will cause the bottom sheet to render at the original size and then the capped size, it's both inefficient and will cause user visible jank.

The correct way to apply a maximum width/height is to do it during layout by incorporating it into the measure specs that are passed to the child. This doesn't clobber any state that the user of the view configured (i.e. when the parent measure specs change, e.g. due to screen rotation, the views correctly relayout) and it avoids doing multiple layout passes, the child can measure itself to the correct size the first time.

PiperOrigin-RevId: 387379138
2021-07-30 10:55:45 -04:00
conradchen
a2e76736c5 [BottomSheetBehavior] Fix ViewDragHelper state inconsistency
When BottomSheetBehavior is set to not draggable, it's still forwarding touch event to ViewDragHelper, which causes ViewDragHelper changes its state to dragging although it's not really dragging. This causes bugs like if we change draggable to true during "no-effect" dragging, ViewDragHelper won't report the dragging state change because it thinks the state is not changing.

Fixes this by avoiding forwarding touch events to ViewDragHelper when it's not draggable, so its state won't be changed.

Resolves https://github.com/material-components/material-components-android/issues/2258

PiperOrigin-RevId: 384942764
2021-07-15 12:37:35 -04:00
Afzal Najam
c3713724de [BottomSheet] Fix fitToContents reference in comment
Resolves https://github.com/material-components/material-components-android/pull/2196

GIT_ORIGIN_REV_ID=d996a3692496f60bd895df1a3a22b6bb4697d41f
PiperOrigin-RevId: 384750498
2021-07-15 12:33:43 -04:00
Wilson Filho
a38d2d89a8 [BottomSheet] Add maxHeight to bottom sheet behavior
Resolves https://github.com/material-components/material-components-android/pull/2216

GIT_ORIGIN_REV_ID=be136b9c5cedfb018b5a05fecac5ea9a3e242f36
PiperOrigin-RevId: 383682661
2021-07-09 15:28:02 -04:00
Sascha Huth
77c2a8383c [BottomSheet] make FloatRange for setHalfExpandedRatio() exclusive
Resolves https://github.com/material-components/material-components-android/pull/2239

GIT_ORIGIN_REV_ID=2eb3b01052ed017f23a53e5db121bb0c571f0fe6
PiperOrigin-RevId: 379791479
2021-06-17 14:30:42 -04:00
Material Design Team
b4982f9cdc [BottomSheet] Adds additional methods that are restricted to the library. They will be used for Experiment and deleted/revised after experiment.
PiperOrigin-RevId: 378874986
2021-06-14 18:32:13 +00:00
Bruno Coelho
7910be1813 Added BottomSheetDialogFragment constructor that takes a layout ID 2021-06-02 18:33:23 +01:00
leticiars
ce928fcb65 [Bottomsheets][Large Screens] Adding a max width for bottom sheets to optimize for large screens.
PiperOrigin-RevId: 368533002
2021-04-16 17:47:14 -04:00
Material Design Team
030e5bd65b [BottomSheet] read the edgeToEdgeEnabled value earlier in the lifecycle
The DialogFragment will set the content view during the INITIALIZED state of the Lifecycle.  This happens prior to onCreate and currently results in the edgeToEdgeEnabled value always being false at the time the OnApplyWindowInsertListener is conditionally set.

PiperOrigin-RevId: 366294759
2021-04-01 16:46:49 -04:00
cketcham
6f220b11a7 [BottomSheet] Sets default for BottomSheetBehavior paddingTopSystemWindowInsets to true
This adds space where the status bar is for any bottomsheet that would have otherwise been fullscreen.

PiperOrigin-RevId: 361933708
2021-03-10 10:03:14 -05:00
cketcham
28c3254d2a [BottomSheet] Allow opting out of edge to edge on the top
PiperOrigin-RevId: 359525223
2021-03-03 12:40:48 -05:00
cketcham
33f5aefb35 [BottomSheet] Only add OnApplyWindowInsetsListener if edgeToEdgeEnabled is true
PiperOrigin-RevId: 359407836
2021-03-03 12:40:08 -05:00
cketcham
2933600552 [BottomSheet] Prevent adding half expanded accessibility action if fitToContents is true
PiperOrigin-RevId: 356805609
2021-02-17 06:45:07 -08:00
haodong
0d0c90b9ef Updated string translations.
PiperOrigin-RevId: 354978993
2021-02-01 11:03:44 -08:00
Mao
8f77050a25 [BottomSheetBehavior] Remove duplicate state from BottomSheetBehavior#getState doc.
Resolves https://github.com/material-components/material-components-android/pull/1927

GIT_ORIGIN_REV_ID=50d11909b926457822ab310f1d4316aa0e3a0908
PiperOrigin-RevId: 350785062
2021-01-08 14:08:39 -05:00
cketcham
c15139a5c3 [BottomSheet] Automatically enable insets for ThemeOverlay style
Because the BottomSheet could be shown under the navigation bar if it's transparent or translucent, it's best to ensure insets are added. If no insets are added, views can end up behind the navigation bar which prevents any interaction.

PiperOrigin-RevId: 348470697
2021-01-06 13:28:56 -05:00
cketcham
c574e9ea23 [BottomSheet] Add flag to opt in to edge to edge behavior rather than only relying on the navigationBarColor
PiperOrigin-RevId: 347387288
2020-12-14 15:08:19 -05:00
cketcham
b1812b9a6b Internal Change
PiperOrigin-RevId: 347042445
2020-12-11 14:47:53 -05:00
cketcham
3037cf046c Automated g4 rollback of changelist 343006492
PiperOrigin-RevId: 347038837
2020-12-11 14:45:45 -05:00
cketcham
b163458a3a [BottomSheet] Updates the way BottomSheet handles insets
This updates ThemeOverlay styles to prevent drawing a transparent nav bar and updates BottomSheetBehavior and BottomSheetDialog to handle insets correctly so content isn't drawn behind the status bar or navigation bar.

Resolves https://github.com/material-components/material-components-android/issues/1222
Resolves https://github.com/material-components/material-components-android/issues/267

PiperOrigin-RevId: 343006492
2020-11-18 10:40:16 -05:00
dniz
9d1d9773cd [BottomSheet] Added string translations for i18n / l10n
PiperOrigin-RevId: 334800004
2020-10-01 11:29:12 -04:00
marianomartin
e944d1b2a6 [BottomSheet] Fixed issue where peekHeight is more than the height of the contents
PiperOrigin-RevId: 329722448
2020-09-02 13:29:54 -04:00