Skip to content

Commit 4ef8c84

Browse files
authored
Merge pull request #330 from vallemar/master
feat(BottomSheet): add default collapsed sheet height for android
2 parents 1ec0b28 + adea36b commit 4ef8c84

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/bottomsheet/bottomsheet-common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface BottomSheetOptions {
3131
ignoreBottomSafeArea?: boolean; // optional ios parameter to bottom safe area. Default is false
3232
disableDimBackground?: boolean; // optional parameter to remove the dim background
3333
skipCollapsedState?: boolean; // optional Android parameter to skip midway state when view is greater than 50%. Default is false
34+
peekHeight?: number // optional Android parameter to set the collapsed sheet height.
3435
}
3536

3637
export abstract class ViewWithBottomSheetBase extends View {

src/bottomsheet/bottomsheet.android.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { applyMixins } from '@nativescript-community/ui-material-core';
2-
import { AndroidActivityBackPressedEventData, Application, View, fromObject } from '@nativescript/core';
2+
import { AndroidActivityBackPressedEventData, Application, View, fromObject, Utils } from '@nativescript/core';
33
import { BottomSheetOptions, ViewWithBottomSheetBase } from './bottomsheet-common';
44

55
export { ViewWithBottomSheetBase } from './bottomsheet-common';
@@ -133,6 +133,12 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
133133
// disable peek/collapsed state
134134
behavior.setSkipCollapsed(true);
135135
}
136+
137+
const peekHeight = bottomSheetOptions.options?.peekHeight;
138+
if(peekHeight){
139+
behavior.setState(com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_COLLAPSED);
140+
behavior.setPeekHeight(Utils.layout.toDevicePixels(peekHeight));
141+
}
136142

137143
if (owner && !owner.isLoaded) {
138144
owner.callLoaded();

src/bottomsheet/bottomsheet.ios.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,11 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
406406
bottomSheet.dismissOnBackgroundTap = options.dismissOnBackgroundTap !== false;
407407
bottomSheet.dismissOnDraggingDownSheet = options.dismissOnDraggingDownSheet !== false;
408408

409+
const peekHeight = options.peekHeight;
410+
if(peekHeight){
411+
bottomSheet.preferredSheetHeight = peekHeight;
412+
}
413+
409414
if (options.trackingScrollView) {
410415
const scrollView = this.getViewById(options.trackingScrollView);
411416
if (scrollView && scrollView.nativeViewProtected instanceof UIScrollView) {

0 commit comments

Comments
 (0)