Skip to content

feat(BottomSheet): add default collapsed sheet height for android #330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/bottomsheet/bottomsheet-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface BottomSheetOptions {
ignoreBottomSafeArea?: boolean; // optional ios parameter to bottom safe area. Default is false
disableDimBackground?: boolean; // optional parameter to remove the dim background
skipCollapsedState?: boolean; // optional Android parameter to skip midway state when view is greater than 50%. Default is false
peekHeight?: number // optional Android parameter to set the collapsed sheet height.
}

export abstract class ViewWithBottomSheetBase extends View {
Expand Down
8 changes: 7 additions & 1 deletion src/bottomsheet/bottomsheet.android.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { applyMixins } from '@nativescript-community/ui-material-core';
import { AndroidActivityBackPressedEventData, Application, View, fromObject } from '@nativescript/core';
import { AndroidActivityBackPressedEventData, Application, View, fromObject, Utils } from '@nativescript/core';
import { BottomSheetOptions, ViewWithBottomSheetBase } from './bottomsheet-common';

export { ViewWithBottomSheetBase } from './bottomsheet-common';
Expand Down Expand Up @@ -133,6 +133,12 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
// disable peek/collapsed state
behavior.setSkipCollapsed(true);
}

const peekHeight = bottomSheetOptions.options?.peekHeight;
if(peekHeight){
behavior.setState(com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_COLLAPSED);
behavior.setPeekHeight(Utils.layout.toDevicePixels(peekHeight));
}

if (owner && !owner.isLoaded) {
owner.callLoaded();
Expand Down
5 changes: 5 additions & 0 deletions src/bottomsheet/bottomsheet.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@ export class ViewWithBottomSheet extends ViewWithBottomSheetBase {
bottomSheet.dismissOnBackgroundTap = options.dismissOnBackgroundTap !== false;
bottomSheet.dismissOnDraggingDownSheet = options.dismissOnDraggingDownSheet !== false;

const peekHeight = options.peekHeight;
if(peekHeight){
bottomSheet.preferredSheetHeight = peekHeight;
}

if (options.trackingScrollView) {
const scrollView = this.getViewById(options.trackingScrollView);
if (scrollView && scrollView.nativeViewProtected instanceof UIScrollView) {
Expand Down